3

We would like to add a link "view all other [category name] products" on the product page.

We tried several things no full success.

  1. it seems there is a last viewed category methode Mage::getSingleton('catalog/session')->getLastViewedCategoryId() but this is always empty
  2. and Mage::registry('current_category') is also empty
  3. so we added a method to capture the breadcrumbs and get the before last item (this seems to work in some cases, but when the user opens some items directly or some Magento systems show the shortest path: then it results in "view all"

We are now testing a work around where we use setData to the session to store the category name and url whilst visting the category. We retrieve this on the product page. This seems to work in some cases also - but we use a FPC - so this code is not always executed.

What is the best - and always working - method to get the last visited category?

thanks in advance

  • you can create custome table in magento.when customer visit category page it will save value to table and display to product page – Vaibhav Ahalpara Oct 17 '16 at 5:13
-1

You can try below code to get continue Shopping Category Url.

$lastProductIdAddedToCart = Mage::getSingleton('checkout/session')->getLastAddedProductId();
if($lastProductIdAddedToCart) {
    $productCategoryIdsArray = Mage::getModel('catalog/product')->load($lastProductIdAddedToCart)->getCategoryIds();
    //print_r($productCategoryIdsArray);    
    $continueShoppingCategoryUrl = Mage::getModel('catalog/category')->load(end($productCategoryIdsArray))->getUrl();
}

View the source for more details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.