From 09d4e10b222261dd0ecfd4fbcb92b3c6ac755579 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 7 Dec 2023 18:52:06 +0530 Subject: [PATCH] Fix count and handle issues --- .../products/helpers/list/list_content.tpl | 36 +++++++++++++++++++ classes/Product.php | 4 +-- controllers/admin/AdminProductsController.php | 25 +++++++------ js/admin/dnd.js | 2 +- 4 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 adminhtl/themes/default/template/controllers/products/helpers/list/list_content.tpl diff --git a/adminhtl/themes/default/template/controllers/products/helpers/list/list_content.tpl b/adminhtl/themes/default/template/controllers/products/helpers/list/list_content.tpl new file mode 100644 index 000000000..abb543aa2 --- /dev/null +++ b/adminhtl/themes/default/template/controllers/products/helpers/list/list_content.tpl @@ -0,0 +1,36 @@ +{** + * 2010-2023 Webkul. + * + * NOTICE OF LICENSE + * + * All right is reserved, + * Please go through LICENSE.txt file inside our module + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to newer + * versions in the future. If you wish to customize this module for your + * needs please refer to CustomizationPolicy.txt file inside our module for more information. + * + * @author Webkul IN + * @copyright 2010-2023 Webkul IN + * @license LICENSE.txt + *} + +{extends file='helpers/list/list_content.tpl'} + +{block name='td_content'} + {if isset($tr.$key) && isset($params.position)} + {if $order_by == 'position' && $order_way != 'DESC'} +
+
+ {$tr.$key.position + 1} +
+
+ {else} + {$tr.$key.position + 1} + {/if} + {else} + {$smarty.block.parent} + {/if} +{/block} diff --git a/classes/Product.php b/classes/Product.php index e6375ab88..a3e9c6a47 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -649,12 +649,12 @@ class ProductCore extends ObjectModel * @param int $position * return boolean Update result */ - public function updatePosition($way, $position) + public function updatePosition($way, $position, $id_category = null) { if (!$res = Db::getInstance()->executeS(' SELECT cp.`id_product`, cp.`position`, cp.`id_category` FROM `'._DB_PREFIX_.'category_product` cp - WHERE cp.`id_category` = '.(int)Tools::getValue('id_category', 1).' + WHERE cp.`id_category` = '.(int) ($id_category ? $id_category: Tools::getValue('id_category', 1)).' ORDER BY cp.`position` ASC') ) { return false; diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 6e92d6cb2..d0e8748ae 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -144,14 +144,19 @@ class AdminProductsControllerCore extends AdminController } } - if (Shop::isFeatureActive() && $this->context->cookie->id_category_products_filter) { - $category = new Category((int)$this->context->cookie->id_category_products_filter); + if (Tools::getValue('productFilter_a!id_category_default') === '') { + $this->context->cookie->id_category_room_types_filter = false; + } + + if (Shop::isFeatureActive() && $this->context->cookie->id_category_room_types_filter) { + $category = new Category((int)$this->context->cookie->id_category_room_types_filter); if (!$category->inShop()) { - $this->context->cookie->id_category_products_filter = false; + $this->context->cookie->id_category_room_types_filter = false; Tools::redirectAdmin($this->context->link->getAdminLink('AdminProducts')); } } + // to support filter URLs with 'id_category' parameter if ($id_category = (int)Tools::getValue('id_category')) { $_POST['submitFilter'] = '1'; $_POST['productFilter_a!id_category_default'] = $id_category; @@ -161,12 +166,13 @@ class AdminProductsControllerCore extends AdminController || ($id_category = (int) Tools::getValue('productFilter_a!id_category_default')) ) { $this->id_current_category = $id_category; - $this->context->cookie->id_category_products_filter = $id_category; - } elseif ($id_category = $this->context->cookie->id_category_products_filter) { + $this->context->cookie->id_category_room_types_filter = $id_category; + } elseif ($id_category = $this->context->cookie->id_category_room_types_filter) { $this->id_current_category = $id_category; } if ($this->id_current_category) { $this->_category = new Category((int)$this->id_current_category); + $this->position_group_identifier = (int) $this->id_current_category; } else { $this->_category = new Category(); } @@ -213,7 +219,6 @@ class AdminProductsControllerCore extends AdminController // show the list of the product according to the booking or service products $this->_where .= ' AND a.`booking_product` = 1'; - $this->_use_found_rows = false; $this->_group = ' GROUP BY a.`id_product`'; $this->fields_list = array(); @@ -468,7 +473,7 @@ class AdminProductsControllerCore extends AdminController parent::processResetFilters($list_id); // reset category filter - $this->context->cookie->id_category_products_filter = false; + $this->context->cookie->id_category_room_types_filter = false; } /** @@ -3530,7 +3535,7 @@ class AdminProductsControllerCore extends AdminController $product = $obj; // Prepare Categories tree for display in Associations tab $root = Category::getRootCategory(); - $default_category = $this->context->cookie->id_category_products_filter ? $this->context->cookie->id_category_products_filter : Context::getContext()->shop->id_category; + $default_category = $this->context->cookie->id_category_room_types_filter ? $this->context->cookie->id_category_room_types_filter : Context::getContext()->shop->id_category; if (!$product->id || !$product->isAssociatedToShop()) { $selected_cat = Category::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->default_form_language); } else { @@ -4694,7 +4699,7 @@ class AdminProductsControllerCore extends AdminController if ($this->tabAccess['edit'] === '1') { $way = (int)(Tools::getValue('way')); $id_product = (int)Tools::getValue('id_product'); - $id_category = (int)Tools::getValue('id_category'); + $id_category = (int)Tools::getValue('id_category_hotel'); $positions = Tools::getValue('product'); $page = (int)Tools::getValue('page'); $selected_pagination = (int)Tools::getValue('selected_pagination'); @@ -4709,7 +4714,7 @@ class AdminProductsControllerCore extends AdminController } if ($product = new Product((int)$pos[2])) { - if (isset($position) && $product->updatePosition($way, $position)) { + if (isset($position) && $product->updatePosition($way, $position, $id_category)) { $category = new Category((int)$id_category); if (Validate::isLoadedObject($category)) { hook::Exec('categoryUpdate', array('category' => $category)); diff --git a/js/admin/dnd.js b/js/admin/dnd.js index 6be4a261b..7e2c46c67 100644 --- a/js/admin/dnd.js +++ b/js/admin/dnd.js @@ -112,7 +112,7 @@ function initTableDnD(table) else if (tableId == 'product') { params = { action: 'updatePositions', - id_category: ids[1], + id_category_hotel: ids[1], id_product: ids[2], way: way };