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
If you have done all steps you described, it should work.
The condition to make it works is your attribute has:
backend_modelvalue isMagento\Eav\Model\Entity\Attribute\Backend\ArrayBackend.backend_typevalue istext(default value) orvarchar.frontend_inputvalue ismultiselect.source_modelvalue isMagento\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
-
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– jaybong2022年11月24日 02:18:39 +00:00Commented Nov 24, 2022 at 2:18
-
@jaybong Great. Glad to help!Tu Van– Tu Van2022年11月24日 03:37:37 +00:00Commented Nov 24, 2022 at 3:37