I have added an "Add to Cart" button for the upsell items on the product view page, using the following code:
<button type="button" onclick="setLocation('<?php echo $this->helper('checkout/cart')->getAddUrl($_link) ?>')">
<?php echo $this->__('Add to Cart') ?>
</button>
The problem is that when adding the product to the cart it then redirects to the home page. I have the After Adding a Product Redirect to Shopping Cart
option set to No
in the checkout configuration.
How do I get it to stay on the same page?
Best Answer
Magento have a function
_goBack()
atMage_Checkout_CartController
,which is give us the facility to redirect user at any page after successfully Cart from addAction by add an extra parameter(return_url
) with add to cart url.At _goBack magento have check,current Action have any value for
return_url
param.If have then it redirect to customer to that page.For this case,you need send a extra parameter
return_url
with add to cart url.Currently,you getting cart url from
$this->helper('checkout/cart')->getAddUrl($_link)
and parent current page url asreturn_url
value