我尝试从产品中删除类别,但没有成功。 它仍然是该类别的产品。
这是我正在使用的代码:
$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 中从一个类别移动到另一个类别)。
最佳答案
您还需要保存您的产品:
$this->product->save();
关于php - 以编程方式从产品中删除类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21984014/