Copy categories from parent configurable product t

2019-07-21 09:08发布

问题:

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.