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?

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

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).
    – jaybong
    Commented Nov 24, 2022 at 2:18
  • @jaybong Great. Glad to help!
    – Tu Van
    Commented Nov 24, 2022 at 3:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.