From 7ca4e6918ba85ec9b7c72f936c8bba81798a7612 Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Fri, 23 Sep 2016 17:16:26 +0200 Subject: [PATCH] addition has to clean function to see if there are products to clean --- adm/tabs/AdminProducts.php | 64 +++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/adm/tabs/AdminProducts.php b/adm/tabs/AdminProducts.php index 30626859..9eb9b954 100755 --- a/adm/tabs/AdminProducts.php +++ b/adm/tabs/AdminProducts.php @@ -246,7 +246,7 @@ class AdminProducts extends AdminTab Tools::redirectAdmin($currentIndex.(Tools::getValue('id_category') ? '&id_category='.Tools::getValue('id_category') : '').'&token='.($token ? $token : $this->token)); } - if (Tools::isSubmit('clean_positionproduct')) { + if (Tools::isSubmit('clean_positionproduct') || Tools::isSubmit('has_to_cleanproduct')) { global $cookie, $currentIndex; if ($cookie->id_employee == 1) { @@ -256,31 +256,42 @@ class AdminProducts extends AdminTab WHERE cp.`id_category` = '.(int)$this->_category->id.' ORDER BY cp.`position` ASC '); + if (Tools::isSubmit('has_to_cleanproduct')) { + $hasToBeCleaned = array(); + foreach ($category_products as $key => $cat_product) { + if(!Validate::isLoadedObject($product = new Product((int)$cat_product['id_product']))){ + $hasToBeCleaned[] = (int)$cat_product['id_product']; + } + } + echo '
';var_dump($hasToBeCleaned);echo '
';die(); + } + if (Tools::isSubmit('clean_positionproduct')) { - // Position mise à 0 - Db::getInstance()->Execute(' - UPDATE `'._DB_PREFIX_.'category_product` - SET `position` = 0 - WHERE `id_category` = '.(int)$this->_category->id - ); + // Position mise à 0 + Db::getInstance()->Execute(' + UPDATE `'._DB_PREFIX_.'category_product` + SET `position` = 0 + WHERE `id_category` = '.(int)$this->_category->id + ); - $pos = 0; - foreach ($category_products as $key => $cat_product) { - if(Validate::isLoadedObject($product = new Product((int)$cat_product['id_product']))){ - Db::getInstance()->Execute(' - UPDATE `'._DB_PREFIX_.'category_product` - SET `position` = '. (int)($pos) .' - WHERE `id_product` = '.(int)$cat_product['id_product'].' - AND `id_category`='.(int)$this->_category->id - ); - $pos++; - } else { - Db::getInstance()->Execute(' - DELETE FROM `'._DB_PREFIX_.'category_product` - WHERE `id_category` = '.(int)$this->_category->id.' - AND `id_product` = '.(int)$cat_product['id_product'].' - '); - continue; + $pos = 0; + foreach ($category_products as $key => $cat_product) { + if(Validate::isLoadedObject($product = new Product((int)$cat_product['id_product']))){ + Db::getInstance()->Execute(' + UPDATE `'._DB_PREFIX_.'category_product` + SET `position` = '. (int)($pos) .' + WHERE `id_product` = '.(int)$cat_product['id_product'].' + AND `id_category`='.(int)$this->_category->id + ); + $pos++; + } else { + Db::getInstance()->Execute(' + DELETE FROM `'._DB_PREFIX_.'category_product` + WHERE `id_category` = '.(int)$this->_category->id.' + AND `id_product` = '.(int)$cat_product['id_product'].' + '); + continue; + } } } } @@ -1980,7 +1991,10 @@ class AdminProducts extends AdminTab echo '

'.$this->l('Order by product name').'

'; } if((int)$this->_category->id_oarent !=1 && $cookie->id_employee==1){ - echo '

'; + echo '

+ + +

'; echo '

'.$this->l('Re-Order by product position, clean all position of the category').'

'; }