0

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

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

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();
        }
    }
4

3 回答 3

1

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

**$itemCollection = Mage::getModel('wishlist/item')->getCollection()
                    ->addCustomerIdFilter($customerId);
    foreach($itemCollection as $item) {
         if($item->getProduct()->getId() == $productId){
            $item->delete();
         }
    }**
于 2014-10-31T10:32:20.653 回答
0

This is the standard method for removing items from a wishlist in Magento:

Mage::getModel('wishlist/item')->load($id)->delete();
于 2013-08-13T03:43:28.640 回答
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();
}

更多信息

于 2014-10-31T10:50:55.043 回答