Script to Make a Duplicate Category

<?php
require_once('app/Mage.php');
umask(0);
Mage::app('admin');

error_reporting(1);
set_time_limit(0);
ini_set('memory_limit', '2048M');

// COPY Products From => To
// 5 => 10


if(isset($_REQUEST['from'])){
    $from = $_REQUEST['from'];
    $to = $_REQUEST['to'];
    $category = Mage::getModel('catalog/category')->load($from);
   
    $productCollection = $category->setStoreId(1)->getProductCollection();
   
    foreach($productCollection as $_product) {
     $product = Mage::getModel('catalog/product')->load($_product->getId());
   
     $newCategories = $origCats = $product->getCategoryIds();
     if(!in_array($to, $origCats)) {
     $newCategories = array_merge($origCats, array($to));
     $product->setCategoryIds($newCategories)->save();
     echo 'Assigned -- ' . $product->getId() . '<br />';
     }
    }
    echo 'Completed Execution!!!';
}else{
    echo 'Error';
}
//Run this url to update( from is category id and to is a category id to which u want to move
//eg:http://xyz/magento/copycategoryproducts.php?from=4072&to=4602
//output:
//Assigned -- 12021
//Assigned -- 12022
//Assigned -- 12161
//Assigned -- 12162
//Assigned -- 12275

Comments

Popular Posts

Magmi Single and Multiple Category Importer