From 2db490b3c25efa687ef0eda01411622b3b05ae49 Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Fri, 13 Apr 2012 16:03:05 +0000 Subject: [PATCH] [-] BO : fix bug #PSFV-839 - Reset products features while editing products git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14640 b9a71923-0436-4b27-9f14-aed3839534dd --- .../controllers/products/accounting.tpl | 2 +- .../controllers/products/associations.tpl | 1 + .../controllers/products/attachments.tpl | 2 +- .../controllers/products/combinations.tpl | 1 + .../controllers/products/customization.tpl | 1 + .../controllers/products/features.tpl | 2 +- .../template/controllers/products/images.tpl | 1 + .../controllers/products/informations.tpl | 1 + .../template/controllers/products/pack.tpl | 2 +- .../template/controllers/products/prices.tpl | 2 +- .../controllers/products/quantities.tpl | 2 +- .../template/controllers/products/seo.tpl | 1 + .../controllers/products/shipping.tpl | 1 + .../controllers/products/suppliers.tpl | 2 +- .../controllers/products/virtualproduct.tpl | 1 + .../controllers/products/warehouses.tpl | 2 +- controllers/admin/AdminProductsController.php | 96 +++++++++++++------ 17 files changed, 84 insertions(+), 36 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/products/accounting.tpl b/admin-dev/themes/default/template/controllers/products/accounting.tpl index 6205a7694..537bfe68e 100644 --- a/admin-dev/themes/default/template/controllers/products/accounting.tpl +++ b/admin-dev/themes/default/template/controllers/products/accounting.tpl @@ -25,7 +25,7 @@ *} {if isset($product->id)} - +

{l s='Accounting'}

{if !empty($error)} diff --git a/admin-dev/themes/default/template/controllers/products/associations.tpl b/admin-dev/themes/default/template/controllers/products/associations.tpl index 093a4b111..fa8c43b5a 100644 --- a/admin-dev/themes/default/template/controllers/products/associations.tpl +++ b/admin-dev/themes/default/template/controllers/products/associations.tpl @@ -24,6 +24,7 @@ * International Registered Trademark & Property of PrestaShop SA *} +

{l s='Associations'}

diff --git a/admin-dev/themes/default/template/controllers/products/attachments.tpl b/admin-dev/themes/default/template/controllers/products/attachments.tpl index 87f187a64..1b3181ac9 100644 --- a/admin-dev/themes/default/template/controllers/products/attachments.tpl +++ b/admin-dev/themes/default/template/controllers/products/attachments.tpl @@ -25,7 +25,7 @@ *} {if isset($obj->id)} - +

{l s='Attachment'}

diff --git a/admin-dev/themes/default/template/controllers/products/combinations.tpl b/admin-dev/themes/default/template/controllers/products/combinations.tpl index 248e76182..030474776 100644 --- a/admin-dev/themes/default/template/controllers/products/combinations.tpl +++ b/admin-dev/themes/default/template/controllers/products/combinations.tpl @@ -38,6 +38,7 @@ {if isset($product->id)} + - +

{l s='Pack'}

diff --git a/admin-dev/themes/default/template/controllers/products/prices.tpl b/admin-dev/themes/default/template/controllers/products/prices.tpl index 5e3ea9c1b..71627a5d7 100644 --- a/admin-dev/themes/default/template/controllers/products/prices.tpl +++ b/admin-dev/themes/default/template/controllers/products/prices.tpl @@ -101,7 +101,7 @@ jQuery(document).ready(Customer.init); {* END CUSTOMER AUTO-COMPLETE / TO REFACTO *} - +

{l s='Product price'}

{l s='You must enter either the pre-tax retail price, or the retail price with tax. The input field will be automatically calculated.'} diff --git a/admin-dev/themes/default/template/controllers/products/quantities.tpl b/admin-dev/themes/default/template/controllers/products/quantities.tpl index b64149d40..b78ea6af5 100644 --- a/admin-dev/themes/default/template/controllers/products/quantities.tpl +++ b/admin-dev/themes/default/template/controllers/products/quantities.tpl @@ -25,7 +25,7 @@ *} {if isset($product->id)} - +

{l s='Available quantities for sale'}

diff --git a/admin-dev/themes/default/template/controllers/products/seo.tpl b/admin-dev/themes/default/template/controllers/products/seo.tpl index ee2add40e..ef0a4b84d 100644 --- a/admin-dev/themes/default/template/controllers/products/seo.tpl +++ b/admin-dev/themes/default/template/controllers/products/seo.tpl @@ -24,6 +24,7 @@ * International Registered Trademark & Property of PrestaShop SA *} +

{l s='SEO'}

diff --git a/admin-dev/themes/default/template/controllers/products/shipping.tpl b/admin-dev/themes/default/template/controllers/products/shipping.tpl index 905aa80a5..5d193961c 100644 --- a/admin-dev/themes/default/template/controllers/products/shipping.tpl +++ b/admin-dev/themes/default/template/controllers/products/shipping.tpl @@ -24,6 +24,7 @@ * International Registered Trademark & Property of PrestaShop SA *} +

1. {l s='Info.'}

{l s='Shipping'}

diff --git a/admin-dev/themes/default/template/controllers/products/suppliers.tpl b/admin-dev/themes/default/template/controllers/products/suppliers.tpl index 2b8d0cf9f..cf410257c 100644 --- a/admin-dev/themes/default/template/controllers/products/suppliers.tpl +++ b/admin-dev/themes/default/template/controllers/products/suppliers.tpl @@ -26,7 +26,7 @@ {if isset($product->id)} - +

{l s='Suppliers of the current product'}

diff --git a/admin-dev/themes/default/template/controllers/products/virtualproduct.tpl b/admin-dev/themes/default/template/controllers/products/virtualproduct.tpl index 88bc6c029..7caaf9b53 100644 --- a/admin-dev/themes/default/template/controllers/products/virtualproduct.tpl +++ b/admin-dev/themes/default/template/controllers/products/virtualproduct.tpl @@ -101,6 +101,7 @@ +

{l s='Virtual Product (services, booking and downloadable products)'}

diff --git a/admin-dev/themes/default/template/controllers/products/warehouses.tpl b/admin-dev/themes/default/template/controllers/products/warehouses.tpl index e0a250abd..47db895ce 100644 --- a/admin-dev/themes/default/template/controllers/products/warehouses.tpl +++ b/admin-dev/themes/default/template/controllers/products/warehouses.tpl @@ -26,7 +26,7 @@ {if isset($product->id)} - +

{l s='Product location in warehouses'}

diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index a262bb244..4b5b97430 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -70,6 +70,8 @@ class AdminProductsControllerCore extends AdminController protected $position_identifier = 'id_product'; + protected $submitted_tabs; + public function __construct() { $this->table = 'product'; @@ -1459,7 +1461,7 @@ class AdminProductsControllerCore extends AdminController $this->updateDownloadProduct($this->object); $this->object->setTaxRulesGroup((int)Tools::getValue('id_tax_rules_group'), true); - if (!count($this->errors)) + if (empty($this->errors)) { $languages = Language::getLanguages(false); if (!$this->object->updateCategories(Tools::getValue('categoryBox'))) @@ -1511,16 +1513,33 @@ class AdminProductsControllerCore extends AdminController } else $this->object->delete(); + // if errors : stay on edit page + $this->display = 'edit'; } else $this->errors[] = Tools::displayError('An error occurred while creating object.').' '.$this->table.''; } + protected function isTabSubmitted($tab_name) + { + if (!is_array($this->submitted_tabs)) + $this->submitted_tabs = Tools::getValue('submitted_tabs'); + + if (is_array($this->submitted_tabs) && in_array($tab_name, $this->submitted_tabs)) + return true; + + return false; + } + public function processUpdate() { $this->checkProduct(); + if (!empty($this->errors)) + { + //$this->display = 'edit'; return false; + } $id = (int)Tools::getValue('id_'.$this->table); /* Update an existing product */ @@ -1537,27 +1556,43 @@ class AdminProductsControllerCore extends AdminController if ($object->update()) { - $this->addCarriers(); - $this->updateAccessories($object); + if ($this->isTabSubmitted('Shipping')) + $this->addCarriers(); + if ($this->isTabSubmitted('Associations')) + { + $this->updateAccessories($object); + $this->updateAssoShop((int)$object->id); + } + + if ($this->isTabSubmitted('Accounting')) + $this->processAccounting(); + if ($this->isTabSubmitted('Suppliers')) + $this->processSuppliers(); + if ($this->isTabSubmitted('Warehouses')) + $this->processWarehouses(); + if ($this->isTabSubmitted('Features')) + $this->processFeatures(); + if ($this->isTabSubmitted('Combinations')) + $this->processProductAttribute(); + if ($this->isTabSubmitted('Prices')) + { + $this->processPriceAddition(); + $this->processSpecificPricePriorities(); + $this->object->setTaxRulesGroup((int)Tools::getValue('id_tax_rules_group')); + } + if ($this->isTabSubmitted('Customization')) + $this->processCustomizationConfiguration(); + if ($this->isTabSubmitted('Attachments')) + $this->processAttachments(); + + $this->updatePackItems($object); $this->updateDownloadProduct($object, 1); - $this->updateAssoShop((int)$object->id); - $this->processAccounting(); - $this->processSuppliers(); - $this->processWarehouses(); - $this->processFeatures(); - $this->processProductAttribute(); - $this->processPriceAddition(); - $this->processSpecificPricePriorities(); - $this->processCustomizationConfiguration(); - $this->object->setTaxRulesGroup((int)Tools::getValue('id_tax_rules_group')); - $this->processAttachments(); - if (!$this->updatePackItems($object)) - $this->errors[] = Tools::displayError('An error occurred while adding products to the pack.'); - elseif (!$object->updateCategories(Tools::getValue('categoryBox'), true)) + $this->updateTags(Language::getLanguages(false), $object); + + if (!$object->updateCategories(Tools::getValue('categoryBox'), true)) $this->errors[] = Tools::displayError('An error occurred while linking object.').' '.$this->table.' '.Tools::displayError('To categories'); - elseif (!$this->updateTags(Language::getLanguages(false), $object)) - $this->errors[] = Tools::displayError('An error occurred while adding tags.'); - elseif (empty($this->errors)) + + if (empty($this->errors)) { if (in_array($object->visibility, array('both', 'search'))) Search::indexation(false, $object->id); @@ -1589,6 +1624,9 @@ class AdminProductsControllerCore extends AdminController $this->redirect_after = self::$currentIndex.(Tools::getIsset('id_category') ? '&id_category='.(int)Tools::getValue('id_category') : '').'&conf=4&token='.$this->token; } } + // if errors : stay on edit page + else + $this->display = 'edit'; } else $this->errors[] = Tools::displayError('An error occurred while updating object.').' '.$this->table.' ('.Db::getInstance()->getMsgError().')'; @@ -1742,7 +1780,8 @@ class AdminProductsControllerCore extends AdminController } if (Tools::getValue('virtual_product_expiration_date') && !Validate::isDate(Tools::getValue('virtual_product_expiration_date') && !empty($is_virtual_file)) - && Tools::getValue('virtual_product_expiration_date_attribute') && !Validate::isDate(Tools::getValue('virtual_product_expiration_date_attribute'))) + && Tools::getValue('virtual_product_expiration_date_attribute') && !Validate::isDate(Tools::getValue('virtual_product_expiration_date_attribute')) + ) { if (!Tools::getValue('virtual_product_expiration_date')) { @@ -1881,15 +1920,17 @@ class AdminProductsControllerCore extends AdminController */ public function updateTags($languages, $product) { - $tagError = true; + $tag_success = true; /* Reset all tags for THIS product */ if (!Tag::deleteTagsForProduct((int)$product->id)) - return false; + $this->errors[] = Tools::displayError('An error occurred while deleting previous tags.'); /* Assign tags to this product */ foreach ($languages as $language) if ($value = Tools::getValue('tags_'.$language['id_lang'])) - $tagError &= Tag::addTags($language['id_lang'], (int)$product->id, $value); - return $tagError; + $tag_success &= Tag::addTags($language['id_lang'], (int)$product->id, $value); + + if (!$tag_success) + $this->errors[] = Tools::displayError('An error occurred while adding tags.'); } public function initContent($token = null) @@ -2132,7 +2173,7 @@ class AdminProductsControllerCore extends AdminController { parent::initToolbarTitle(); if ($product = $this->loadObject(true)) - if ((bool)$product->id) + if ((bool)$product->id && $this->display != 'list') $this->toolbar_title[2] = $this->toolbar_title[2].' ('.$product->name[$this->context->language->id].')'; } @@ -3959,11 +4000,10 @@ class AdminProductsControllerCore extends AdminController if ($qty > 0 && isset($item_id)) { if (!Pack::addItem((int)$product->id, (int)$item_id, (int)$qty)) - return false; + $this->errors[] = Tools::displayError('An error occurred while adding products to the pack.'); } } } - return true; } public function getL($key)