2

I am using this code for add product in customer wishlist. For first product it is working properly but when I try to add second product, it replace the first product in wishlist.

function addfavourites($customerId, $storeId, $productId)
    {
        /*************** Add wishlist - Start *****************/
        $arrProductIds = array();
        if ($customerId && $productId) {
            try {
                $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
                $product = Mage::getModel('catalog/product')->load($productId);

                if (!$product->getId() || !$product->isVisibleInCatalog()) {
                    $responseData = "Cannot specify product.";
                    return array('status' => 0, 'msg'=> $responseData);
                }

                if ($storeId!='') {
                    $product->setStoreId($storeId);
                } else {
                    $product->setStoreId(1);
                }
                $params = array('product' => $productId, 'qty' => 1, 'store_id' => $storeId);
                $request = new Varien_Object();  
                $request->setData($params); 
                $request->setStoreId($storeId);
                $result = $wishlist->addNewItem($product, $request);
                $resultWishListId = $result['wishlist_item_id'];
                if (is_string($result)) {
                    Mage::throwException($result);
                }
                $wishlist->save();
                $responseData = 'Product added in favourites successfully.';
                return array('status' => 1, 'msg'=> $responseData, 'resultWishListId'=>$resultWishListId);
            } catch (Exception $exception) {
                $responseData = $exception->getMessage();
                return array('status' => 0, 'msg'=> $responseData);
            }
        } else {
            $responseData = 'Please enter customerId.';
            return array('status' => 0, 'msg'=> $responseData);
        }
        /*************** Add wishlist - End *****************/
    }
  • any errors being shown? – David Manners Apr 28 '15 at 12:50
  • No error. Only form submit and no value updated/added for product information. – Neeraj Sharma Apr 29 '15 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.