更新时间:2023-08-26 15:31:52
您需要从产品中获取所有类别ID,然后从类别ID数组中删除销售类别ID,然后将其重新设置为产品.
You need get all category ids from product, then remove Sales category ID from category ids array and set them back to product.
例如,销售类别ID为5.
Example, Sales category ID is 5.
foreach ($collection as $product) {
//Getting all category ids
$ids = $product->getCategoryIds();
//Searching array key with value 5 and removing from array
if (($key = array_search(5, $ids)) !== false) {
unset($ids[$key]);
$product->setCategoryIds($ids)
$product->save();
}
}
P.S.您可以使用magento cron作业功能,而不需要使用以下功能:
P.S. You can use magento cron job functionality, than you do not need to use:
require_once 'app/Mage.php';
Mage::app();