Skip to content

Instantly share code, notes, and snippets.

@gelanivishal
Created December 1, 2016 06:56
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 gelanivishal/050c1c1f429ea96e0e016ecd44f6c0f8 to your computer and use it in GitHub Desktop.
Save gelanivishal/050c1c1f429ea96e0e016ecd44f6c0f8 to your computer and use it in GitHub Desktop.
MAGENTO: COPY PRODUCTS FROM ONE CATEGORY TO ANOTHER CATEGORY
<?php
require_once ( "app/Mage.php" );
umask(0);
// Initialize Magento
Mage::app();
$category = Mage::getModel('catalog/category');
$category->load('24'); // Category id you want to copy
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
foreach ($collection as $product) {
$product->getId();// Now get category ids and add a specific category to them and save?
$categories = $product->getCategoryIds();
$categories[] = 29; // Category id you want to add
$product->setCategoryIds($categories);
$product->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment