If Category Have Only One Product Auto Redirect To Product Details Page Magento

Put this code your category page template file example 2column_left.phtml

$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;
            }
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *