Last active
August 3, 2016 15:29
-
-
Save tuanphpvn/94f2368b5c8c1725bed1 to your computer and use it in GitHub Desktop.
Random n product to category #Magento, #Category, #Product, #CreateData
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 | |
$addRamdomProductToCategory = function($n, $arrCategoryId) { | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
$productModel = Mage::getModel('catalog/product'); | |
$productIds = Mage::getModel('catalog/product')->getCollection()->getAllIds(); | |
foreach($arrCategoryId as $catId) { | |
$arrProductIdIndexs = array_rand($productIds, $n); | |
foreach($arrProductIdIndexs as $index) { | |
$productObj = $productModel->load($productIds[$index]); | |
$productObj->setCategoryIds(array($catId)); | |
$productObj->setIsMassupdate(true); | |
$productObj->setExcludeUrlRewrite(true); | |
$productObj->save(); | |
} | |
} | |
}; | |
$addRamdomProductToCategory(20, $arrCategoryId); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment