直接更新 Magento 的数据库很棘手但可行。需要处理 EAV 的事情。
产品entity_id和sku都存放在这个表中
catalog_product_entity
产品属性名称存储在这些表之一中,您的系统中可能还有其他表。
catalog_product_entity_datetime
catalog_product_entity_decimal
catalog_product_entity_gallery
catalog_product_entity_int
catalog_product_entity_media_gallery
catalog_product_entity_text
catalog_product_entity_url_key
catalog_product_entity_varchar
属性值存放在
eav_attribute
因此,您需要将这三个表连接在一起。这是一个实体关系图,展示了它的工作原理和示例 SQL。
诀窍是知道要使用哪个entity_X 表,以及特定属性使用哪个attribute_id。 attribute_ids 因系统而异。此查询将帮助您查看您的查询。此示例仅查看 _entity_varchar 表。您的属性可能在 _entity_int 或 _entity_text 等中。此示例显示单个产品的值,在本例中 sku='0203MR-0'
显示产品属性 ID
select
p.entity_id,
p.entity_type_id,
p.attribute_set_id,
p.type_id,
p.sku,
a.attribute_id,
a.frontend_label as attribute,
av.value
from
catalog_product_entity p
left join catalog_product_entity_varchar av on
p.entity_id = av.entity_id
left join eav_attribute a on
av.attribute_id = a.attribute_id
where
p.sku = '0203MR-0'
;
一旦您知道相关属性的attribute_id,您就可以列出或更新这些属性。在这种情况下,我们对产品名称感兴趣,而在我的系统中,attribute_id 是 71。
列出产品名称
select
p.entity_id,
p.entity_type_id,
p.attribute_set_id,
p.type_id,
p.sku,
a.attribute_id,
a.frontend_label as attribute,
av.value
from
catalog_product_entity p
join catalog_product_entity_text av on
p.entity_id = av.entity_id
join eav_attribute a on
av.attribute_id = a.attribute_id
where
a.attribute_id = 71
;
更新产品名称
update
catalog_product_entity p
join catalog_product_entity_text av on
p.entity_id = av.entity_id
join eav_attribute a on
av.attribute_id = a.attribute_id
set
av.value = replace(av.value,
'example',
'test')
where
a.attribute_id = 71
;