0

For products in the admin, I need to have a custom attribute which contains the list of countries. It needs to be multiselect.

I created a multi select attribute in the admin, left the options blank, and in the database changed the source_model to 'Magento\Catalog\Model\Product\Attribute\Source\Countryofmanufacture'

This appeared correctly on a product page in the admin, however when selecting one or more countries and saving, the countries do not save.

What am I doing wrong?

asked Nov 22, 2022 at 3:32

1 Answer 1

1

If you have done all steps you described, it should work.

The condition to make it works is your attribute has:

  • backend_model value is Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend.
  • backend_type value is text (default value) or varchar.
  • frontend_input value is multiselect.
  • source_model value is Magento\Catalog\Model\Product\Attribute\Source\Countryofmanufacture

You can run this SQL query to check if all properties are correct:

SELECT `attribute_id`, `attribute_code`, `backend_model`, `backend_type`, `frontend_input`, `frontend_label`, `source_model` FROM `eav_attribute` WHERE `source_model` = 'Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Countryofmanufacture'

It should show the result like the screenshot below: enter image description here

answered Nov 22, 2022 at 7:19
2
  • Thanks, I was missing something there. Additionally I found I needed to either clear the cache or reindex the site in order for the save to work (did both at the same time). Commented Nov 24, 2022 at 2:18
  • @jaybong Great. Glad to help! Commented Nov 24, 2022 at 3:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.