简体   繁体   中英

Magento: assign product (grouped) category to all simple product that build it

I have 8000 simple products without category assigned.

These simple products are used to create a lot some grouped products .

All grouped product have category assigned.

Is possible to assign grouped product category to all simple products that are associated to it?

you could just try to add entries to catalog_category_product table..:

INSERT IGNORE INTO catalog_category_product (category_id, product_id)
SELECT ccp.category_id, cpr.child_id FROM catalog_product_entity  cpe
JOIN catalog_product_relation cpr ON cpr.parent_id = cpe.entity_id
JOIN catalog_category_product ccp ON cpe.entity_id = ccp.product_id
WHERE cpe.type_id = 'grouped'
ORDER BY cpe.entity_id
;

following SQL will add all simple products which are associated with any grouped products to all categories to which the grouped product is assigned. I wrote in just now and didn't test it so be sure to test it before launching on PRODUCTION db;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM