Aujourd’hui, suite à une modification différente via l’administration dans deux instances du même site (dev et staging), j’ai du modifié le type d’un attribut produit. L’idée était de le passer de liste déroulante à multi-select. Pour y parvenir, j’ai du faire quelques modifications dans la base de données directement puisqu’il n’est pas possible de le faire via l’administration.
On voit que le type d’entrée est grisé. Il n’est donc pas possible de faire ce changement via l’administration de Magento. Pour pouvoir changer cet attribut produit, il va falloir avoir recours à un script SQL. Ce script modifiera directement dans la base de données l’attribut.
Pour faire cette modification, je me suis basé sur un gist que j’ai adapté selon mes besoins :
-- YOUR_ATTRIBUTE_ID is the ID of the attribute you want to change
SET @ATTRIBUTE_ID = YOUR_ATTRIBUTE_ID;
-- 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 = 'varchar',
backend_table = NULL,
frontend_model = NULL,
frontend_input = 'multiselect',
frontend_class = NULL,
source_model = NULL
WHERE attribute_id = @ATTRIBUTE_ID;
-- Next, copy the attribute values from the old table to the new one
INSERT INTO catalog_product_entity_varchar ( 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 = @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 = @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.
*/
SQLEt voilà !
Laisser un commentaire
Vous devez vous connecter pour publier un commentaire.