user2629419
user2629419

Reputation: 443

Magento remove the product in wishlist

I can able to remove all items in wishlist, but how do i remove individual items from wishlist

The following is the code, to remove all items in wishlist:

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

Upvotes: 0

Views: 4693

Answers (3)

Ravi Patel
Ravi Patel

Reputation: 5211

$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

Upvotes: 0

Prafull
Prafull

Reputation: 591

Hi use this code to remove a product having productid $productId of a customer having customerid $customerId.

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

Upvotes: 1

magentoassistance
magentoassistance

Reputation: 121

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

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

Upvotes: 0

Related Questions