restriction with carrier priority

This commit is contained in:
Marion Muszynski 2017-01-06 16:25:08 +01:00
parent b250ea6d3d
commit 6cc03d0287

View File

@ -55,9 +55,11 @@ class ParentOrderController extends ParentOrderControllerCore {
$cart_products = self::$cart->getProducts(); $cart_products = self::$cart->getProducts();
if(count($cart_products) > 0) { if(count($cart_products) > 0) {
$_carriers = array();
$_sales = array(); $_sales = array();
$_carriers = array();
$carrier_uniq = array(); $carrier_uniq = array();
$count_carriers = array();
$dropshipping = false;
$shipping_only_athome = false; $shipping_only_athome = false;
foreach ($cart_products as $key => $cart_product) { foreach ($cart_products as $key => $cart_product) {
$sale = Sale::getSaleFromCategory($cart_product['id_category_default']); $sale = Sale::getSaleFromCategory($cart_product['id_category_default']);
@ -80,11 +82,13 @@ class ParentOrderController extends ParentOrderControllerCore {
&& !in_array($carrier['id_carrier'], $carrier_uniq)) { && !in_array($carrier['id_carrier'], $carrier_uniq)) {
$_carriers[] = $carrier; $_carriers[] = $carrier;
$carrier_uniq[] = $carrier['id_carrier']; $carrier_uniq[] = $carrier['id_carrier'];
if((int)$carrier['id_carrier'] == 22) {
$dropshipping = true;
}
} }
} }
} }
} }
// si multiple vente dont vente consommables // si multiple vente dont vente consommables
foreach ($_sales as $key => $carriers) { foreach ($_sales as $key => $carriers) {
if ((int) $key == _SHOP_PRIVATESALES_CONSUMABLE) { if ((int) $key == _SHOP_PRIVATESALES_CONSUMABLE) {
@ -106,8 +110,16 @@ class ParentOrderController extends ParentOrderControllerCore {
} elseif (count($_sales)==1) { } elseif (count($_sales)==1) {
// $carrier_shipping_cost = 5; // $carrier_shipping_cost = 5;
} }
} else {
foreach ($carriers as $key => $value) {
if(isset($count_carriers[(int)$value])) {
$count_carriers[(int)$value]++;
} else {
$count_carriers[(int)$value] = 1;
}
}
} }
} }
// si multiple carriers // si multiple carriers
if (count($_carriers) > 1) { if (count($_carriers) > 1) {
@ -141,11 +153,17 @@ class ParentOrderController extends ParentOrderControllerCore {
// Gestion carrier socolissimo (soflexibilite) // Gestion carrier socolissimo (soflexibilite)
$carriers_socol = array(); $carriers_socol = array();
foreach ($_carriers as $key => $carrier) { foreach ($_carriers as $key => $carrier) {
if($dropshipping && $carrier['id_carrier'] == 22) {
$carrier_drop = $carrier;
}
if ($carrier['external_module_name'] == "soflexibilite") { if ($carrier['external_module_name'] == "soflexibilite") {
$carriers_socol[] = $carrier; $carriers_socol[] = $carrier;
} }
} }
if (!empty($carriers_socol)){ if(isset($carrier_drop) && !$shipping_only_athome) {
unset($carriers);
$carriers[0] = $carrier_drop;
} elseif (!empty($carriers_socol)){
unset($carriers); unset($carriers);
$carriers = $carriers_socol; $carriers = $carriers_socol;
} else { } else {
@ -164,17 +182,27 @@ class ParentOrderController extends ParentOrderControllerCore {
} else { } else {
$carriers = $_carriers; $carriers = $_carriers;
} }
// distinction "at home" et "out of home" // distinction "at home" et "out of home"
$carriers_ah = array(); $carriers_ah = array();
$carriers_ooh = array(); $carriers_ooh = array();
$config_carrier_ooh = array(88,89); // prod //$config_carrier_ooh = array(88,89); // prod
// $config_carrier_ooh = array(47,48); // dev // $config_carrier_ooh = array(47,48); // dev
// $config_carrier_ooh = array(40,45); // local $config_carrier_ooh = array(40,45); // local
foreach ($carriers as $carrier) { foreach ($carriers as $carrier) {
if($shipping_only_athome && $carrier['id_carrier'] != 87) { // prod //if($shipping_only_athome && $carrier['id_carrier'] != 87) { // prod
// if($shipping_only_athome && $carrier['id_carrier'] != 45) { // dev if($shipping_only_athome && $carrier['id_carrier'] != 45) { // dev
// if($shipping_only_athome && $carrier['id_carrier'] != 38) { // local //if($shipping_only_athome && $carrier['id_carrier'] != 38) { // local
continue;
}
// if($carrier['id_carrier'] != 87
// && isset($count_carriers[(int)$carrier['id_carrier']]) && isset($count_carriers[87])
// && $count_carriers[(int)$carrier['id_carrier']] < $count_carriers[87]) { // prod
if($carrier['id_carrier'] != 45
&& isset($count_carriers[(int)$carrier['id_carrier']]) && isset($count_carriers[45])
&& $count_carriers[(int)$carrier['id_carrier']] < $count_carriers[45]) { // dev
// if($carrier['id_carrier'] != 38
// && isset($count_carriers[(int)$carrier['id_carrier']]) && isset($count_carriers[38])
// && $count_carriers[(int)$carrier['id_carrier']] < $count_carriers[38]) { //local
continue; continue;
} }
if (in_array($carrier['id_carrier'], $config_carrier_ooh) ){ if (in_array($carrier['id_carrier'], $config_carrier_ooh) ){
@ -183,11 +211,10 @@ class ParentOrderController extends ParentOrderControllerCore {
$carriers_ah[] = $carrier; $carriers_ah[] = $carrier;
} }
} }
// fix a check ! // fix a check !
if (count($carriers_ah) > 0) { if (count($carriers_ah) > 0) {
unset($carriers); unset($carriers);
$carriers = $carriers_ah; $carriers = $carriers_ah;
} }
} }