2013-08-12 83 views
0

我可以能够去除所有项目中的心愿,但我要如何心愿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(); 
     } 
    } 
+0

你知道有一个链接 “从愿望清单中移除” 在标准Magento的心愿列表页?看看所涉及的控制器/模型,并且您有答案.. –

回答

0

这是从一个心愿在Magento删除项目的标准方法:

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

嗨使用此代码以除去产品ID $机生产线的产物有顾客的客户$ customerId

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