Copy categories from parent configurable product to simple child product in Magento

早过忘川 提交于 2020-01-04 14:32:26

问题


I need some advise on best way to archieve this programmatically.

The problem is that i have many configurable prodcuts (+20.000) which are allready in a category. All the simple underlaying child products are not in any category at all. I want all simple child products to inherit category from parent.

If configurable product "A" is in category called "Category A", all child products of product "A" should be included in "Category A".

This is going to used for an XML product feed, so i can not use anchor categories in Magento.

Any advise on how to archieve this, also considering the amounts of SKU's that needs to be updated in database?


回答1:


We had this same problem. This query will fill in the gaps by grabbing each configurable product's children, and inserting a new category association for each one (one for each of the parent categories)

INSERT IGNORE INTO catalog_category_product (category_id, product_id) SELECT ccp.category_id, cpl.product_id FROM catalog_product_super_link cpl LEFT JOIN catalog_category_product ccp ON ccp.product_id = cpl.parent_id WHERE ccp.category_id IN (SELECT entity_id FROM catalog_category_entity);

Note: The WHERE clause at the end is to prevent foreign key errors.



来源:https://stackoverflow.com/questions/22184352/copy-categories-from-parent-configurable-product-to-simple-child-product-in-mage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!