1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| 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']
);
} |
Partager