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

This commit is contained in:
Christophe Latour 2017-09-18 17:49:50 +02:00
commit fa2704e7b8

View File

@ -9,8 +9,8 @@ class Category extends CategoryCore {
return parent::add($autodate, $nullValues);
}
public function update($nullValues = false){
public function update($nullValues = false)
{
$this->doNotRegenerateNTree = true;
$current = Db::getInstance()->getRow('SELECT `position`, `id_parent` FROM `' . _DB_PREFIX_ . 'category` WHERE `id_category` = ' . (int) $this->id);
if (!$current)
@ -32,6 +32,48 @@ class Category extends CategoryCore {
Module::hookExec('categoryUpdate', array('category' => $this));
return $ret;
}
public function updatePosition($way, $position)
{
if (!$res = Db::getInstance()->ExecuteS('
SELECT cp.`id_category`, cp.`position`, cp.`id_parent`
FROM `'._DB_PREFIX_.'category` cp
WHERE cp.`id_parent` = '.(int)$this->id_parent.'
ORDER BY cp.`position` ASC'
)) {
return false;
}
foreach ($res AS $category) {
if ((int)($category['id_category']) == (int)($this->id)) {
$movedCategory = $category;
}
}
if (!isset($movedCategory) || !isset($position)) {
return false;
}
// < and > statements rather than BETWEEN operator
// since BETWEEN is treated differently according to databases
$result = (Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'category`
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
WHERE `position`
'.($way
? '> '.(int)($movedCategory['position']).' AND `position` <= '.(int)($position)
: '< '.(int)($movedCategory['position']).' AND `position` >= '.(int)($position)).'
AND `id_parent`='.(int)($movedCategory['id_parent']))
AND Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'category`
SET `position` = '.(int)($position).'
WHERE `id_parent` = '.(int)($movedCategory['id_parent']).'
AND `id_category`='.(int)($movedCategory['id_category'])));
Module::hookExec('categoryUpdate', array('category' => $this, 'position' => true));
return $result;
}
public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1, $checkAccess = true)
{