Jump to content

afficher fiche produit directement si un seul produit


Recommended Posts

Bonjour,

 

je souhaite afficher directement la fiche produit si il n'en a qu'un produit dans la sous catégorie sélectionner dans le menu.

 

c'est vraiment important.

 

j'ai trouvé cela sur un forum mais cela ne change rien au site.

 

Je l'ai mis a la place de getTree de la page blockcategorie.php:

public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0)
   {
      global $link, $cookie;

      $children = array();
      if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth))
         foreach ($resultParents[$id_category] as $subcat)
            $children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1);
      if (!isset($resultIds[$id_category]))
         return false;
      
      $cat = New Category($id_category);
      $nb_products = $cat-> getProducts($cookie->id_lang, 1, 10, NULL, NULL, true); // on récupère le nombre de produits de la catégorie

      if ($nb_products == 1)
      {
         //si le nombre de produits est égal à 1, on récupère le lien vers ce produit
         $prod_list = $cat-> getProducts($cookie->id_lang, 1, 10, NULL, NULL);
         $catlink = $link->getProductLink($prod_list[0]['id_product'], $prod_list[0]['link_rewrite']);
      }
      // sinon on retourne le lien vers la catégorie (comportement identique à celui d'origine)
      else
         $catlink = $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']);

      return array('id' => $id_category
               , 'link' => $catlink
               , 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description']
               , 'children' => $children
               , 'meta_title' => $resultIds[$id_category]['meta_title']
               );
   }

merci.

Edited by kate66 (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...