From 93df3eee13ea1de4a121f03db1cea701b75f93fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Gaillard?= Date: Tue, 27 Dec 2011 10:40:32 +0000 Subject: [PATCH] [-] BO : BugFix : Admin suppliers errors message (add) & Admin attributes add / update fix --- classes/AdminController.php | 14 ++++++++------ .../admin/AdminAttributesGroupsController.php | 18 +++++++++++++++++- controllers/admin/AdminSuppliersController.php | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/classes/AdminController.php b/classes/AdminController.php index c7515df13..63418a7d1 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -580,10 +580,10 @@ class AdminControllerCore extends Controller */ public function processSave($token) { - if ((!$this->id_object) || (!Tools::getValue('submitAdd'.$this->table))) - return $this->processAdd($token); - else + if ($this->id_object) return $this->processUpdate($token); + else + return $this->processAdd($token); } /** @@ -596,12 +596,13 @@ class AdminControllerCore extends Controller /* Checking fields validity */ $this->validateRules(); - if (!count($this->_errors)) + if (count($this->_errors) <= 0) { $object = new $this->className(); + $this->copyFromPost($object, $this->table); $this->beforeAdd($object); - if (!$object->add()) + if (method_exists($object, 'add') && !$object->add()) { $this->_errors[] = Tools::displayError('An error occurred while creating object.'). ' '.$this->table.' ('.Db::getInstance()->getMsgError().')'; @@ -625,8 +626,9 @@ class AdminControllerCore extends Controller } $this->_errors = array_unique($this->_errors); - if (count($this->_errors) > 0) + if (count($this->_errors) > 0) { return; + } return $object; } diff --git a/controllers/admin/AdminAttributesGroupsController.php b/controllers/admin/AdminAttributesGroupsController.php index 58a96b8d3..ba88dc029 100644 --- a/controllers/admin/AdminAttributesGroupsController.php +++ b/controllers/admin/AdminAttributesGroupsController.php @@ -435,6 +435,22 @@ class AdminAttributesGroupsControllerCore extends AdminController } } + /** + * Call the right method for creating or updating object + * + * @param $token + * @return mixed + */ + public function processSave() + { + $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; + + if ((int)Tools::getValue('id_attribute') <= 0) + return $this->processAdd($token); + else + return $this->processUpdate($token); + } + public function postProcess() { if (!Combination::isFeatureActive()) @@ -486,7 +502,7 @@ class AdminAttributesGroupsControllerCore extends AdminController $_POST['position'] = DB::getInstance()->getValue($sql); } $_POST['id_parent'] = 0; - parent::postProcess(); + $this->processSave(); } } else diff --git a/controllers/admin/AdminSuppliersController.php b/controllers/admin/AdminSuppliersController.php index fcec25ac0..3ba3300ff 100644 --- a/controllers/admin/AdminSuppliersController.php +++ b/controllers/admin/AdminSuppliersController.php @@ -327,7 +327,7 @@ class AdminSuppliersControllerCore extends AdminController if (Tools::isSubmit('submitAdd'.$this->table)) { - if (!($obj = $this->loadObject(true))) + if (Tools::isSubmit('id_supplier') && !($obj = $this->loadObject(true))) return; // updates/creates address if it does not exist