Compare commits

...

2 Commits

Author SHA1 Message Date
Michael RICOIS
1303a72d41 Use method to restrict Address 2018-02-14 10:20:13 +01:00
Michael RICOIS
46d2353512 checkAdress 2018-02-13 16:10:34 +01:00
4 changed files with 127 additions and 120 deletions

View File

@ -6,9 +6,10 @@ $ant_changeaddress = new Ant_Changeaddress();
if($cookie->isLogged() && Tools::getValue('id_order')) {
if(Tools::getValue('getPR')
&& ($mode = Tools::getValue('mode'))
&& ($h_xcoords = (float) Tools::getValue('h_xcoords'))
&& ($h_ycoords = (float) Tools::getValue('h_ycoords'))) {
&& ($mode = Tools::getValue('mode'))
&& ($h_xcoords = (float) Tools::getValue('h_xcoords'))
&& ($h_ycoords = (float) Tools::getValue('h_ycoords'))) {
$pr_list = array();
header('Content-Type: text/json');
die(json_encode(Db::getInstance()->ExecuteS('
@ -22,54 +23,33 @@ if($cookie->isLogged() && Tools::getValue('id_order')) {
')));
}
if(Tools::getValue('getAD')
&& ($id_address = Tools::getValue('id_address'))
&& ($id_cart = Tools::getValue('id_cart'))) {
if (Tools::getValue('getAD')
&& ($id_address = Tools::getValue('id_address'))
&& ($id_cart = Tools::getValue('id_cart'))) {
$errors = array();
$order_cart = new Cart((int)$id_cart);
$delivery = new Address((int)$id_address);
$prefix_postcode = substr($delivery->postcode, 0 ,2);
// Checking CANARIES
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.');
}
// Checking CEUTA/MELINA
$ceuta = array(51001, 51002, 51003, 51004, 51005, 51070, 51071, 51080);
if ($delivery->id_country == 6 && (in_array(intval($delivery->postcode),$ceuta))
) {
$errors[] = Tools::displayError('Lo sentimos, en estos momentos no distribuimos nuestros productos en Ceuta. Si deseas más información, puedes contactar con el Servicio de atención al cliente o llamar al 902 044 399.');
}
$melina = array(52001, 52002, 52003, 52004, 52005, 52006, 52070, 52071, 52080);
if ($delivery->id_country == 6 && (in_array(intval($delivery->postcode),$melina))
) {
$errors[] = Tools::displayError('Lo sentimos, en estos momentos no distribuimos nuestros productos en Melina. Si deseas más información, puedes contactar con el Servicio de atención al cliente o llamar al 902 044 399.');
}
// Checking DOM-TOM
$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');
}
// Checking only in france
$products_only_fr = array();
$saleOnlyFr = false;
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');
if (($sale = Sale::getSaleFromCategory($product['id_category_default'])) !== NULL) {
// Sale with only france shipping
if ($sale->shipping_fr == 1) {
$saleOnlyFr = true;
}
}
}
// Check address restriction
$delivery = new Address(self::$cart->id_address_delivery);
$deliveryCheckResult = Cart::checkAddress($delivery, $saleOnlyFr);
if (is_array($deliveryCheckResult)) {
$errors[] = $deliveryCheckResult['msg'];
}
if(empty($errors)) {
if (empty($errors)) {
$change_address = $ant_changeaddress->getAddress($id_address);
$html = '';
foreach ($change_address as $key => $value) {

View File

@ -52,33 +52,24 @@ if ($cookie->isLogged()) {
if($newAddressId) {
$errors = array();
$delivery = new Address((int)$newAddressId);
$prefix_postcode = substr($delivery->postcode, 0 ,2);
// Checking CANARIES
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.');
}
// Checking DOM-TOM
$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');
}
// Checking only in france
$products_only_fr = array();
$saleOnlyFr = false;
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');
if (($sale = Sale::getSaleFromCategory($product['id_category_default'])) !== NULL) {
// Sale with only france shipping
if ($sale->shipping_fr == 1) {
$saleOnlyFr = true;
}
}
}
// Check address restriction
$delivery = new Address(self::$cart->id_address_delivery);
$deliveryCheckResult = Cart::checkAddress($delivery, $saleOnlyFr);
if (is_array($deliveryCheckResult)) {
$errors[] = $deliveryCheckResult['msg'];
}
if (empty($errors)) {
$order->id_address_delivery = (int)$newAddressId;

View File

@ -1111,5 +1111,60 @@ class Cart extends CartCore {
);
return '<img src="/img/l/'.(int) $versions[$value].'.jpg" alt="" />';
}
/**
* Check if deliver is available
* @param DeliveryCore $delivery
* @param boolean $saleOnlyFr
* @return string[]|boolean
*/
public static function checkAddress($delivery, $saleOnlyFr = false)
{
// Bloque les canaries ES
$prefix_postcode = substr($delivery->postcode, 0 ,2);
if ($delivery->id_country == 6
&& (intval($prefix_postcode) == 35 || intval($prefix_postcode) == 38) ) {
return array(
'msg' => 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."),
'param' => 'canaries'
);
}
// Bloque Ceuta/Melina ES
$ceuta = array(51001, 51002, 51003, 51004, 51005, 51070, 51071, 51080);
if ($delivery->id_country == 6 && in_array(intval($delivery->postcode), $ceuta) ) {
return array(
'msg' => Tools::displayError("Lo sentimos, en estos momentos no distribuimos nuestros productos en Ceuta. Si deseas más información, puedes contactar con el Servicio de atención al cliente o llamar al 902 044 399."),
'param' => 'ceuta'
);
}
$melina = array(52001, 52002, 52003, 52004, 52005, 52006, 52070, 52071, 52080);
if ($delivery->id_country == 6 && in_array(intval($delivery->postcode), $melina) ) {
return array(
'msg' => Tools::displayError("Lo sentimos, en estos momentos no distribuimos nuestros productos en Melina. Si deseas más información, puedes contactar con el Servicio de atención al cliente o llamar al 902 044 399."),
'param' => 'melina'
);
}
// Bloque DOM-TOM
$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)) ) {
return array(
'msg' => Tools::displayError("Nous sommes désolé, nous ne livrons pas dans le DOM-TOM"),
'param' => 'domtom'
);
}
// Sale only deliver in FR
if ($delivery->id_country != 8 && $saleOnlyFr === true) {
return array(
'msg' => Tools::displayError("Votre commande contient des produits expédiés uniquement en France"),
'param' => 'onlyfr'
);
}
return true;
}
}

View File

@ -1,6 +1,8 @@
<?php
class OrderController extends OrderControllerCore {
public function preProcess() {
class OrderController extends OrderControllerCore
{
public function preProcess()
{
global $isVirtualCart, $orderTotal;
if($this->step == 0 && !Tools::getValue('ajax') && Module::isInstalled('privatesales_delay')) {
@ -18,46 +20,19 @@ class OrderController extends OrderControllerCore {
));
}
if($this->step == 2 && !Tools::getValue('ajax')){
// Bloque les canaries ES
$delivery = new Address(self::$cart->id_address_delivery);
$prefix_postcode = substr($delivery->postcode, 0 ,2);
if ($delivery->id_country == 6
&& (intval($prefix_postcode) == 35 || intval($prefix_postcode) == 38)
) {
//$this->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.');
$this->step = 1;
Tools::redirect('order.php?step=1&canaries=1');
}
// Bloque Ceuta/Melina ES
$ceuta = array(51001, 51002, 51003, 51004, 51005, 51070, 51071, 51080);
if ($delivery->id_country == 6 && (in_array(intval($delivery->postcode),$ceuta))
) {
$this->step = 1;
Tools::redirect('order.php?step=1&ceuta=1');
}
$melina = array(52001, 52002, 52003, 52004, 52005, 52006, 52070, 52071, 52080);
if ($delivery->id_country == 6 && (in_array(intval($delivery->postcode),$melina))
) {
$this->step = 1;
Tools::redirect('order.php?step=1&melina=1');
}
// bloque DOM-TOM
$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))
) {
//$this->errors[] = Tools::displayError('Nous sommes désolé, nous ne livrons pas dans le DOM-TOM');
$this->step = 1;
Tools::redirect('order.php?step=1&domtom=1');
}
if ($this->step == 2 && !Tools::getValue('ajax')) {
$deliveryWithOnlyFr = false;
$delivery = new Address(self::$cart->id_address_delivery);
$deliveryCheckResult = Cart::checkAddress($delivery, $deliveryWithOnlyFr);
if (is_array($deliveryCheckResult)) {
$this->step = 1;
$param = $deliveryCheckResult['param'];
Tools::redirect('order.php?step=1&'.$param.'=1');
}
}
if(Module::isInstalled('privatesales')) {
if (Module::isInstalled('privatesales')) {
$removed = FALSE;
$products_only_fr = array();
foreach(self::$cart->getProducts() as $product) {
@ -69,36 +44,42 @@ class OrderController extends OrderControllerCore {
}
// shipping only in france
if($sale->shipping_fr == 1) {
// $link = new Link();
$products_only_fr[] = array(
'name' => $product['name'].' - '.$sale->title[(int)self::$cart->id_lang],
//'link' => $link->getProductLink((int)$product['id_product'], $product['link_rewrite'], $product['category'], $product['ean13'])
);
}
}
if (!empty($products_only_fr)) {
self::$smarty->assign('products_fr',$products_only_fr);
self::$smarty->assign('products_fr', $products_only_fr);
if ($this->step == 2) {
$delivery = new Address(self::$cart->id_address_delivery);
if ($delivery->id_country != 8 && !Tools::getValue('ajax')) {
$this->step = 1;
Tools::redirect('order.php?step=1&onlyfr=1');
}
$deliveryWithOnlyFr = false;
if (!empty($products_only_fr)) {
$deliveryWithOnlyFr = true;
}
$delivery = new Address(self::$cart->id_address_delivery);
$deliveryCheckResult = Cart::checkAddress($delivery, $deliveryWithOnlyFr);
if (is_array($deliveryCheckResult)) {
$this->step = 1;
$param = $deliveryCheckResult['param'];
Tools::redirect('order.php?step=1&'.$param.'=1');
}
}
}
if($removed === TRUE) {
if ($removed === TRUE) {
self::$smarty->assign(array(
'products_removed' => TRUE,
));
$this->nbProducts = self::$cart->nbProducts();
}
if(!$this->nbProducts) {
if (!$this->nbProducts) {
$this->step = -1;
}
}
global $page_name;
if(!isset($this->php_self)) {
@ -114,10 +95,10 @@ class OrderController extends OrderControllerCore {
}
}
self::$smarty->assign(array('page_name' => $page_name));
self::$smarty->assign(array(
'step' => $this->step,
));
'page_name' => $page_name,
'step' => $this->step,
));
$displayLeft = array(
'page-404', 'address', 'addresses', 'authentication', 'best-sales',