Home > Blog > Magento: Improve the "Continue Shopping" Button

Magento: Improve the "Continue Shopping" Button

Posted by Derek on December 31, 2014

On a typical Magento site there is a button on the cart page labeled “Continue Shopping”. If the user adds an item to the cart then clicks this button it will return her to the product page of the last added item. The URL for this link is retrieved using the checkout session, which stores a value with the key ‘last_added_product_id’. However, there are a couple minor flaws in this functionality. First, is that the session key is cleared after it’s accessed by a core module. So, if the cart is updated or the page is refreshed this session value is lost and the button is set to direct to the homepage. Second, the user may not have come from the product page, they may have used an “add to cart” button on a category page.

In my opinion it is a much better experience to always return the user to the last page they were on before coming to the cart. This can easily be accomplished with a modification to the cart page template located at default/template/checkout/cart.phtml.

Before the HTML add

$referer = $this->getRequest()->getServer('HTTP_REFERER');
$session = Mage::getSingleton('core/session', array('name'=>'frontend'));
if ($referer != $this->helper('core/url')->getCurrentUrl())
  $session->setData('cart_referer_url', $referer);
$continueUrl = $session->getData('cart_referer_url');

And then where the button is created change the PHP in the line to

echo (isset($continueUrl) ? $continueUrl : $this->getContinueShoppingUrl())

Leave a Reply

(Your email will not be publicly displayed.)

Captcha Code

Click the image to see another captcha.