2014-05-07 40 views
0

您好我有Magento的根類別,其中有大約100萬 產品副本Magento的根類別所有的產品在它

。現在我需要到這一類產品複製到其他類別

可以請你建議我如何能做到這一點

由於在管理,我有嘗試創建一個新的類別,並指定 產品

but in one time i can assign 1500 and that will take so long如果我手動做。 所以請建議我如何做到這一點。

+0

http://stackoverflow.com/questions/10523254/magento-mass-assign-products-to-category – himansu

回答

1

讓我們說,隨着產品種類的ID爲10
而你要的所有產品複製到類ID爲20
運行此腳本。

$sourceId = 10; 
$destinationId = 20; 
$source = Mage::getModel('catalog/category')->load($sourceId); 
$destination = Mage::getModel('catalog/category')->load($destinationId); 

$products = $source->getProductsPosition(); 
$destination->setPostedProducts($products); 
$destination->save(); 

但請記住,目標類別中的任何產品都將從該類別中刪除。

如果要保留目前已有的產品,請使用以下內容。

$sourceId = 10; 
$destinationId = 20; 
$source = Mage::getModel('catalog/category')->load($sourceId); 
$destination = Mage::getModel('catalog/category')->load($destinationId); 

$products = $source->getProductsPosition(); 
$destinationProducts = $destination->getProductsPosition(); 
$destination->setPostedProducts(array_merge($products, $destinationProducts)); 
$destination->save(); 
+0

我試圖用這個+馬呂斯,但我不斷收到一個外鍵錯誤...這對你有用嗎? – WebDevB

相關問題