Assign one category products to another category or categories using standalone script.
<?php
require_once('app/Mage.php');
umask(0);
Mage::app('admin');
error_reporting(1);
set_time_limit(0);
ini_set('memory_limit', '2048M');
$from = $from_category_id;
$toarray = array($to_category_id_1,$to_category_id_2,$to_category_id_3);
foreach($toarray as $to){
echo $to."To category";
$category = Mage::getModel('catalog/category')->load($from);
$productCollection = $category->getProductCollection();
foreach($productCollection as $_product) {
Mage::getSingleton('catalog/category_api')
->assignProduct($to,$_product->getId());
echo 'Assigned -- ' . $_product->getId() . '<br />';
}
}
echo 'Completed Execution!!!';
exit;
Leave a Reply