I have a large number products that I need to move or copy to other categories in Magento How is this possible?

Is this also possible through database? If it is, which table(s) should modified?


Try this, Before that take a Backup

You can achieve this easily using a MySQL query.

As per as my suggestion this is the best way.

Magento saves product-category associations in the catalog_category_product table.


Step 1: Take a backup of the database. Mainly the catalog_category_product table.

Step 2: Run the below query for moving products from the old category to the new category.

SELECT {NEW_CAT_ID} cat, product_id, position FROM catalog_category_product WHERE category_id= {OLD_CAT_ID} AND product_id NOT IN ( SELECT product_id FROM catalog_category_product WHERE category_id = {NEW_CAT_ID}));

Suppose, your new category id is 7, and the old category id is 4.

INSERT INTO catalog_category_product(

    SELECT 7 cat, `product_id`, `position`
    FROM catalog_category_product
    WHERE `category_id` = 4
    AND product_id NOT IN
        SELECT  `product_id`
        FROM catalog_category_product
        WHERE category_id = 7

Step 3: Delete records from the old category using a MySQL query:

Delete from catalog_category_product where category_id={OLD_CAT_ID};


Delete from catalog_category_product where category_id=4;
| improve this answer | |

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.