Skip to content

Instantly share code, notes, and snippets.

@larascasse
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larascasse/82511c440e82d4da4c7e to your computer and use it in GitHub Desktop.
Save larascasse/82511c440e82d4da4c7e to your computer and use it in GitHub Desktop.
Magento Duplicate category
INSERT INTO catalog_category_product
SELECT {{NEWCATEGORY}} as category_id, tablea.product_id, 999 as position
FROM `catalog_category_product` tablea
LEFT OUTER JOIN `catalog_category_product` tableb
ON tablea.product_id = tableb.product_id
AND tableb.category_id = {{NEWCATEGORY}}
WHERE tablea.`category_id` = {{OLDCATEGORY}} AND tableb.position is NULL
@larascasse
Copy link
Author

INSERT INTO catalog_category_product
SELECT 28 as category_id, tablea.product_id, 999 as position
FROM catalog_category_product tablea
LEFT OUTER JOIN catalog_category_product tableb
ON tablea.product_id = tableb.product_id
AND tableb.category_id = 28
WHERE tablea.category_id = 16 AND tableb.position is NULL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment