2016-10-12 12:40:33 +02:00
< ? 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 {
2016-10-12 16:45:24 +02:00
if ( Tools :: isSubmit ( 'submitChangeAddress' )) {
if ( Tools :: getValue ( 'id_cart' )) {
$mode = Tools :: getValue ( 'delivery_mode' , '' );
if ( empty ( $mode )) {
$mode = " DOM " ;
}
if ( $mode == " DOM " && Tools :: getValue ( 'id_address_delivery' )) {
$newAddressId = Tools :: getValue ( 'id_address_delivery' );
} else {
$newAddressId = $ant_changeaddress -> createAddress (
( int ) $customer -> id ,
" FR " ,
pSQL ( Tools :: getValue ( 'prname' , '' )),
pSQL ( Tools :: getValue ( 'pradress3' , '' )),
pSQL ( Tools :: getValue ( 'pradress2' , '' )),
pSQL ( Tools :: getValue ( 'przipcode' , '' )),
pSQL ( Tools :: getValue ( 'prtown' , '' )),
pSQL ( Tools :: getValue ( 'cephonenumber' , '' )),
pSQL ( Tools :: getValue ( 'cename' , '' )),
pSQL ( Tools :: getValue ( 'cefirstname' , '' ))
);
}
2016-10-19 18:31:19 +02:00
2016-10-12 16:45:24 +02:00
if ( $newAddressId ) {
2016-10-14 13:59:51 +02:00
$errors = array ();
$delivery = new Address (( int ) $newAddressId );
$prefix_postcode = substr ( $delivery -> postcode , 0 , 2 );
2016-10-14 15:10:11 +02:00
// Checking CANARIES
2016-10-14 13:59:51 +02:00
if ( $delivery -> id_country == 6
&& ( intval ( $prefix_postcode ) == 35 || intval ( $prefix_postcode ) == 38 )
) {
$errors [] = Tools :: displayError ( 'Lo sentimos, en estos momentos no distribuimos nuestros productos en Canarias. Si deseas más información, puedes contactar con el Servicio de atención al cliente o llamar al 902 044 399.' );
}
2016-10-14 15:10:11 +02:00
// Checking DOM-TOM
2016-10-14 13:59:51 +02:00
$prefix_postcode = substr ( $delivery -> postcode , 0 , 3 );
$domtom = array ( 971 , 972 , 973 , 974 , 975 , 976 , 984 , 986 , 987 , 988 );
if ( $delivery -> id_country == 8 && ( in_array ( intval ( $prefix_postcode ), $domtom ))
) {
$errors [] = Tools :: displayError ( 'Nous sommes désolé, nous ne livrons pas dans le DOM-TOM' );
}
2016-10-14 15:10:11 +02:00
// Checking only in france
$products_only_fr = array ();
foreach ( $order_cart -> getProducts () as $product ) {
if (( $sale = Sale :: getSaleFromCategory ( $product [ 'id_category_default' ])) !== NULL ) {
// shipping only in france
if ( $sale -> shipping_fr == 1 && $delivery -> id_country != 8 ) {
$errors [] = Tools :: displayError ( 'Votre commande contient des produits expédiés uniquement en France' );
}
}
}
2016-10-14 13:59:51 +02:00
if ( empty ( $errors )) {
$order -> id_address_delivery = ( int ) $newAddressId ;
$order -> update ();
2016-10-19 18:31:19 +02:00
if ( Db :: getInstance () -> getRow ( '
SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE id_cart = '.pSQL(intval(Tools::getValue(' id_cart '))).' ' )
) {
Db :: getInstance () -> Execute ( ' UPDATE ps_socolissimo_delivery_info SET
delivery_mode = " '.pSQL( $mode ).' " ,
prname = " '.pSQL(Tools::getValue('prname', $delivery->lastname )).' " ,
prfirstname = " '.pSQL(Tools::getValue('prfirstname', $delivery->firstname )).' " ,
cecompanyname = " '.pSQL(Tools::getValue('cecompanyname', (!empty( $delivery->company )? $delivery->company :''))).' " ,
cename = " '.pSQL(Tools::getValue('cename', '')).' " ,
cefirstname = " '.pSQL(Tools::getValue('cefirstname', '')).' " ,
prcompladress = " '.pSQL(Tools::getValue('prcompladress', '')).' " ,
pradress1 = " '.pSQL(Tools::getValue('pradress1', (!empty( $delivery->address1 )? $delivery->address1 :''))).' " ,
pradress2 = " '.pSQL(Tools::getValue('pradress2', (!empty( $delivery->address2 )? $delivery->address2 :''))).' " ,
pradress3 = " '.pSQL(Tools::getValue('pradress3', '')).' " ,
pradress4 = " '.pSQL(Tools::getValue('pradress4', '')).' " ,
przipcode = " '.pSQL(Tools::getValue('przipcode', (!empty( $delivery->postcode )? $delivery->postcode :''))).' " ,
prtown = " '.pSQL(Tools::getValue('prtown', (!empty( $delivery->city )? $delivery->city :''))).' " ,
cephonenumber = " '.pSQL(Tools::getValue('cephonenumber', ( $delivery->phone_mobile ? $delivery->phone_mobile : ( $delivery->phone ? $delivery->phone : '')) )).' " ,
ceemail = " '.pSQL(Tools::getValue('ceemail', (!empty( $customer->email )? $customer->email :''))).' " ,
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 ' ))));
}
2016-10-21 11:57:17 +02:00
$smarty -> assign ( array ( 'confirmation' => 1 ));
2016-10-14 13:59:51 +02:00
}
2016-10-12 16:45:24 +02:00
}
} else {
2016-10-13 15:53:23 +02:00
$errors [] = Tools :: displayError ( 'An error occured' );
2016-10-12 16:45:24 +02:00
}
}
2016-10-12 12:40:33 +02:00
$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)' ,
);
2016-10-12 16:45:24 +02:00
} elseif ( $address [ 'delivery_mode' ] == " BPR " || $address [ 'delivery_mode' ] == " CDI " ) {
2016-10-12 12:40:33 +02:00
$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' ));
$smarty -> assign ( array (
'c_address' => $c_address ,
//'pr_coords' => $pr_coords
));
}
} else {
$delivery_mode = " DOM " ;
}
$current_address = $ant_changeaddress -> getAddress ( $order -> id_address_delivery );
2016-11-08 16:09:41 +01:00
$current_delivery = new Address (( int ) $order -> id_address_delivery );
2016-10-12 12:40:33 +02:00
$smarty -> assign ( array (
'current_address' => $current_address ,
2016-11-08 16:09:41 +01:00
'addresses' => $ant_changeaddress -> getAddresses (( int ) $customer -> id ,( int ) $current_delivery -> id_country ,( int ) $cookie -> id_lang )
2016-10-12 12:40:33 +02:00
));
$smarty -> assign ( array (
'address' => $address ,
'mode' => $mode ,
'delivery_mode' => $delivery_mode ,
'order' => $order ,
'order_cart' => $order_cart ,
));
}
} else {
$errors [] = Tools :: displayError ( 'Invalid order' );
}
}
$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' );