Magento-如何清除不在属性集中的属性

col*_*mde 3 attributes magento

我从另一个开发人员那里接管了一个网站,发现属性设置有些混乱。

具体来说,产品具有与相关属性集不相关的属性。

如果您使用属性设置为“葡萄酒”的葡萄酒,则属性之一是“葡萄品种”。

但是我也有“啤酒”,它具有完全不同的属性集,但是不知何故,我的啤酒之一是葡萄品种。

它没有分配给Beers属性集,也没有显示在该产品的后端(因此我无法对其进行编辑),但是如果我在数据库中查找,它就在那里(在catalog_product_entity_ *和catalog_product_index_eav中)当我进行出口时,它也在那里,如果有人搜索“ Merlot”,他们就会拿出这种啤酒。有数百种这样的产品。

从产品中删除不在其分配的属性集中的所有属性的最佳方法是什么?

我敢肯定,我可以在SQL中弄清楚这一点,但这并不是最好的处理方式,因为我担心会丢失某些内容并完全搞砸产品。

col*_*mde 5

这就是我最终要做的。几周后,它似乎还没有引起任何问题:

CREATE TABLE catalog_product_entity_int_old LIKE catalog_product_entity_int;
INSERT INTO catalog_product_entity_int_old SELECT * FROM catalog_product_entity_int;

DELETE FROM catalog_product_entity_int 
    WHERE value_id IN 
        (SELECT cpei.value_id 
            FROM catalog_product_entity_int_old cpei 
            WHERE cpei.attribute_id NOT IN 
                (SELECT eea.attribute_id 
                    FROM eav_entity_attribute eea 
                        JOIN catalog_product_entity cpe ON eea.attribute_set_id = cpe.attribute_set_id 
                    WHERE cpe.entity_id = cpei.entity_id) 
        ORDER BY cpei.entity_id)
Run Code Online (Sandbox Code Playgroud)

DELETE FROM catalog_product_index_eav WHERE
attribute_id NOT IN (
    (SELECT eea.attribute_id 
    FROM eav_entity_attribute eea 
        JOIN catalog_product_entity cpe ON eea.attribute_set_id = cpe.attribute_set_id 
    WHERE cpe.entity_id = catalog_product_index_eav .entity_id) 
);
Run Code Online (Sandbox Code Playgroud)

然后重新生成索引。

  • 从Magento 2.1开始,此解决方案仍然有效。对于2.1 EE,在第一个查询集中“ entity_id”应为“ row_id”(由于内容分段)。 (2认同)