0

I need to add all my simple products associated with a configurable product to the same categories as the configurable.

I do not want to have to complete this manually nor do i want to purchase an extension.

Is there a way to do this?

Thank you Krystle

1

You could write a little script. The following SQL should give you the product id of the configurable product (config_product_id, which you don't really need), its assigned category_id, and its assigned simple products (simple_product_id).

SELECT 
    configCategory.category_id,
    r.parent_id as config_product_id,
    r.child_id as simple_product_id
FROM catalog_product_relation as r
INNER JOIN catalog_product_entity as simpleEntity
    ON r.child_id = simpleEntity.entity_id
    AND simpleEntity.type_id = 'simple'
INNER JOIN catalog_product_entity as configEntity
    ON configEntity.entity_id = r.parent_id
    AND configEntity.type_id = 'configurable'
INNER JOIN catalog_category_product as configCategory
    ON configCategory.product_id = configEntity.entity_id

You could then iterate over the result, and for each record, create a new record in catalog_category_product with values category_id, simple_product_id and a position value (for ordering). To prevent SQL erros because of duplicate keys, I would suggest using INSERT IGNORE statements.

0

To contribute to Claudio K's answer, this updated query should to the trick, entirely:

INSERT IGNORE INTO catalog_category_product (`category_id`,`product_id`, `position`)
SELECT 
    configCategory.category_id as category_id,
    r.child_id as product_id,
    1 as position
FROM catalog_product_relation as r
INNER JOIN catalog_product_entity as simpleEntity
    ON r.child_id = simpleEntity.entity_id
    AND simpleEntity.type_id = 'simple'
INNER JOIN catalog_product_entity as configEntity
    ON configEntity.entity_id = r.parent_id
    AND configEntity.type_id = 'configurable'
INNER JOIN catalog_category_product as configCategory
    ON configCategory.product_id = configEntity.entity_id;

Make sure you test it on a development environment, before running it on your live shop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.