Fix shipping cost for category 8744158

This commit is contained in:
Michael RICOIS 2018-01-09 10:05:53 +01:00
parent d9f23e7f30
commit 04254c0d83

View File

@ -142,7 +142,8 @@ class Cart extends CartCore {
return $this->_products;
}
function getOrderShippingCost($id_carrier=NULL, $useTax=TRUE, $add_carrier_cost = true) {
function getOrderShippingCost($id_carrier=NULL, $useTax=TRUE, $add_carrier_cost = true)
{
global $defaultCountry;
if ($this->isVirtualCart())
@ -183,7 +184,7 @@ class Cart extends CartCore {
}
// Get id zone
if(isset($this->id_address_delivery)
if (isset($this->id_address_delivery)
&& $this->id_address_delivery
&& Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
$id_zone = Address::getZoneById((int)($this->id_address_delivery));
@ -196,19 +197,19 @@ class Cart extends CartCore {
}
// If no carrier, select default one
if(!$id_carrier) {
if (!$id_carrier) {
$id_carrier = $this->id_carrier;
}
if($id_carrier && !$this->isCarrierInRange($id_carrier, $id_zone)) {
if ($id_carrier && !$this->isCarrierInRange($id_carrier, $id_zone)) {
$id_carrier = '';
}
if(empty($id_carrier) && $this->isCarrierInRange(Configuration::get('PS_CARRIER_DEFAULT'), $id_zone)) {
if (empty($id_carrier) && $this->isCarrierInRange(Configuration::get('PS_CARRIER_DEFAULT'), $id_zone)) {
$id_carrier = (int)(Configuration::get('PS_CARRIER_DEFAULT'));
}
if(empty($id_carrier)) {
if (empty($id_carrier)) {
if((int)($this->id_customer)) {
$customer = new Customer((int)($this->id_customer));
$result = Carrier::getCarriers((int)(Configuration::get('PS_LANG_DEFAULT')), TRUE, FALSE, (int)($id_zone), $customer->getGroups());
@ -262,28 +263,28 @@ class Cart extends CartCore {
}
}
if(empty($id_carrier)) {
if (empty($id_carrier)) {
$id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
}
if(!isset(self::$_carriers[$id_carrier])) {
if (!isset(self::$_carriers[$id_carrier])) {
self::$_carriers[$id_carrier] = new Carrier((int)($id_carrier), Configuration::get('PS_LANG_DEFAULT'));
}
$carrier = self::$_carriers[$id_carrier];
if(!Validate::isLoadedObject($carrier)) {
die(Tools::displayError('Fatal error: "no default carrier"'));
}
if(!$carrier->active) {
if (!$carrier->active) {
return $shipping_cost;
}
// Free fees if free carrier
if($carrier->is_free == 1) {
if ($carrier->is_free == 1) {
return 0;
}
// Select carrier tax
if($useTax && !Tax::excludeTaxeOption()) {
if ($useTax && !Tax::excludeTaxeOption()) {
$carrierTax = Tax::getCarrierTaxRate((int)$carrier->id, (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
}
@ -293,23 +294,23 @@ class Cart extends CartCore {
if ($dgv->checkFreeShippingPriceCart($this)) return 0;
// Free fees
$free_fees_price = 0;
if(isset($configuration['PS_SHIPPING_FREE_PRICE'])) {
if (isset($configuration['PS_SHIPPING_FREE_PRICE'])) {
$free_fees_price = Tools::convertPrice((float)($configuration['PS_SHIPPING_FREE_PRICE']), Currency::getCurrencyInstance((int)($this->id_currency)));
}
$orderTotalwithDiscounts = $this->getOrderTotal(TRUE, Cart::BOTH_WITHOUT_SHIPPING);
if($orderTotalwithDiscounts >= (float)($free_fees_price) && (float)($free_fees_price) > 0) {
if ($orderTotalwithDiscounts >= (float)($free_fees_price) && (float)($free_fees_price) > 0) {
return $shipping_cost;
}
if(isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $this->getTotalWeight() >= (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) && (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0) {
if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $this->getTotalWeight() >= (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) && (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0) {
return $shipping_cost;
}
// Get shipping cost using correct method
if($carrier->range_behavior) {
if ($carrier->range_behavior) {
// Get id zone
if(
isset($this->id_address_delivery)
@ -337,6 +338,7 @@ class Cart extends CartCore {
$shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int)($this->id_currency));
}
}
// Adding handling charges
if(isset($configuration['PS_SHIPPING_HANDLING']) && $carrier->shipping_handling) {
$shipping_cost += (float)($configuration['PS_SHIPPING_HANDLING']);
@ -350,11 +352,11 @@ class Cart extends CartCore {
$shipping_cost = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int)($this->id_currency)));
//get external shipping cost from module
if($carrier->shipping_external) {
if ($carrier->shipping_external) {
$moduleName = $carrier->external_module_name;
$module = Module::getInstanceByName($moduleName);
if(Validate::isLoadedObject($module)) {
if (Validate::isLoadedObject($module)) {
if(array_key_exists('id_carrier', $module)) {
$module->id_carrier = $carrier->id;
}
@ -373,7 +375,7 @@ class Cart extends CartCore {
}
}
if(Module::isInstalled('privatesales')) {
if (Module::isInstalled('privatesales')) {
$product_cats = array();
foreach($products as $product) {
$product_cats[] = $product['id_category_default'];
@ -387,72 +389,52 @@ class Cart extends CartCore {
$cpt_sales = count($sales);
// si consommables forcer à 5euros
/*if ($cpt_sales==1) {
foreach ($sales as $key => $sale) {
if ((int) $sale['id_sale'] == (int) _SHOP_PRIVATESALES_CONSUMABLE) {
$sale = new Sale((int)$sale['id_sale']);
$sale_carriers = $sale->getCarriers();
foreach ($sale_carriers as $id_c) {
if ((int) $carrier->id == (int) $id_c) {
$shipping_cost = 5;
$shipping_cost = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int)($this->id_currency)));
return $shipping_cost;
}
}
unset($sale_carriers);
if ($cpt_sales == 1) {
// Set a fix shipping cost
$enableFixShippingCost = true;
$shipping_cost_fix = 5;
if ($enableFixShippingCost) {
$cat_shipping_cost_fix = array(8744158);
if (in_array($product_cats[0], $cat_shipping_cost_fix)) {
$shipping_cost = Tools::convertPrice($shipping_cost_fix, Currency::getCurrencyInstance((int)($this->id_currency)));
return $shipping_cost;
}
}
}*/
// Surcout transporteur classique
// if ($carrier->id == 33
// || $carrier->id == 24
// || $carrier->id == 37
// || $carrier->id == 45) {
// if ($carrier->id == 28
// || $carrier->id == 24
// || $carrier->id == 27)
// if ($carrier->id == 45
// || $carrier->id == 46
// || $carrier->id == 47
// || $carrier->id == 48) {
if($cpt_sales == 2) {
$shipping_cost += (float) Configuration::get('PS_SHIPPING_HANDLING_PS_1');
} elseif($cpt_sales == 3) {
$shipping_cost += (float) Configuration::get('PS_SHIPPING_HANDLING_PS_2');
} elseif($cpt_sales == 4) {
$shipping_cost += (float) Configuration::get('PS_SHIPPING_HANDLING_PS_3');
} elseif($cpt_sales == 5) {
$shipping_cost += (float) Configuration::get('PS_SHIPPING_HANDLING_PS_4');
} elseif($cpt_sales >= 6) {
$shipping_cost += (float) Configuration::get('PS_SHIPPING_HANDLING_PS_4');
}
// }
}
else if ($cpt_sales == 2) {
$shipping_cost += (float) Configuration::get('PS_SHIPPING_HANDLING_PS_1');
}
elseif ($cpt_sales == 3) {
$shipping_cost += (float) Configuration::get('PS_SHIPPING_HANDLING_PS_2');
}
elseif ($cpt_sales == 4) {
$shipping_cost += (float) Configuration::get('PS_SHIPPING_HANDLING_PS_3');
}
elseif ($cpt_sales == 5) {
$shipping_cost += (float) Configuration::get('PS_SHIPPING_HANDLING_PS_4');
}
elseif ($cpt_sales >= 6) {
$shipping_cost += (float) Configuration::get('PS_SHIPPING_HANDLING_PS_4');
}
}
// Apply tax
if(isset($carrierTax)) {
if (isset($carrierTax)) {
$shipping_cost *= 1 + ($carrierTax / 100);
}
if(Module::isInstalled('privatesales') && $add_carrier_cost) {
if (Module::isInstalled('privatesales') && $add_carrier_cost) {
if (class_exists('Sale')) {
if (in_array($carrier->id, self::$carrier_special)) {
if(Configuration::get('PRIVATESALES_CARRIERFENCE') ) {
if (Configuration::get('PRIVATESALES_CARRIERFENCE') ) {
$cart_products = $this->getProducts();
if(count($cart_products) > 0) {
if (count($cart_products) > 0) {
$_carriers = array();
foreach ($cart_products as $key => $cart_product) {
$sale = Sale::getSaleFromCategory($cart_product['id_category_default']);
if($sale) {
if ($sale) {
$sale_carriers = $sale->getCarriers();
foreach ($sale_carriers as $carrier_test) {
@ -496,6 +478,7 @@ class Cart extends CartCore {
}
}
}
return (float)(Tools::ps_round((float)($shipping_cost), 2));
}