0
我試圖從產品中刪除類別,但未成功使用它。 它仍然作爲該類別的產品。以編程方式從產品中刪除類別
這是我使用的代碼:
$categories = array();
$categories[] = $this->erp['mastercat'];
if(isset($this->erp['article']['all_categories'])){
if(is_array($this->erp['article']['all_categories']) && count($this->erp['shop']['all_categories'])>0){
foreach($this->erp['article']['all_categories'] as $category){
if(!in_array($category,$categories)){
$categories[] = $category;
}
}
}else if(!empty($this->erp['article']['all_categories'])){
if(!in_array($this->erp['article']['all_categories'], $categories)){
$categories[] = $this->erp['article']['all_categories'];
}
}
}
$this->product->setCategoryIds($categories);
我使用的是空數組,只放我需要在它的類別。
我不明白爲什麼以前選擇的類別和新的(我把它移入我的erp從一個類別到另一個類別)被選中。
http://stackoverflow.com/questions/17798615/how-to-remove-a-product-from-a-category-magento-1-5 –