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 = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_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')) { $carrier_dropshipping = (int)Configuration::get('ANT_CARRIER_DROP'); $carrier_dom = (int)Configuration::get('ANT_CARRIER_DOM'); if(Configuration::get('PRIVATESALES_CARRIERFENCE') ) { $cart_products = self::$cart->getProducts(); if(count($cart_products) > 0) { $_sales = array(); $_carriers = array(); $carrier_uniq = array(); $count_carriers = array(); $dropshipping = false; $shipping_only_athome = false; foreach ($cart_products as $key => $cart_product) { $sale = Sale::getSaleFromCategory($cart_product['id_category_default']); if($sale) { $sale_carriers = $sale->getCarriers(); if ($sale->shipping_fr == 1) { $shipping_only_athome = true; } $sale_delivery[] = $sale->delivery_delay; $_sales[(int)$sale->id] = $sale_carriers; 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) { if(in_array($carrier['id_carrier'], $sale_carriers) && !in_array($carrier['id_carrier'], $carrier_uniq)) { $_carriers[] = $carrier; $carrier_uniq[] = $carrier['id_carrier']; if((int)$carrier['id_carrier'] == $carrier_dropshipping) { $dropshipping = true; } } } } } // si multiple vente dont vente consommables foreach ($_sales as $key => $carriers) { if ((int) $key == _SHOP_PRIVATESALES_CONSUMABLE) { if (count($_sales) > 1 && count($_carriers) > 1 && count($_carriers)>count($carriers)) { $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; }); foreach ($carriers_to_remove as $key => $value) { unset($_carriers[$key]); } break; } elseif (count($_sales)==1) { // $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 if (count($_carriers) > 1) { $extra_carrier = 0; $carrier_extra_available = array(); $id_carrier_available = array(); $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 { // Gestion carrier socolissimo (soflexibilite) $carriers_socol = array(); $config_carrier_mr = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_MR'))); $config_carrier_socol = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_SOCOL'))); foreach ($_carriers as $key => $carrier) { if($dropshipping && $carrier['id_carrier'] == $carrier_dropshipping) { $carrier_drop = $carrier; } if ($carrier['external_module_name'] == "soflexibilite") { if($address->id_country == 3) { $carrier['delay'] = str_replace(array("France",'10 000','8 000'),array("Belgique",'des','des'),$carrier['delay']); } } if (in_array((int)$carrier['id_carrier'], $config_carrier_socol)) { $carriers_socol[] = $carrier; } if(in_array((int)$carrier['id_carrier'], $config_carrier_mr) && isset($count_carriers[$config_carrier_socol[1]]) && isset($count_carriers[(int)$carrier['id_carrier']]) && $count_carriers[$config_carrier_socol[1]] == $count_carriers[(int)$carrier['id_carrier']] ) { // $count_carriers[$config_carrier_socol[1]] - socol ooh $carriers_socol[] = $carrier; } } if(isset($carrier_drop) && !$shipping_only_athome) { unset($carriers); $carriers[0] = $carrier_drop; } elseif (!empty($carriers_socol)){ 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; } } } else { $carriers = $_carriers; } // distinction "at home" et "out of home" $carriers_ah = array(); $carriers_ooh = array(); $config_carrier_ooh = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_OOH'))); foreach ($carriers as $carrier) { if($shipping_only_athome && $carrier['id_carrier'] != $carrier_dom) { continue; } if($carrier['id_carrier'] != $carrier_dom && isset($count_carriers[(int)$carrier['id_carrier']]) && isset($count_carriers[$carrier_dom]) && $count_carriers[(int)$carrier['id_carrier']] < $count_carriers[$carrier_dom]) { continue; } if (in_array($carrier['id_carrier'], $config_carrier_ooh) ){ $carriers_ooh[] = $carrier; } else { $carriers_ah[] = $carrier; } } // fix a check ! if (count($carriers_ah) > 0) { unset($carriers); $carriers = $carriers_ah; } } } } 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')) )); 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); } }