B-219 Sec-55 Noida, India
+918010221733

Setting the ‘continue shopping’ URL to last product’s category page in magento

Here is a code snippet for setting the ‘Continue Shopping’ location to the category listing page of the last product added to the cart. Open the template/checkout/cart.phtml file in your active theme. Place the following code in the foreach loop

(ie. after this line of code)

<?php foreach($this->getItems() as $_item): ?>

that generates the products list in the cart.

<?php $_categories = $_item->getProduct()->getCategoryIds();
$_category = Mage::getModel(‘catalog/category’)->load($_categories[0]);
$url = $this->getUrl($_category->getUrlPath());
Mage::getSingleton(‘checkout/session’)->setContinueShoppingUrl($url);
?>

You are done!

(Visited 40 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.