[-] BO: fix PSCFV-3681 - addresses of warehouses cant be updated

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@16924 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rGaillard
2012-08-21 09:08:02 +00:00
parent 6277b71d20
commit e353808db3
+44 -40
View File
@@ -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());