Merge branch 'develop' of gitlab.antadis.net:dev-antadis/bebeboutik into develop

This commit is contained in:
Christophe Latour 2017-09-15 11:21:48 +02:00
commit 94eaef5407

View File

@ -64,6 +64,67 @@ class AdminCategories extends AdminTab
parent::__construct();
}
protected function recurseCategoryTreeFlat($id_category, $category_selected, $level_start = 1)
{
global $currentIndex;
$id_lang = _USER_ID_LANG_;
$categoriesOption = "";
$active = false;
$sql = 'SELECT c.`id_category`, cl.`name`, c.`level_depth`
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`
WHERE `id_lang` = '.(int)($id_lang).'
AND c.`id_parent` = '.(int)($id_category).'
'.($active ? 'AND `active` = 1' : '').'
ORDER BY `position` ASC';
$categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
// Get level
if (count($categories) > 0) {
foreach($categories as $c) {
$levelStr = " ";
$levelStr = str_pad($levelStr, $c['level_depth']-$level_start, '-', STR_PAD_LEFT);
if ($levelStr == " ") {
$levelStr = "";
}
$categoriesOption.= '<option value="" data-url="'.$currentIndex.'&'.
$this->identifier.'='.$c['id_category'].'&view'.$this->table.'&token='.($token!=NULL ? $token : $this->token).'"'.
($category_selected == $c['id_category'] ? ' selected="selected"' : '').'>'.
$levelStr.$c['name'].'</option>';
$children = $this->recurseCategoryTreeFlat($c['id_category'], $category_selected, $level_start);
$categoriesOption.= $children;
}
}
return $categoriesOption;
}
protected function displayListTree()
{
if ($this->_category->id_category == 1) {
echo "";
}
// Go to list category and subcategory
else {
$categoryMain = null;
// Get Upper category_id
$categoryM = new Category($this->_category->id_category);
$categoryParents = $categoryM->getParentsCategories();
if (count($categoryParents) > 0) {
$categoryRoot = $categoryParents[count($categoryParents)-1];
}
if ($categoryRoot) {
echo '<select id="selectCategory" style="margin:0 5px;padding:4px;font-size:14px;"
onchange="document.location=$(this).find(\'option:selected\').data(\'url\');">';
echo $this->recurseCategoryTreeFlat($categoryRoot['id_category'], $this->_category->id_category);
echo '</select>';
}
}
}
public function displayListContent($token = NULL)
{
global $currentIndex, $cookie;
@ -384,7 +445,9 @@ class AdminCategories extends AdminTab
/**
* @Override regenerateEntireNTree
*/
echo '<br/><a onclick="return confirm(\''.$this->l('Regenerate entire categories tree ?').'\');" class="button btn" href="'.__PS_BASE_URI__.substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)).'?tab=AdminCatalog&regenerateTree&token='.($token!=NULL ? $token : $this->token).'"">' . $this->l('Regenerate NTree') . '</a><br/>';
echo '<br/><a onclick="return confirm(\''.$this->l('Regenerate entire categories tree ?').'\');" class="button btn" href="'.__PS_BASE_URI__.substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)).'?tab=AdminCatalog&regenerateTree&token='.($token!=NULL ? $token : $this->token).'"">' . $this->l('Regenerate NTree') . '</a>';
$this->displayListTree();
echo '<br/>';
$this->displayList($token);
echo '</div>';