Clean ajax and add parameter to not loop in categoryUpdate hook

This commit is contained in:
Michael RICOIS 2017-09-18 17:44:09 +02:00
parent bfae895cf1
commit f0e00394fa
3 changed files with 13 additions and 11 deletions

View File

@ -236,9 +236,8 @@ if (array_key_exists('ajaxCategoriesPositions', $_POST))
$category = new Category($id_category_to_move); $category = new Category($id_category_to_move);
if (Validate::isLoadedObject($category)) if (Validate::isLoadedObject($category))
{ {
if (isset($position) && $category->updatePosition($way, $position)) if (isset($position) && $category->updatePosition($way, $position))
{ {
Module::hookExec('categoryUpdate');
die(true); die(true);
} }
else else
@ -246,7 +245,6 @@ if (array_key_exists('ajaxCategoriesPositions', $_POST))
} }
else else
die('{"hasError" : true, "errors" : "This category can not be loaded"}'); die('{"hasError" : true, "errors" : "This category can not be loaded"}');
} }
if (array_key_exists('ajaxCMSCategoriesPositions', $_POST)) if (array_key_exists('ajaxCMSCategoriesPositions', $_POST))
@ -703,7 +701,7 @@ if (Tools::isSubmit('getAdminHomeElement'))
} }
if (Tools::isSubmit('getChildrenCategories') && Tools::getValue('id_category_parent')) if (Tools::isSubmit('getChildrenCategories') && Tools::getValue('id_category_parent'))
{ {
$children_categories = Category::getChildrenWithNbSelectedSubCat(Tools::getValue('id_category_parent'), Tools::getValue('selectedCat'), $cookie->id_lang); $children_categories = Category::getChildrenWithNbSelectedSubCat(Tools::getValue('id_category_parent'), Tools::getValue('selectedCat'), $cookie->id_lang);
die(Tools::jsonEncode($children_categories)); die(Tools::jsonEncode($children_categories));
} }

View File

@ -121,7 +121,7 @@ $(document).ready(function() {
// Down links // Down links
$(this).find('td.dragHandle a:even').attr('href', $(this).find('td.dragHandle a:even').attr('href').replace(up_reg, 'position='+ (i + 1) +'&')); $(this).find('td.dragHandle a:even').attr('href', $(this).find('td.dragHandle a:even').attr('href').replace(up_reg, 'position='+ (i + 1) +'&'));
}); });
tableDrag.find('tr').not('.nodrag').removeClass('alt_row'); tableDrag.find('tr').not('.nodrag').removeClass('alt_row');
tableDrag.find('tr:not(".nodrag"):odd').addClass('alt_row'); tableDrag.find('tr:not(".nodrag"):odd').addClass('alt_row');
tableDrag.find('tr td.dragHandle a:hidden').show(); tableDrag.find('tr td.dragHandle a:hidden').show();
@ -150,7 +150,7 @@ $(document).ready(function() {
// Down links // Down links
$(this).find('td.dragHandle a:even').attr('href', $(this).find('td.dragHandle a:even').attr('href').replace(up_reg, 'position='+ (i + 1) +'&')); $(this).find('td.dragHandle a:even').attr('href', $(this).find('td.dragHandle a:even').attr('href').replace(up_reg, 'position='+ (i + 1) +'&'));
}); });
tableDrag.find('tr').not('.nodrag').removeClass('alt_row'); tableDrag.find('tr').not('.nodrag').removeClass('alt_row');
tableDrag.find('tr:not(".nodrag"):odd').addClass('alt_row'); tableDrag.find('tr:not(".nodrag"):odd').addClass('alt_row');

View File

@ -473,11 +473,15 @@ class PrivateSales extends Module {
return $this->display(__FILE__, 'header.tpl'); return $this->display(__FILE__, 'header.tpl');
} }
public function hookCategoryAddition($params) { public function hookCategoryAddition($params)
$sale = Sale::getSaleFromCategory($params['category']->id, FALSE); {
if($sale !== NULL) { if (isset($params['position']) && $params['position'] === true) {
$sale->buildCategoryCache(); } else {
} $sale = Sale::getSaleFromCategory($params['category']->id, FALSE);
if($sale !== NULL) {
$sale->buildCategoryCache();
}
}
} }
public function hookCategoryUpdate($params) { public function hookCategoryUpdate($params) {