2016-01-04 12:48:08 +01:00
|
|
|
<?php
|
|
|
|
if(Module::isInstalled('privatesales')) {
|
|
|
|
include_once(dirname(__FILE__).'/../../modules/privatesales/Sale.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
class ParentOrderController extends ParentOrderControllerCore {
|
|
|
|
public function preProcess() {
|
|
|
|
if(Module::isInstalled('privatesales')) {
|
|
|
|
$removed = FALSE;
|
|
|
|
|
|
|
|
foreach(self::$cart->getProducts() as $product) {
|
|
|
|
if(($sale = Sale::getSaleFromCategory($product['id_category_default'])) !== NULL) {
|
|
|
|
if($sale->isFinished() || !$sale->enabled) {
|
|
|
|
self::$cart->deleteProduct($product['id_product'], $product['id_product_attribute'], $product['id_customization']);
|
|
|
|
$removed = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($removed === TRUE) {
|
|
|
|
self::$smarty->assign(array(
|
|
|
|
'products_removed' => TRUE,
|
|
|
|
));
|
|
|
|
$this->nbProducts = self::$cart->nbProducts();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$this->nbProducts) {
|
|
|
|
$this->step = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::preProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function _assignCarrier() {
|
|
|
|
$customer = new Customer((int)(self::$cookie->id_customer));
|
|
|
|
$address = new Address((int)(self::$cart->id_address_delivery));
|
|
|
|
$id_zone = Address::getZoneById((int)($address->id));
|
|
|
|
$carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups());
|
|
|
|
$carriers_special = Cart::$carrier_special;
|
|
|
|
|
|
|
|
$only_gifts = TRUE;
|
|
|
|
foreach(self::$cart->getProducts() as $p) {
|
|
|
|
if($p['id_product'] != 4840) {
|
|
|
|
$only_gifts = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self::$smarty->assign('only_gifts', $only_gifts);
|
|
|
|
|
|
|
|
$sale_delivery = array();
|
|
|
|
// Restriction du choix du transporteur
|
|
|
|
if(Module::isInstalled('privatesales')) {
|
|
|
|
if(Configuration::get('PRIVATESALES_CARRIERFENCE') ) {
|
|
|
|
$cart_products = self::$cart->getProducts();
|
|
|
|
if(count($cart_products) > 0) {
|
|
|
|
|
2016-03-17 12:31:42 +01:00
|
|
|
$_sales = array();
|
2017-01-06 16:25:08 +01:00
|
|
|
$_carriers = array();
|
2016-01-04 12:48:08 +01:00
|
|
|
$carrier_uniq = array();
|
2017-01-06 16:25:08 +01:00
|
|
|
$count_carriers = array();
|
|
|
|
$dropshipping = false;
|
2016-05-30 15:42:20 +02:00
|
|
|
$shipping_only_athome = false;
|
2016-01-04 12:48:08 +01:00
|
|
|
foreach ($cart_products as $key => $cart_product) {
|
|
|
|
$sale = Sale::getSaleFromCategory($cart_product['id_category_default']);
|
|
|
|
if($sale) {
|
|
|
|
$sale_carriers = $sale->getCarriers();
|
2016-05-30 15:42:20 +02:00
|
|
|
if ($sale->shipping_fr == 1) {
|
|
|
|
$shipping_only_athome = true;
|
|
|
|
}
|
2016-01-04 12:48:08 +01:00
|
|
|
$sale_delivery[] = $sale->delivery_delay;
|
2016-03-17 12:31:42 +01:00
|
|
|
$_sales[(int)$sale->id] = $sale_carriers;
|
2016-01-04 12:48:08 +01:00
|
|
|
if(count($sale_carriers) == 0) {
|
|
|
|
mail('thibault@antadis.com', '[BBB] Vente sans transporteur', 'La vente ' . $sale->id . ' n\'a aucun transporteur défini
|
|
|
|
pour le panier ' . $cart->id);
|
|
|
|
mail('valentin@bebeboutik.com', '[BBB] Vente sans transporteur', 'La vente ' . $sale->id . ' n\'a aucun transporteur défini
|
|
|
|
pour le panier ' . $cart->id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
foreach($carriers as $carrier) {
|
2016-03-17 12:31:42 +01:00
|
|
|
if(in_array($carrier['id_carrier'], $sale_carriers)
|
2016-01-04 12:48:08 +01:00
|
|
|
&& !in_array($carrier['id_carrier'], $carrier_uniq)) {
|
|
|
|
$_carriers[] = $carrier;
|
|
|
|
$carrier_uniq[] = $carrier['id_carrier'];
|
2017-01-06 16:25:08 +01:00
|
|
|
if((int)$carrier['id_carrier'] == 22) {
|
|
|
|
$dropshipping = true;
|
|
|
|
}
|
2016-01-04 12:48:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-17 12:31:42 +01:00
|
|
|
// si multiple vente dont vente consommables
|
2016-03-18 15:57:22 +01:00
|
|
|
foreach ($_sales as $key => $carriers) {
|
|
|
|
if ((int) $key == _SHOP_PRIVATESALES_CONSUMABLE) {
|
2016-05-09 17:43:57 +02:00
|
|
|
if (count($_sales) > 1 && count($_carriers) > 1 && count($_carriers)>count($carriers)) {
|
2016-03-17 12:31:42 +01:00
|
|
|
$carriers_to_remove = array_filter($_carriers, function ($_carrier) use (&$carriers) {
|
|
|
|
foreach ($carriers as $c) {
|
|
|
|
if ((int) $c == (int) $_carrier['id_carrier']) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2016-03-18 15:57:22 +01:00
|
|
|
|
2016-03-17 12:31:42 +01:00
|
|
|
foreach ($carriers_to_remove as $key => $value) {
|
|
|
|
unset($_carriers[$key]);
|
|
|
|
}
|
|
|
|
break;
|
2016-03-18 15:57:22 +01:00
|
|
|
|
|
|
|
} elseif (count($_sales)==1) {
|
2016-05-17 14:31:41 +02:00
|
|
|
// $carrier_shipping_cost = 5;
|
2016-03-17 12:31:42 +01:00
|
|
|
}
|
2017-01-06 16:25:08 +01:00
|
|
|
} else {
|
|
|
|
foreach ($carriers as $key => $value) {
|
|
|
|
if(isset($count_carriers[(int)$value])) {
|
|
|
|
$count_carriers[(int)$value]++;
|
|
|
|
} else {
|
|
|
|
$count_carriers[(int)$value] = 1;
|
|
|
|
}
|
|
|
|
}
|
2016-03-17 12:31:42 +01:00
|
|
|
}
|
2017-01-06 16:25:08 +01:00
|
|
|
}
|
2016-03-17 12:31:42 +01:00
|
|
|
|
2016-01-04 12:48:08 +01:00
|
|
|
// si multiple carriers
|
|
|
|
if (count($_carriers) > 1) {
|
|
|
|
$extra_carrier = 0;
|
|
|
|
$carrier_extra_available = array();
|
|
|
|
$id_carrier_available = array();
|
2016-03-17 12:31:42 +01:00
|
|
|
|
2016-01-04 12:48:08 +01:00
|
|
|
$id_carrier_available = array_map(function($carrier){
|
|
|
|
return $carrier['id_carrier'];
|
|
|
|
}, $_carriers);
|
|
|
|
$id_carrier_available = array_unique($id_carrier_available);
|
|
|
|
|
|
|
|
foreach ($carriers_special as $carrier_special) {
|
|
|
|
if (in_array($carrier_special, $id_carrier_available)) {
|
|
|
|
$extra_carrier++;
|
|
|
|
$carrier_extra_available[] = $carrier_special;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($extra_carrier == 1) {
|
|
|
|
$carrier_final = array();
|
|
|
|
foreach ($_carriers as $key => $carrier) {
|
|
|
|
if ($carrier['id_carrier'] == $carrier_extra_available[0] ) {
|
|
|
|
$carrier_final = $carrier;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($carriers);
|
|
|
|
$carriers[0] = $carrier_final;
|
|
|
|
} else {
|
2016-05-09 17:43:57 +02:00
|
|
|
// Gestion carrier socolissimo (soflexibilite)
|
|
|
|
$carriers_socol = array();
|
2016-01-04 12:48:08 +01:00
|
|
|
foreach ($_carriers as $key => $carrier) {
|
2017-01-06 16:25:08 +01:00
|
|
|
if($dropshipping && $carrier['id_carrier'] == 22) {
|
|
|
|
$carrier_drop = $carrier;
|
|
|
|
}
|
2016-05-09 17:43:57 +02:00
|
|
|
if ($carrier['external_module_name'] == "soflexibilite") {
|
|
|
|
$carriers_socol[] = $carrier;
|
2016-01-04 12:48:08 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-06 16:25:08 +01:00
|
|
|
if(isset($carrier_drop) && !$shipping_only_athome) {
|
|
|
|
unset($carriers);
|
|
|
|
$carriers[0] = $carrier_drop;
|
|
|
|
} elseif (!empty($carriers_socol)){
|
2016-05-09 17:43:57 +02:00
|
|
|
unset($carriers);
|
|
|
|
$carriers = $carriers_socol;
|
|
|
|
} else {
|
|
|
|
// TODOOO multi special carrier $carrier_extra_available[]
|
|
|
|
$carrier_final = array();
|
|
|
|
foreach ($_carriers as $key => $carrier) {
|
|
|
|
if ($carrier['id_carrier'] == $carrier_extra_available[0] ) {
|
|
|
|
$carrier_final = $carrier;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($carriers);
|
|
|
|
$carriers[0] = $carrier_final;
|
|
|
|
}
|
2016-01-04 12:48:08 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$carriers = $_carriers;
|
|
|
|
}
|
2016-05-13 13:31:50 +02:00
|
|
|
// distinction "at home" et "out of home"
|
|
|
|
$carriers_ah = array();
|
|
|
|
$carriers_ooh = array();
|
2017-01-06 16:25:08 +01:00
|
|
|
//$config_carrier_ooh = array(88,89); // prod
|
2017-01-06 16:32:55 +01:00
|
|
|
$config_carrier_ooh = array(47,48); // dev
|
|
|
|
//$config_carrier_ooh = array(40,45); // local
|
2016-05-18 10:30:17 +02:00
|
|
|
foreach ($carriers as $carrier) {
|
2017-01-06 16:25:08 +01:00
|
|
|
//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'] != 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
|
2016-05-30 15:42:20 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-05-18 10:30:17 +02:00
|
|
|
if (in_array($carrier['id_carrier'], $config_carrier_ooh) ){
|
|
|
|
$carriers_ooh[] = $carrier;
|
|
|
|
} else {
|
|
|
|
$carriers_ah[] = $carrier;
|
|
|
|
}
|
|
|
|
}
|
2016-06-20 10:42:30 +02:00
|
|
|
// fix a check !
|
|
|
|
if (count($carriers_ah) > 0) {
|
|
|
|
unset($carriers);
|
2017-01-06 16:25:08 +01:00
|
|
|
$carriers = $carriers_ah;
|
2016-06-20 10:42:30 +02:00
|
|
|
}
|
2016-05-18 10:30:17 +02:00
|
|
|
|
2016-05-13 13:31:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self::$smarty->assign(array(
|
|
|
|
'checked' => $this->_setDefaultCarrierSelection($carriers),
|
|
|
|
'carriers' => $carriers,
|
|
|
|
'carriers_ooh' => $carriers_ooh,
|
|
|
|
'carrier_shipping_cost' => $carrier_shipping_cost ? $carrier_shipping_cost:0,
|
|
|
|
'sale_delivery' => array_unique($sale_delivery),
|
|
|
|
'default_carrier' => (int)(Configuration::get('PS_CARRIER_DEFAULT'))
|
|
|
|
));
|
2016-01-04 12:48:08 +01:00
|
|
|
self::$smarty->assign(array(
|
|
|
|
'HOOK_EXTRACARRIER' => Module::hookExec('extraCarrier', array('address' => $address)),
|
|
|
|
'HOOK_BEFORECARRIER' => Module::hookExec('beforeCarrier', array('carriers' => $carriers))
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function _processCarrier() {
|
|
|
|
if(Module::isInstalled('privatesales')) {
|
|
|
|
// if(Configuration::get('PRIVATESALES_CARRIERFENCE')) {
|
|
|
|
// $cart_products = self::$cart->getProducts();
|
|
|
|
// if(count($cart_products) > 0) {
|
|
|
|
// $sale = Sale::getSaleFromCategory($cart_products[0]['id_category_default']);
|
|
|
|
// if($sale) {
|
|
|
|
// $sale_carriers = $sale->getCarriers();
|
|
|
|
// if(!in_array(Tools::getValue('id_carrier'), $sale_carriers)) {
|
|
|
|
// $this->errors[] = Tools::displayError('Invalid carrier or no carrier selected');
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
if(count($this->errors) === 0) {
|
|
|
|
parent::_processCarrier();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
parent::_processCarrier();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setMedia() {
|
|
|
|
parent::setMedia();
|
|
|
|
|
|
|
|
global $css_files;
|
|
|
|
$css_files = array_slice($css_files, 0, 1);
|
|
|
|
}
|
|
|
|
}
|