Category to Product
This page was written in English, please see the English version for the most accurate code.
This code was tested on Prestashop 1.2
If you have a category with only one product, it may be the "main" product you sell on your site or just a category that currently has only one product. You can have it automatically redirect to the product page and save the user the extra click.
Add the following code to /category.php line #9 (below $rewrited_url = null;)
if ($category->id != 1 && is_object($cookie) &&
strpos($_SERVER['HTTP_USER_AGENT'],'bot') === false &&
strpos($_SERVER['HTTP_USER_AGENT'],'baidu') === false &&
strpos($_SERVER['HTTP_USER_AGENT'],'spider') === false &&
strpos($_SERVER['HTTP_USER_AGENT'],'Ask Jeeves') === false &&
strpos($_SERVER['HTTP_USER_AGENT'],'slurp') === false &&
strpos($_SERVER['HTTP_USER_AGENT'],'crawl') === false)
{
$category = new Category(intval(Tools::getValue('id_category')), intval($cookie->id_lang));
$nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true);
if ($nbProducts == 1)
{
$cat_products = $category->getProducts(intval($cookie->id_lang), 1, 1, $orderBy, $orderWay);
foreach ($cat_products AS $product)
{
Header( "Location: ".$product['link']);
exit;
}
}
}