0

We need to convert a dropdown attribute to multiselect

I found a way here :

If attribute_code : age ,
entity_type_id = 10 ,
store_id = 1

UPDATE eav_attribute SET
entity_type_id = '10',
attribute_model = NULL,
backend_model = 'eav/entity_attribute_backend_array',
backend_type = 'varchar',
backend_table = NULL,
frontend_model = NULL,
frontend_input = 'multiselect',
frontend_class = NULL
WHERE attribute_id = 'age';

Next, copy the attribute values from the old table to the new:

INSERT INTO catalog_product_entity_varchar ( 10, attribute_id, 1, entity_id, value)
SELECT entity_type_id, attribute_id, 1, entity_id, value
FROM catalog_product_entity_int
WHERE attribute_id = age;

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 = 10 and attribute_id = age;

Credits :

http://swarminglabs.com/how-to-change-a-product-dropdown-attribute-to-a-multi-select/

but here i want to know how to find "attribute_id and entity_id" for an attribute. so i can replace those values in above queries

  • by entity_id you mean entity_type_id, right? – Marius Jan 21 '16 at 13:49
  • Thanks for reply to my post. in database table i saw "entity_type_id" = "10 for that attribute. prntscr.com/9sxn7a but i dont know what is entity_id , is both are same ? – Baby in Magento Jan 21 '16 at 13:53
  • entity_id is the id of the products you want to change. I don't think you need those because you need to change the values for all the products that have that attribute. I think entity_type_id is the one you need. Check my answer and see if it works. Backup your db first though. – Marius Jan 21 '16 at 13:55
  • i got attribute_id as "1020" , now in question in 2nd query , there is "entity_id" text, is i have to remove that? – Baby in Magento Jan 21 '16 at 13:58
  • can you please update my 2nd query in question – Baby in Magento Jan 21 '16 at 14:00
1

you can find the entity_type id like this.

SELECT 
    entity_type_id 
FROM 
    eav_entity_type
WHERE
    entity_type_code = 'catalog_product'

and the attribute id like this

SELECT 
    attribute_id
FROM 
    eav_attribute
WHERE 
    attribute_code = 'age' AND
    entity_type_id = (SELECT 
                          entity_type_id 
                      FROM 
                          eav_entity_type
                      WHERE
                          entity_type_code = 'catalog_product'
                      )

or simply

SELECT 
    attribute_id
FROM 
    eav_attribute
WHERE 
    attribute_code = 'age' AND
    entity_type_id = THE RESULT FROM THE FIRST QUERY

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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