I have scoured the web yet I am no nearer to understanding how I add a product to the wishlist in code.

I have a product ID and a customer object in my controller and I just want to be able to add that product to that customer's wishlist. It is not rocket science I am after, just something that should be doable.

3 Answers 3


All the code you need can be found in app/code/core/Mage/Wishlist/controllers/IndexController.php method _addItemToWishList.

You will need to load the product by it's ID and load the wish list by customer. The code would look roughly something like this.

$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$product = Mage::getModel('catalog/product')->load($productId);

$buyRequest = new Varien_Object(array()); // any possible options that are configurable and you want to save with the product

$result = $wishlist->addNewItem($product, $buyRequest);

Just out of curiosity. Why not use the addAction provided by the wishlist controller to add the products?

You can obtain the url via echo Mage::helper('wishlist')->getAddUrl($product);

  • I want to do an ajax 'add to' from a modal, with things like 'how many others have it in their wishlist' being part of the display. I actually copied the addAction to 'ajaxAction' in the normal controller, so I have something that works. Just got to tidy it up and put it into my own module. Nonetheless I am surprised that there is no convenient method and that I have to extend the wishlist controller class - a bit hackish to me!!! No idea what it does with 'buyRequest', luckily I don't need it. Anyway, thanks for pointing me in the right direction!
    – Theodores
    May 12, 2014 at 14:14
  • Note that if you want to add a (configured) configurable product to your wishlist the array in the Varien_Object should have the following keys: e.g. product='99', qty='1', super_attribute[133]='3'
    – Willster
    Jul 15, 2015 at 11:40
Hi use this code to remove a product having productid **$productId** of a customer having customerid **$customerId**.

   $itemCollection = Mage::getModel('wishlist/item')->getCollection()
        foreach($itemCollection as $item) {
             if($item->getProduct()->getId() == $productId){
if($_GET['addmultiple'] == "cartitem")

        $cuu = $this->helper('core/url')->getCurrentUrl();
        $currentUrl = str_replace("?addmultiple=cartitem","",$cuu);

            $cart = Mage::helper('checkout/cart')->getCart();
            $myupsell_product = $_product->getUpSellProductCollection();
            foreach($myupsell_product as $upsellprd)

            $params = 1;
            $pid = $upsellprd->getId();
            $product = Mage::getModel('catalog/product')->load($pid);;
            $cart->addProduct($product, $params);
            $msg .= $product->getName(). " is successfully added into cart<br>";
         header("Refresh: 0; url=$currentUrl");     

    catch(Exception $e) 
        header("Refresh: 0; url=$currentUrl");     



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.