Magento删除愿望清单中的产品

时间:2013-08-12 07:12:08

标签: magento

我可以删除心愿单中的所有项目,但如何从心愿单中删除单个项目

以下是删除心愿单中所有项目的代码:

public function removeWishList($customer_id,$product_id)
    {           
        $itemCollection = Mage::getModel('wishlist/item')->getCollection()
            ->addCustomerIdFilter($customer_id);                            

        foreach($itemCollection as $item) {
            $item->delete();
            //Mage::getModel('wishlist/item')->load($product_id)->delete();
        }
    }

3 个答案:

答案 0 :(得分:1)

您可以使用此代码删除具有customerid $ customerId 的客户的产品 $ productId 的产品。

**$itemCollection = Mage::getModel('wishlist/item')->getCollection()
                    ->addCustomerIdFilter($customerId);
    foreach($itemCollection as $item) {
         if($item->getProduct()->getId() == $productId){
            $item->delete();
         }
    }**

答案 1 :(得分:0)

这是从Magento中的愿望清单中删除项目的标准方法:

Mage::getModel('wishlist/item')->load($id)->delete();

答案 2 :(得分:0)

$customerId = 1; // Replace with the customer id you are targetting

$itemCollection = Mage::getModel('wishlist/item')->getCollection()
    ->addCustomerIdFilter($customerId);

foreach($itemCollection as $item) {
    $item->delete();
}

Moreinfo

相关问题