From d473c04ebe61180f5e95418162b74ee5dcb08221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gaillard?= Date: Thu, 14 Feb 2013 14:51:51 +0100 Subject: [PATCH] [*] BO: store filter by category in admin products --- .../products/helpers/list/list_header.tpl | 4 +- controllers/admin/AdminProductsController.php | 33 +++++++++++----- controllers/front/ProductController.php | 39 ++++++++++--------- 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/products/helpers/list/list_header.tpl b/admin-dev/themes/default/template/controllers/products/helpers/list/list_header.tpl index 3b7a193cc..faa1f679d 100644 --- a/admin-dev/themes/default/template/controllers/products/helpers/list/list_header.tpl +++ b/admin-dev/themes/default/template/controllers/products/helpers/list/list_header.tpl @@ -35,7 +35,7 @@ if (this.value !== "") location.href = base_url + '&id_category=' + parseInt(this.value); else - location.href = base_url; + location.href = base_url + '&reset_filter_category=1'; }); // Make sure the checkbox is checked/unchecked when the link is clicked @@ -47,7 +47,7 @@ else { $(this).find('input').removeAttr('checked'); - location.href = base_url; + location.href = base_url + '&reset_filter_category=1'; } }); }); diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 207a90841..c48f024e6 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -53,6 +53,8 @@ class AdminProductsControllerCore extends AdminController protected $position_identifier = 'id_product'; protected $submitted_tabs; + + protected $id_current_category; public function __construct() { @@ -122,17 +124,28 @@ class AdminProductsControllerCore extends AdminController $this->available_tabs_lang['Module'.ucfirst($m['module'])] = Module::getModuleName($m['module']); } - + if (Tools::getValue('reset_filter_category')) + $this->context->cookie->id_category_products_filter = false; /* Join categories table */ if ($id_category = (int)Tools::getValue('productFilter_cl!name')) { $this->_category = new Category((int)$id_category); $_POST['productFilter_cl!name'] = $this->_category->name[$this->context->language->id]; } - elseif ($id_category = Tools::getvalue('id_category')) - $this->_category = new Category((int)$id_category); else - $this->_category = new Category(); + { + if ($id_category = (int)Tools::getValue('id_category')) + { + $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->id_current_category = $id_category; + if ($this->id_current_category) + $this->_category = new Category((int)$this->id_current_category); + else + $this->_category = new Category(); + } $join_category = false; if (Validate::isLoadedObject($this->_category) && empty($this->_filter)) @@ -242,7 +255,8 @@ class AdminProductsControllerCore extends AdminController 'type' => 'bool', 'orderby' => false ); - if ((int)Tools::getValue('id_category')) + + if ((int)$this->id_current_category) $this->fields_list['position'] = array( 'title' => $this->l('Position'), 'width' => 70, @@ -2127,8 +2141,8 @@ class AdminProductsControllerCore extends AdminController } else { - if ($id_category = (int)Tools::getValue('id_category')) - self::$currentIndex .= '&id_category='.(int)$id_category; + if ($id_category = (int)$this->id_current_category) + self::$currentIndex .= '&id_category='.(int)$this->id_current_category; // If products from all categories are displayed, we don't want to use sorting by position if (!$id_category) @@ -2140,8 +2154,9 @@ class AdminProductsControllerCore extends AdminController unset($this->context->cookie->{$this->table.'Orderway'}); } } - $id_category = (int)Tools::getValue('id_category', 1); - $this->tpl_list_vars['is_category_filter'] = Tools::getValue('id_category') ? true : false; + if (!$id_category) + $id_category = 1; + $this->tpl_list_vars['is_category_filter'] = (bool)$this->id_current_category; // Generate category selection tree $helper = new Helper(); diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index f5d9db5fd..b29b7e7cc 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -87,19 +87,11 @@ class ProductControllerCore extends FrontController { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); + $this->errors[] = Tools::displayError('Product not found'); } - else - $this->canonicalRedirection(); - - if (!Validate::isLoadedObject($this->product)) - $this->errors[] = Tools::displayError('Product not found'); else { - if (Pack::isPack((int)$this->product->id) && !Pack::isInStock((int)$this->product->id)) - $this->product->quantity = 0; - - $this->product->description = $this->transformDescriptionWithImg($this->product->description); - + $this->canonicalRedirection(); /* * If the product is associated to the shop * and is active or not active but preview mode (need token + file_exists) @@ -181,11 +173,14 @@ class ProductControllerCore extends FrontController if (!$this->errors) { + if (Pack::isPack((int)$this->product->id) && !Pack::isInStock((int)$this->product->id)) + $this->product->quantity = 0; + + $this->product->description = $this->transformDescriptionWithImg($this->product->description); + // Assign to the template the id of the virtual product. "0" if the product is not downloadable. $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int)$this->product->id)); - // Product pictures management - require_once('images.inc.php'); $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); if (Tools::isSubmit('submitCustomizedDatas')) @@ -204,15 +199,21 @@ class ProductControllerCore extends FrontController else if (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture'); - $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true); + $pictures = array(); - foreach ($files as $file) - $pictures['pictures_'.$this->product->id.'_'.$file['index']] = $file['value']; - - $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true); $text_fields = array(); - foreach ($texts as $text_field) - $text_fields['textFields_'.$this->product->id.'_'.$text_field['index']] = str_replace('
', "\n", $text_field['value']); + if ($this->product->customizable) + { + $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true); + foreach ($files as $file) + $pictures['pictures_'.$this->product->id.'_'.$file['index']] = $file['value']; + + $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true); + + foreach ($texts as $text_field) + $text_fields['textFields_'.$this->product->id.'_'.$text_field['index']] = str_replace('
', "\n", $text_field['value']); + } + $this->context->smarty->assign(array( 'pictures' => $pictures, 'textFields' => $text_fields));