Created
November 29, 2016 22:12
-
-
Save avocadoslab/179de8ab5b9c7f75acbbbdbd32f0d3e1 to your computer and use it in GitHub Desktop.
copy products from one category to other category.
This file contains hidden or 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); | |
Mage::app('admin'); | |
error_reporting(1); | |
set_time_limit(0); | |
ini_set('memory_limit', '2048M'); | |
// COPY Products From => To | |
// 5 => 10 | |
$from = 5; | |
$to = 10; | |
$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!!!'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment