bebeboutik/modules/ant_changeaddress/change_address.php

149 lines
6.5 KiB
PHP
Raw Normal View History

<?php
require_once(dirname(__FILE__).'/../../config/config.inc.php');
require_once(dirname(__FILE__).'/../../init.php');
require_once(dirname(__FILE__).'/../../modules/ant_changeaddress/ant_changeaddress.php');
$controller->preProcess();
$ant_changeaddress = new Ant_Changeaddress();
$lang = (int) $cookie->id_lang;
$isolang = Language::getIsoById($lang);
$errors = array();
if ($cookie->isLogged()) {
$smarty->assign('isLogged', 1);
$customer = new Customer((int)($cookie->id_customer));
if (!Validate::isLoadedObject($customer)) {
die(Tools::displayError('Customer not found'));
}
if(Tools::getValue('id_order')) {
$id_order = Tools::getValue('id_order');
$order = new Order((int) $id_order);
$order_cart = new Cart((int) $order->id_cart);
if((int)$order->id_customer != (int)$customer->id) {
$errors[] = Tools::displayError('Invalid customer for this order');
} else {
$address = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE id_cart = '.pSQL(intval($order->id_cart)).'
');
if ($address) {
if ($address['delivery_mode'] == "DOM"){
$delivery_mode = "DOM";
$mode = array(
'2' => 'Livraison à domicile (DOM)',
'3' => 'Livraison à domicile (DOM)',
);
} elseif($address['delivery_mode'] == "BPR") {
$delivery_mode = "BPR";
$mode = array(
'2' => 'Livraison en Bureau de Poste (BPR)',
'3' => 'Livraison en Bureau de Poste (BPR)',
);
} elseif($address['delivery_mode'] == "A2P"){
$delivery_mode = "A2P";
$mode = array(
'2' => 'Livraison Commerce de proximité (A2P)',
'3' => 'Livraison Commerce de proximité (A2P)',
);
}
if ($delivery_mode == "BPR" || $delivery_mode == "A2P") {
$pr_coords = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'lapostews_pr`
WHERE `id_pr` = '.pSQL($address['prid']).'
');
$c_address = htmlentities(preg_replace('/(, ){2,}/', ', ', preg_replace('/(, ){2,}/', ', ', implode(', ', array($address['pradress3'], $address['pradress4'], $address['pradress1'], $address['pradress2']))).', '.$address['przipcode'].' '.$address['prtown'].', FRANCE'));
//echo '<pre>';var_dump($c_address);echo '</pre>';die();
$smarty->assign(array(
'c_address' => $c_address,
//'pr_coords' => $pr_coords
));
}
} else {
$delivery_mode = "DOM";
}
$current_address = $ant_changeaddress->getAddress($order->id_address_delivery);
$smarty->assign(array(
'current_address' => $current_address,
'addresses' => $customer->getAddresses((int)$cookie->id_lang)
));
$smarty->assign(array(
'address' => $address,
'mode' => $mode,
'delivery_mode' => $delivery_mode,
'order' => $order,
'order_cart' => $order_cart,
));
}
} else {
$errors[] = Tools::displayError('Invalid order');
}
if(isset($_POST['submitChangeAddress'])) {
$mode = Tools::getValue('delivery_mode','');
if (empty($mode)) {
$mode = "DOM";
}
Db::getInstance()->Execute('UPDATE ps_socolissimo_delivery_info SET
delivery_mode = "'.pSQL($mode).'",
prname = "'.pSQL(Tools::getValue('prname', '')).'",
prfirstname = "'.pSQL(Tools::getValue('prfirstname', '')).'",
cecompanyname = "'.pSQL(Tools::getValue('cecompanyname', '')).'",
cename = "'.pSQL(Tools::getValue('cename', '')).'",
cefirstname = "'.pSQL(Tools::getValue('cefirstname', '')).'",
prcompladress = "'.pSQL(Tools::getValue('prcompladress', '')).'",
pradress1 = "'.pSQL(Tools::getValue('pradress1', '')).'",
pradress2 = "'.pSQL(Tools::getValue('pradress2', '')).'",
pradress3 = "'.pSQL(Tools::getValue('pradress3', '')).'",
pradress4 = "'.pSQL(Tools::getValue('pradress4', '')).'",
przipcode = "'.pSQL(Tools::getValue('przipcode', '')).'",
prtown = "'.pSQL(Tools::getValue('prtown', '')).'",
cephonenumber = "'.pSQL(Tools::getValue('cephonenumber', '')).'",
ceemail = "'.pSQL(Tools::getValue('ceemail', '')).'",
cedeliveryinformation = "'.pSQL(Tools::getValue('cedeliveryinformation', '')).'",
cedoorcode1 = "'.pSQL(Tools::getValue('cedoorcode1', '')).'",
cedoorcode2 = "'.pSQL(Tools::getValue('cedoorcode2', '')).'",
prid = "'.pSQL(Tools::getValue('prid', '')).'"
WHERE id_cart = '.pSQL(intval(Tools::getValue('id_cart'))));
$order = Db::getInstance()->getRow('
SELECT date_add,id_order
FROM `'._DB_PREFIX_.'orders`
WHERE id_cart = '.pSQL(intval(Tools::getValue('id_cart'))).'
');
mail('marion@antadis.com', '[BBB] Modif transporteur FRONT',
'ID Customer : ' . $address['id_customer'].
' , ID Order : ' . $order['id_order'].
' , Date Order : ' . $order['date_add'].
' , Date now : ' . date("Y-m-d H:i:s").
' , ID cart : ' . Tools::getValue('id_cart').
' , Mode en date : '.$address['delivery_mode'].' -- remplacé par : ' .Tools::getValue('delivery_mode', '').
' , Address1 en date : '.$address['pradress1'].' -- remplacé par : ' .Tools::getValue('pradress1', '').
' , Address2 en date : '.$address['pradress2'].' -- remplacé par : ' .Tools::getValue('pradress2', '').
' , Address3 en date : '.$address['pradress3'].' -- remplacé par : ' .Tools::getValue('pradress3', '').
' , Address4 en date : '.$address['pradress4'].' -- remplacé par : ' .Tools::getValue('pradress4', '')
);
}
}
$smarty->assign(array(
'errors' => $errors,
));
$_POST = array_merge($_POST, $_GET);
require_once(dirname(__FILE__).'/../../header.php');
echo Module::display(dirname(__FILE__), 'change_address.tpl');
require_once(dirname(__FILE__).'/../../footer.php');