我正在尝试将Magento中一个类别中的所有产品分配到另一个类别?有人能用脚本做到这一点吗?我们有6000多种产品,一比一或通过进口来做似乎给我带来了问题。。。哈哈
我试过这个脚本,但它不想工作,我们正在运行1.9.2.4。
<?php
require_once ( "app/Mage.php" );
umask(0);
// Initialize Magento
Mage::app();
$category = Mage::getModel('catalog/category');
$category->load('24'); // Category i want to copy?
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
foreach ($collection as $product) {
$product->getId();
$categories = $product->getCategoryIds();
$categories[] = 29; // Category id I want to copy too?
$product->setCategoryIds($categories);
$product->save();
}
?>
有人能解释一下吗?
添加Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID))
;umask(0);
之后
您可能需要增加max_execution_time
来处理所有产品。