在 magento 1.9 中更新重量

Update Weight in magento 1.9 on mass

我正在尝试创建一个 MySQL 语句,我可以将其放入 php 脚本中以更新 magento 1.9 中几千种产品的权重。

这是我目前的声明:

UPDATE dp_catalog_product_entity_decimal AS ped JOIN dp_eav_attribute AS ea ON  ea.entity_type_id = 10 AND ea.attribute_code = 'weight' AND ped.attribute_id = ea.attribute_id SET ped.value = 8 WHERE ped.entity_id = P1000X3;

它部分取自另一个 post,所以我不确定它是否能正常工作,但我目前遇到错误“#1054 - 'where clause' 中的未知列 'P1000X3' "

我对 sql 连接不太了解,而且我根本不了解 magento 数据库,因此非常感谢任何有助于使此声明生效的帮助。

谢谢。 马特

您的 Magento 表格有前缀 dp_ 吗?确保这一点。

这部分还有:

WHERE ped.entity_id = P1000X3;

ped.entity_id 将是一个整数值(数字)。

我不确定你从哪里得到 P1000X3,但使用它是行不通的(它是一个字符串值)。尽管如此,字符串还是应该用单引号括起来 ',像这样:

'P1000X3';

在 Magento 中更新具有特定 SKU 的产品重量的正确 SQL 是这样的(将 YOUR-MAGENTO-SKU 替换为您要更新的项目的 sku,以及 8与权重值)。

UPDATE catalog_product_entity_decimal AS cped
JOIN eav_attribute AS ea ON ea.entity_type_id = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product')
LEFT JOIN catalog_product_entity AS cpe ON cpe.entity_id = cped.entity_id
AND ea.attribute_code = 'weight'
AND cped.attribute_id = ea.attribute_id
SET cped.value = 8
WHERE cpe.sku = 'YOUR-MAGENTO-SKU';

在您的情况下,您有 table 前缀 dp_ 和产品 sku P1000X3,因此对您来说正确的 SQL 是:

UPDATE dp_catalog_product_entity_decimal AS cped
JOIN dp_eav_attribute AS ea ON ea.entity_type_id = (SELECT entity_type_id FROM dp_eav_entity_type WHERE entity_type_code = 'catalog_product')
LEFT JOIN dp_catalog_product_entity AS cpe ON cpe.entity_id = cped.entity_id
AND ea.attribute_code = 'weight'
AND cped.attribute_id = ea.attribute_id
SET cped.value = 8
WHERE cpe.sku = 'P1000X3';

完成 运行 之后,请务必重新索引您的 Magento 索引。