2013-08-12 81 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