【问题标题】:Magento remove the product in wishlistMagento 删除愿望清单中的产品
【发布时间】:2013-08-12 07:12:07
【问题描述】:

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

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

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

【问题讨论】:

  • 您知道标准 magento 的愿望清单页面中有一个“从愿望清单中删除”链接吗?看看所涉及的控制器/模型,你就有答案了..

标签: magento


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:
      $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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-11
        • 2016-09-16
        相关资源
        最近更新 更多