Directly go to Product Detail page on click of a category in the nav bar

夙愿已清 提交于 2019-12-05 12:31:23

Yes this can be done by using the URL Rewrite Management option in Magento Admin.

In Magento Admin:

  1. Select from menu bar Catalog > URL Rewrite Management.
  2. Click on the Add URLRewrite button.
  3. Select the category you want to redirect from.
  4. Make a note of the ID Path (e.g.: category/10) and the Request Path (e.g.: flowerpots.html)
  5. Repeat steps 1 & 2, but this time select Custom from the Create Urlrewrite dropdown box.
  6. Enter the values in each field:

    • ID Path (from step 4)
    • Request Path (from step 4)
    • Target Path - enter path of your product (or the page you want to redirect to).
      • example 1: for product url www.myswebsite.co.uk/flowers.html enter flowers.html.
      • example 2: for product url www.myswebsite.co.uk/sale/garden/flowers.html enter sale/garden/flowers.html.
  7. Select Redirect Permanent (301) from the Redirect dropdown.

  8. Save.

Now when the category is clicked on on your website it will re-direct to the product.

This can be done programmatically by adding code to the page template in your theme folder which is called for showing the categories. Check full solution here - http://www.codeboss.in/web-funda/2015/01/30/magento-auto-redirect-to-product-details-page-if-category-have-only-one-product/

Follow the Steps:

  1. Open the page template which is assigned to the category pages. You will find it under “template/page/” folder in your theme directory. For example let us assume the page is 1column.phtml (for the One column layout).

  2. Just after the lines

/** * Template for Mage_Page_Block_Html */

  1. Add the following code :
<?php 
$product = Mage::registry('current_product');
if($product == ''){
$category = Mage::registry('current_category');
if(is_object($category)){
$catLoaded = Mage::getModel('catalog/category')->load($category->getEntityId());
 $collection = $catLoaded->getProductCollection();
$collection->addAttributeToSelect('*');
if(count($collection) == 1){
foreach($collection as $product){
 $productUrl = $product->getProductUrl();
 header("location:$productUrl");
 exit;
  }
 }
 }
} 
?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!