I know how to redirect Magento's Continue Shopping button to the first and last categories from the array of all categories for the last product added to the cart but I want to redirect to the first page of the 'CURRENT CATEGORY' that the product was added from for the last product added to the shopping cart. Our catalog is too many levels deep for first or last categories from the array to work as needed.
Here is an example. So if someone adds a product from category (Sub-Sub-Category: 2A) the continue shopping button would need to take them back to the first page of (Sub-Sub-Category: 2A). How do I do this with arrays?
Category: A
Sub-Category: 1A
Sub-Sub-Category: 2A
Sub-Sub-Sub-Category: 3A
app/design/frontend/yourpackage/yourtheme/template/checkout/cart.phtml
Code
<?php
$lastProductAddedToCartId = Mage::getSingleton('checkout/session')->getLastAddedProductId();
if($lastProductAddedToCartId) {
$productCategoryIdsArray = Mage::getModel('catalog/product')->load($lastProductAddedToCartId)->getCategoryIds();
$continueShoppingCategoryUrl = Mage::getModel('catalog/category')->load($productCategoryIdsArray[0])->getUrl();
}
?>
Shopping Cart Button
<?php if($this->getContinueShoppingUrl()): ?>
<button type="button" title="<?php echo $this->__('Continue Shopping') ?>" class="button2 btn-continue" onclick="setLocation('<?php echo (isset($continueShoppingCategoryUrl)) ? $continueShoppingCategoryUrl : $this->getContinueShoppingUrl(); ?>')"><span><span><?php echo $this->__('Continue Shopping') ?></span></span></button>
<?php endif; ?>