2016-03-31 16:40:09 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Category extends CategoryCore
|
|
|
|
{
|
|
|
|
const CATEGORY_HOME = 2;
|
|
|
|
const CATEGORY_COLLECTION = 3;
|
2016-10-21 11:37:55 +02:00
|
|
|
const CATEGORY_COLLECTION_ALL = 8;
|
2016-03-31 16:40:09 +02:00
|
|
|
const CATEGORY_SAVEUR = 12;
|
2016-10-21 11:37:55 +02:00
|
|
|
const CATEGORY_SAVEUR_ALL = 27;
|
2017-05-30 18:36:44 +02:00
|
|
|
const CATEGORY_PLV = 71;
|
|
|
|
const CATEGORY_PLV_ALL = 72;
|
2017-05-31 09:05:10 +02:00
|
|
|
const CATEGORY_TPDBELGE = 75;
|
|
|
|
const CATEGORY_TPDBELGE_ALL = 80;
|
2016-03-31 16:40:09 +02:00
|
|
|
|
|
|
|
public static function getCategoriesTree($id_parent, $currentDepth = 0, $depth = 3, $context = null)
|
|
|
|
{
|
|
|
|
if(!$context)
|
|
|
|
{
|
|
|
|
$context = Context::getContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
if($currentDepth >= $depth)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
SELECT DISTINCT c.`id_category`, cl.`name`
|
|
|
|
FROM `'._DB_PREFIX_.'category` c
|
|
|
|
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON cl.`id_category` = c.`id_category`
|
|
|
|
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON cs.`id_category` = c.`id_category`
|
|
|
|
WHERE c.`id_parent` = '.$id_parent.'
|
|
|
|
AND c.`active` = 1
|
|
|
|
AND cl.`id_lang` = '.$context->language->id.'
|
|
|
|
AND cs.`id_shop` = '.$context->shop->id.'
|
|
|
|
AND cl.`id_shop` = '.$context->shop->id.'
|
|
|
|
ORDER BY cs.`position` ASC
|
|
|
|
';
|
|
|
|
|
|
|
|
$categories = Db::getInstance()->executeS($query);
|
|
|
|
|
|
|
|
if(!$categories)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($categories as $key => $category)
|
|
|
|
{
|
|
|
|
$categories[$key]['link'] = $context->link->getCategoryLink($category['id_category']);
|
|
|
|
$categories[$key]['children'] = self::getCategoriesTree($category['id_category'], $currentDepth+1, $depth, $context);
|
|
|
|
|
|
|
|
if($categories[$key]['children'])
|
|
|
|
{
|
|
|
|
foreach($categories[$key]['children'] as $idx => $childrenCategory)
|
|
|
|
{
|
|
|
|
$categories[$key]['children'][$idx]['link'] = $context->link->getCategoryLink($childrenCategory['id_category']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $categories;
|
|
|
|
}
|
|
|
|
}
|