Forked from dinhkhanh/change-dropdown-attribute-to-multiselect.sql
Last active
October 27, 2020 14:48
-
-
Save mageconsult/733d6851e41aec42f19c8aeeef004268 to your computer and use it in GitHub Desktop.
Magento change dropdown attribute to multiselect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ONLY VALID SINCE MAGENTO 1.9.3.x | |
-- First, update the attribute input type to multiselect | |
UPDATE eav_attribute SET | |
entity_type_id = 4, | |
attribute_model = NULL, | |
backend_model = 'eav/entity_attribute_backend_array', | |
backend_type = 'text', | |
backend_table = NULL, | |
frontend_model = NULL, | |
frontend_input = 'multiselect', | |
frontend_class = NULL, | |
source_model = NULL | |
WHERE attribute_id = YOUR_ATTRIBUTE_ID; | |
-- Next, copy the attribute values from the old table to the new one | |
INSERT INTO catalog_product_entity_text ( entity_type_id, attribute_id, store_id, entity_id, value) | |
SELECT entity_type_id, attribute_id, store_id, entity_id, value | |
FROM catalog_product_entity_int | |
WHERE attribute_id = YOUR_ATTRIBUTE_ID; | |
-- Finally, remove the old values or they will conflict with the new setup | |
-- (the old values will load, but Magento will save new values to the varchar table) | |
DELETE FROM catalog_product_entity_int | |
WHERE entity_type_id = 4 and attribute_id = YOUR_ATTRIBUTE_ID; | |
/* | |
The value for "entity_type_id" that you’ll want to use may not always be "4" as referenced above. | |
You'll want to check the column "eav_entity_type" in table "eav_attribute" | |
and find the entry that has the "entity_type_code" set to "catalog_product". | |
The "entity_type_id" for that record is the value you need to use. In most cases this value is either "4" or "10", | |
but this may vary in future versions of Magento. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment