cancel
Showing results for 
Search instead for 
Did you mean: 

How to add product in wishlist without redirecting to wishlist page

SOLVED

How to add product in wishlist without redirecting to wishlist page

I want my customer can add a product without redirecting to the wishlist page.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to add product in wishlist without redirecting to wishlist page

Hi @Zekinah Lecaros

 

As discussion earlier that you required to installed extension to achieve this functionality !

 

https://github.com/hwguyguy/magento-ajax-wishlist

 

Here i am sending the link, that how to installed extension manually in magento 1 - http://www.aschroder.com/2010/05/installing-a-magento-extension-manually-via-ftp-or-ssh/

 

Hope it helps

if issue solved,Click Kudos & Accept as Solution

View solution in original post

6 REPLIES 6

Re: How to add product in wishlist without redirecting to wishlist page

Hello @Zekinah Lecaros

 

You can find your solution in below links:

 

http://excellencemagentoblog.com/blog/2011/10/27/magento-ajax-based-add-product-to-wishlist-and-comp...

https://www.magecloud.net/marketplace/extension/add-to-cart-using-ajax-13662/

 

You can follow below link to install the plugin:

http://www.aschroder.com/2010/05/installing-a-magento-extension-manually-via-ftp-or-ssh/

 

Please let me know if you stuck somewhere.

Manish Mittal
https://www.manishmittal.com/

Re: How to add product in wishlist without redirecting to wishlist page

Hi @Zekinah Lecaros

 

As discussion earlier that you required to installed extension to achieve this functionality !

 

https://github.com/hwguyguy/magento-ajax-wishlist

 

Here i am sending the link, that how to installed extension manually in magento 1 - http://www.aschroder.com/2010/05/installing-a-magento-extension-manually-via-ftp-or-ssh/

 

Hope it helps

if issue solved,Click Kudos & Accept as Solution

Re: How to add product in wishlist without redirecting to wishlist page

Hello @Zekinah Lecaros,

 

We need to create an extension for it. Please follow below steps

  1. Create file app/etc/modules/Vendor_AjaxWishlist.xml
    <?xml version="1.0"?>
    <config>
    	<modules>
    		<Vendor_AjaxWishlist>
    			<active>true</active>
    			<codePool>local</codePool>
    		</Vendor_AjaxWishlist>
    	</modules>
    </config>
  2. Create extension configuration file app/code/local/Vendor/AjaxWishlist/etc/config.xml
    <?xml version="1.0"?>
    <config>
    	<modules>
    		<Vendor_Wishlist>
    			<version>0.1.0</version>
    		</Vendor_Wishlist>
    	</modules>
    	<frontend>
    		<routers>
    			<ajaxwishlist>
    				<use>standard</use>
    				<args>
    					<module>Vendor_AjaxWishlist</module>
    					<frontName>ajaxwishlist</frontName>
    				</args>
    			</ajaxwishlist>
    		</routers>
    	</frontend>
    </config>
  3. Create controller for wishlist app/code/local/Vendor/AjaxWishlist/controllers/ProductController.php

    <?php
    class Vendor_AjaxWishlist_ProductController extends Mage_Core_Controller_Front_Action {
    
    	/**
    	 * Add items to wishlist and return response in json.
    	 */
    	public function addAction() {
    		$response = array('status' => 1);
    
    		if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
    			Mage::getSingleton('customer/session')->setAfterAuthUrl($this->_getRefererUrl());
    			$response['redirect'] = Mage::getUrl('customer/account/login', array(
    				'referer' => Mage::helper('core')->urlEncode($this->_getRefererUrl()),
    			));
    			$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
    		}
    
    		if (!$this->_validateFormKey()) {
    			$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
    			return;
    		}
    
    		$wishlist = $this->_getWishlist();
    		if (!$wishlist) {
    			$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
    			return;
    		}
    
    		$session = Mage::getSingleton('customer/session');
    
    		$productId = (int)$this->getRequest()->getParam('product');
    		if (!$productId) {
    			$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
    			return;
    		}
    
    		$product = Mage::getModel('catalog/product')->load($productId);
    		if (!$product->getId() || !$product->isVisibleInCatalog()) {
    			$reponse['message'] = $this->__('Cannot specify product.');
    			$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
    			return;
    		}
    
    		try {
    			$requestParams = $this->getRequest()->getParams();
    			if ($session->getBeforeWishlistRequest()) {
    				$requestParams = $session->getBeforeWishlistRequest();
    				$session->unsBeforeWishlistRequest();
    			}
    			$buyRequest = new Varien_Object($requestParams);
    
    			$result = $wishlist->addNewItem($product, $buyRequest);
    			if (is_string($result)) {
    				Mage::throwException($result);
    			}
    			$wishlist->save();
    
    			Mage::dispatchEvent(
    				'wishlist_add_product',
    				array(
    					'wishlist' => $wishlist,
    					'product' => $product,
    					'item' => $result
    				)
    			);
    
    			$referer = $session->getBeforeWishlistUrl();
    			if ($referer) {
    				$session->setBeforeWishlistUrl(null);
    			} else {
    				$referer = $this->_getRefererUrl();
    			}
    
    			/**
    			 *  Set referer to avoid referring to the compare popup window
    			 */
    			$session->setAddActionReferer($referer);
    
    			Mage::helper('wishlist')->calculate();
    
    			$message = $this->__('%1$s has been added to your wishlist. Click <a href="%2$s">here</a> to continue shopping.',
    				$product->getName(), Mage::helper('core')->escapeUrl($referer));
    
    			$response['status'] = 0;
    			$response['message'] = $message;
    		} catch (Mage_Core_Exception $e) {
    			$response['message'] = $this->__('An error occurred while adding item to wishlist: %s', $e->getMessage());
    		}
    		catch (Exception $e) {
    			$response['message'] = $this->__('An error occurred while adding item to wishlist.');
    		}
    
    		$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
    	}
    
    	/**
    	 * Retrieve wishlist object
    	 * @see Mage_Wishlist_IndexController
    	 *
    	 * @param int $wishlistId
    	 * @return Mage_Wishlist_Model_Wishlist|bool
    	 */
    	protected function _getWishlist($wishlistId = null) {
    		$wishlist = Mage::registry('wishlist');
    		if ($wishlist) {
    			return $wishlist;
    		}
    
    		try {
    			if (!$wishlistId) {
    				$wishlistId = $this->getRequest()->getParam('wishlist_id');
    			}
    			$customerId = Mage::getSingleton('customer/session')->getCustomerId();
    			/* @var Mage_Wishlist_Model_Wishlist $wishlist */
    			$wishlist = Mage::getModel('wishlist/wishlist');
    			if ($wishlistId) {
    				$wishlist->load($wishlistId);
    			} else {
    				$wishlist->loadByCustomer($customerId, true);
    			}
    
    			if (!$wishlist->getId() || $wishlist->getCustomerId() != $customerId) {
    				$wishlist = null;
    				Mage::throwException(
    					Mage::helper('wishlist')->__("Requested wishlist doesn't exist")
    				);
    			}
    
    			Mage::register('wishlist', $wishlist);
    		} catch (Mage_Core_Exception $e) {
    			Mage::getSingleton('wishlist/session')->addError($e->getMessage());
    			return false;
    		} catch (Exception $e) {
    			Mage::getSingleton('wishlist/session')->addException($e,
    				Mage::helper('wishlist')->__('Wishlist could not be created.')
    			);
    			return false;
    		}
    
    		return $wishlist;
    	}
    }
  4. Clear cache from admin panel
  5. Done.

--
If my answer is useful, please Accept as Solution & give Kudos

 

 

Re: How to add product in wishlist without redirecting to wishlist page

Re: How to add product in wishlist without redirecting to wishlist page

This article helps me to resolve redirect issue in magento 2 - https://nwdthemes.com/2019/08/23/magento-2-working-with-wishlist/#magento2_wishlist_2

Re: How to add product in wishlist without redirecting to wishlist page

Hello it's not working I have tried as same as given without missing any method, can you help us out, we are using Magento 1.9.4.0