Merge branch 'ticket/r15172-change-adress-socol' into develop

This commit is contained in:
Michael RICOIS 2017-12-21 11:53:06 +01:00
commit 422f7e9820
2 changed files with 65 additions and 44 deletions

View File

@ -134,20 +134,26 @@ class AdminAddresses extends AdminTab
elseif ($postcode AND !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode))
$this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.');
}
/* If this address come from order's edition and is the same as the other one (invoice or delivery one)
** we delete its id_address to force the creation of a new one */
if ((int)(Tools::getValue('id_order')))
{
/**
* If this address come from order's edition and is the same as the other one
* (invoice or delivery one)
* we delete its id_address to force the creation of a new one
*/
if ((int)(Tools::getValue('id_order'))) {
$this->_redirect = false;
if (isset($_POST['address_type']))
$_POST['id_address'] = '';
if (isset($_POST['address_type'])) {
$_POST['id_address'] = '';
}
}
}
if (!sizeof($this->_errors))
parent::postProcess();
if (!sizeof($this->_errors)) {
parent::postProcess();
}
/* Reassignation of the order's new (invoice or delivery) address */
$address_type = ((int)(Tools::getValue('address_type')) == 2 ? 'invoice' : ((int)(Tools::getValue('address_type')) == 1 ? 'delivery' : ''));
if (isset($_POST['submitAdd'.$this->table]) AND ($id_order = (int)(Tools::getValue('id_order'))) AND !sizeof($this->_errors) AND !empty($address_type))
@ -156,43 +162,58 @@ class AdminAddresses extends AdminTab
$this->_errors[] = Tools::displayError('An error occurred while linking this address to its order.');
}
else {
// If socol AND delivery to DOM AND address change, update ps_socolissimo_delivery_info
$cart = Cart::getCartByOrderId($id_order);
if ((int)$cart->id_carrier == (int)Configuration::get('ANT_CARRIER_DOM')) {
$socol = Db::getInstance()->getRow('
SELECT * FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int)$cart->id.'
AND `cecountry` IN ("FR","BE","ES") AND `delivery_mode`="DOM"
AND (`pradress1`!="" OR `pradress2`!="" OR `pradress3`!="" OR `pradress4`!="")
');
if ($socol) {
// Get address
$delivery = new Address($_POST['id_address']);
// Update So Colissimo Address - for printing label
Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'socolissimo_delivery_info` SET
prname = "'.$delivery->lastname.'",
prfirstname = "'.$delivery->firstname.'",
cecompanyname = "'.$delivery->company.'",
cename = "'.$delivery->lastname.'",
cefirstname = "'.$delivery->firstname.'",
prcompladress = "",
pradress1 = "",
pradress2 = "",
pradress3 = "'.$delivery->address1.'",
pradress4 = "'.$delivery->address2.'",
przipcode = "'.$delivery->postcode.'",
prtown = "'.$delivery->city.'",
cephonenumber = "'.($delivery->phone_mobile ? $delivery->phone_mobile : ($delivery->phone ? $delivery->phone : '')).'"
WHERE id_cart = '.(int)$cart->id
);
}
}
Tools::redirectAdmin(Tools::getValue('back').'&conf=4');
}
}
}
protected function afterAdd($object)
{
$this->afterUpdate($object);
}
protected function afterUpdate($object)
{
if (isset($_POST['submitAdd'.$this->table]) &&
($id_order = (int)(Tools::getValue('id_order'))) && !sizeof($this->_errors)) {
// If socol AND delivery to DOM AND address change, update ps_socolissimo_delivery_info
$cart = Cart::getCartByOrderId($id_order);
if ((int)$cart->id_carrier == (int)Configuration::get('ANT_CARRIER_DOM')) {
$socol = Db::getInstance()->getRow('
SELECT * FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int)$cart->id.'
AND `cecountry` IN ("FR","BE","ES") AND `delivery_mode`="DOM"
AND (`pradress1`!="" OR `pradress2`!="" OR `pradress3`!="" OR `pradress4`!="")
');
if ($socol) {
// Get address
$delivery = new Address($_POST['id_address']);
// Update So Colissimo Address - for printing label
Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'socolissimo_delivery_info` SET
prname = "'.$delivery->lastname.'",
prfirstname = "'.$delivery->firstname.'",
cecompanyname = "'.$delivery->company.'",
cename = "'.$delivery->lastname.'",
cefirstname = "'.$delivery->firstname.'",
prcompladress = "",
pradress1 = "",
pradress2 = "",
pradress3 = "'.$delivery->address1.'",
pradress4 = "'.$delivery->address2.'",
przipcode = "'.$delivery->postcode.'",
prtown = "'.$delivery->city.'",
cephonenumber = "'.($delivery->phone_mobile ?
$delivery->phone_mobile : ($delivery->phone ? $delivery->phone : '')).'"
WHERE id_cart = '.(int)$cart->id
);
}
}
}
return true;
}
public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL)
{
parent::getList($id_lang, $orderBy, $orderWay, $start, $limit);

View File

@ -688,13 +688,13 @@ abstract class AdminTabCore
{
$this->copyFromPost($object, $this->table);
$result = $object->update();
$this->afterUpdate($object);
}
if (!$result)
$this->_errors[] = Tools::displayError('An error occurred while updating object.').' <b>'.$this->table.'</b> ('.Db::getInstance()->getMsgError().')';
elseif ($this->postImage($object->id) AND !sizeof($this->_errors))
{
$parent_id = (int)(Tools::getValue('id_parent', 1));
$this->afterUpdate($object);
// Specific back redirect
if ($back = Tools::getValue('back'))
Tools::redirectAdmin(urldecode($back).'&conf=4');