diff --git a/controllers/admin/AdminWarehousesController.php b/controllers/admin/AdminWarehousesController.php index 48da5b24a..db5841cdd 100644 --- a/controllers/admin/AdminWarehousesController.php +++ b/controllers/admin/AdminWarehousesController.php @@ -501,51 +501,55 @@ class AdminWarehousesControllerCore extends AdminController if (!($obj = $this->loadObject(true))) return; - // updates/creates address if it does not exist - if (Tools::isSubmit('id_address') && (int)Tools::getValue('id_address') > 0) - $address = new Address((int)Tools::getValue('id_address')); // updates address - else - $address = new Address(); // creates address - - // sets the address - $address->alias = Tools::getValue('reference', null); - $address->lastname = 'warehouse'; // skip problem with numeric characters in warehouse name - $address->firstname = 'warehouse'; // skip problem with numeric characters in warehouse name - $address->address1 = Tools::getValue('address', null); - $address->address2 = Tools::getValue('address2', null); - $address->postcode = Tools::getValue('postcode', null); - $address->phone = Tools::getValue('phone', null); - $address->id_country = Tools::getValue('id_country', null); - $address->id_state = Tools::getValue('id_state', null); - $address->city = Tools::getValue('city', null); - - // validates the address - $validation = $address->validateController(); - - // checks address validity - if (count($validation) > 0) // if not valid - { - foreach ($validation as $item) - $this->errors[] = $item; - $this->errors[] = Tools::displayError('The address is not correct. Check if all required fields are filled.'); - } - else // valid - { - if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0) - $address->update(); - else - { - $address->save(); - $_POST['id_address'] = $address->id; - } - } - + $this->updateAddress(); + // hack for enable the possibility to update a warehouse without recreate new id $this->deleted = false; return parent::processAdd(); } } + + protected function updateAddress() + { + // updates/creates address if it does not exist + if (Tools::isSubmit('id_address') && (int)Tools::getValue('id_address') > 0) + $address = new Address((int)Tools::getValue('id_address')); // updates address + else + $address = new Address(); // creates address + // sets the address + $address->alias = Tools::getValue('reference', null); + $address->lastname = 'warehouse'; // skip problem with numeric characters in warehouse name + $address->firstname = 'warehouse'; // skip problem with numeric characters in warehouse name + $address->address1 = Tools::getValue('address', null); + $address->address2 = Tools::getValue('address2', null); + $address->postcode = Tools::getValue('postcode', null); + $address->phone = Tools::getValue('phone', null); + $address->id_country = Tools::getValue('id_country', null); + $address->id_state = Tools::getValue('id_state', null); + $address->city = Tools::getValue('city', null); + + // validates the address + $validation = $address->validateController(); + + // checks address validity + if (count($validation) > 0) // if not valid + { + foreach ($validation as $item) + $this->errors[] = $item; + $this->errors[] = Tools::displayError('The address is not correct. Check if all required fields are filled.'); + } + else // valid + { + if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0) + $address->update(); + else + { + $address->save(); + $_POST['id_address'] = $address->id; + } + } + } /** * @see AdminController::processDelete(); @@ -585,7 +589,7 @@ class AdminWarehousesControllerCore extends AdminController // loads object if (!($obj = $this->loadObject(true))) return; - + $this->updateAddress(); // handles carriers associations $obj->setCarriers(Tools::getValue('ids_carriers'), array());