From 767591a436dc074c41d9b331495e9cbb7641fb45 Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Mon, 16 Jan 2012 10:48:51 +0000 Subject: [PATCH] // Fix new combination form submit --- controllers/admin/AdminProductsController.php | 19 ++++++++++--------- js/attributesBack.js | 7 ++++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index d1ac2d2e4..b82514e36 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -543,16 +543,17 @@ class AdminProductsControllerCore extends AdminController public function processProductAttribute($token) { - if (!Combination::isFeatureActive()) + // Don't process if the combination fields have not been submitted + if (!Combination::isFeatureActive() || !isset($_POST['attribute'])) return; $is_virtual = (int)Tools::getValue('is_virtual'); - if (Validate::isLoadedObject($product = new Product((int)(Tools::getValue('id_product'))))) + if (Validate::isLoadedObject($product = $this->object)) { if (!isset($_POST['attribute_price']) || $_POST['attribute_price'] == null) $this->errors[] = Tools::displayError('Attribute price required.'); - if (!isset($_POST['attribute_combinaison_list']) || !count($_POST['attribute_combinaison_list'])) + if (!isset($_POST['attribute_combinaison_list']) || empty($_POST['attribute_combinaison_list'])) $this->errors[] = Tools::displayError('You must add at least one attribute.'); if (!count($this->errors)) @@ -1450,10 +1451,13 @@ class AdminProductsControllerCore extends AdminController if (isset($id) && !empty($id)) { $object = new $this->className($id); + $this->object = $object; + if (Validate::isLoadedObject($object)) { $this->_removeTaxFromEcotax(); $this->copyFromPost($object, $this->table); + if ($object->update()) { $this->addCarriers(); @@ -1470,20 +1474,17 @@ class AdminProductsControllerCore extends AdminController $this->processWarehouses($token); $this->processFeatures($token); $this->processProductAttribute($token); - $languages = Language::getLanguages(false); + if (!$this->updatePackItems($object)) $this->errors[] = Tools::displayError('An error occurred while adding products to the pack.'); else if (!$object->updateCategories($_POST['categoryBox'], true)) $this->errors[] = Tools::displayError('An error occurred while linking object.').' '.$this->table.' '.Tools::displayError('To categories'); - else if (!$this->updateTags($languages, $object)) + else if (!$this->updateTags(Language::getLanguages(false), $object)) $this->errors[] = Tools::displayError('An error occurred while adding tags.'); - else + else if (empty($this->errors)) { - //self::$currentIndex .= '&image_updated='.$id_image; Hook::exec('actionProductUpdate', array('product' => $object)); Search::indexation(false, $object->id); - //if (Tools::getValue('resizer') == 'man' && isset($id_image) && is_int($id_image) && $id_image) - // $this->redirect_after = self::$currentIndex.'&id_product='.$object->id.'&id_category='.(!empty($_REQUEST['id_category'])?$_REQUEST['id_category']:'1').'&edit='.strval(Tools::getValue('productCreated')).'&id_image='.$id_image.'&imageresize&toconf=4&submitAddAndStay='.((Tools::isSubmit('submitAdd'.$this->table.'AndStay') || Tools::getValue('productCreated') == 'on') ? 'on' : 'off').'&token='.(($token ? $token : $this->token)); // Save and preview if (Tools::isSubmit('submitAddProductAndPreview')) diff --git a/js/attributesBack.js b/js/attributesBack.js index 90b25b72e..4c77fae6c 100644 --- a/js/attributesBack.js +++ b/js/attributesBack.js @@ -369,5 +369,10 @@ function openCloseLayer(whichLayer) } $(document).ready(function(){ - $('#product_form').submit(function(){attr_selectall();console.log('couou');}); + $('#product_form').submit(function(){ + attr_selectall(); + // If the new combination form is hidden, remove it so that empty fields are not submitted + if ($('#add_new_combination').is(':hidden')) + $('#add_new_combination').remove(); + }); }); \ No newline at end of file