From 0c6bda85786c11c9d9f58d2f7d9b2821bb1aca6e Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Fri, 1 Apr 2016 15:23:01 +0200 Subject: [PATCH] update reorder --- adm/tabs/AdminProducts.php | 54 ++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/adm/tabs/AdminProducts.php b/adm/tabs/AdminProducts.php index 6e9c2809..17c47e23 100755 --- a/adm/tabs/AdminProducts.php +++ b/adm/tabs/AdminProducts.php @@ -257,38 +257,36 @@ class AdminProducts extends AdminTab // Récupération de tous les produits de la catégorie ordonée // selon la position de la sous-catégorie puis de la position dans la sous catégorie et sinon par id_product - $products = Db::getInstance()->ExecuteS(' + $first_products = Db::getInstance()->ExecuteS(' + SELECT cp.* + FROM `'._DB_PREFIX_.'category_product` cp + LEFT JOIN `'._DB_PREFIX_.'category` c ON (c.id_parent = cp.id_category) + LEFT JOIN `'._DB_PREFIX_.'category_product` cp2 ON (cp2.id_category = c.id_category AND cp2.id_product=cp.id_product) + RIGHT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product=cp.id_product) + WHERE cp.id_category ='.(int)$this->_category->id.' + AND cp2.id_product IS NOT NULL + ORDER BY c.position, cp2.position + '); + $second_products = Db::getInstance()->ExecuteS(' + SELECT cp.* + FROM `'._DB_PREFIX_.'category_product` cp + RIGHT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product=cp.id_product) + WHERE cp.id_category ='.(int)$this->_category->id.' + AND cp.id_product NOT IN ( - SELECT cp.* - FROM `'._DB_PREFIX_.'category_product` cp - LEFT JOIN `'._DB_PREFIX_.'category` c ON (c.id_parent = cp.id_category) - LEFT JOIN `'._DB_PREFIX_.'category_product` cp2 ON (cp2.id_category = c.id_category AND cp2.id_product=cp.id_product) - RIGHT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product=cp.id_product) - WHERE cp.id_category ='.(int)$this->_category->id.' - AND cp2.id_product IS NOT NULL - ORDER BY c.position, cp2.position - ) - UNION - ( - SELECT cp.* - FROM `'._DB_PREFIX_.'category_product` cp - RIGHT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product=cp.id_product) - WHERE cp.id_category ='.(int)$this->_category->id.' - AND cp.id_product NOT IN - ( - SELECT cp2.id_product - FROM `'._DB_PREFIX_.'category_product` cp2 - WHERE cp2.id_category IN - ( - SELECT id_category - FROM `'._DB_PREFIX_.'category` - WHERE id_parent ='.(int)$this->_category->id.' - ) - ) - ORDER BY cp.id_product + SELECT cp2.id_product + FROM `'._DB_PREFIX_.'category_product` cp2 + WHERE cp2.id_category IN + ( + SELECT id_category + FROM `'._DB_PREFIX_.'category` + WHERE id_parent ='.(int)$this->_category->id.' + ) ) + ORDER BY cp.id_product '); + $products = array_merge($first_products,$second_products); // Update des postions foreach ($products as $key => $product) { if ($key == 0){