Created
December 1, 2016 06:56
-
-
Save gelanivishal/050c1c1f429ea96e0e016ecd44f6c0f8 to your computer and use it in GitHub Desktop.
MAGENTO: COPY PRODUCTS FROM ONE CATEGORY TO ANOTHER CATEGORY
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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