/** * creates of a dejala carrier corresponding to $dejalaProduct */ public static function createDejalaCarrier($dejalaConfig, $dejalaProduct) { // MFR091130 - get id zone from the country used in the module (if the store zones were customized) - default is 1 (Europe) $id_zone = 1; $moduleCountryIsoCode = strtoupper($dejalaConfig->country); $countryID = Country::getByIso($moduleCountryIsoCode); if (intval($countryID)) { $id_zone = Country::getIdZone($countryID); } $vatRate = floatval($dejalaProduct['vat']); // MFR091130 - get or create the tax & attach it to our zone if needed $id_tax = Tax::getTaxIdByRate($vatRate); if (!$id_tax) { $tax = new Tax(); $tax->rate = $vatRate; $defaultLanguage = Configuration::get('PS_LANG_DEFAULT'); $tax->name[$defaultLanguage] = $tax->rate . '%'; $tax->add(); $id_tax = Tax::getTaxIdByRate($vatRate); } if (!Tax::zoneHasTax($id_tax, $id_zone)) { // MFR : direct call because $tax->addZone($id_zone) causes errors when called Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'tax_zone` (`id_tax` , `id_zone`) VALUES (' . intval($id_tax) . ', ' . intval($id_zone) . ')'); } $carrier = new Carrier(); $carrier->name = 'dejala'; $carrier->id_tax = $id_tax; $carrier->url = 'http://tracking.dejala.' . $dejalaConfig->country . '/tracker/@'; $carrier->active = true; $carrier->deleted = 0; $carrier->shipping_handling = false; $carrier->range_behavior = 0; $carrier->is_module = 1; $languages = Language::getLanguages(true); foreach ($languages as $language) { if ($language['iso_code'] == 'fr') { $carrier->delay[$language['id_lang']] = utf8_encode('Quand vous voulez... Par coursier, ' . $dejalaProduct['timelimit'] . 'H'); } if ($language['iso_code'] == 'en') { $carrier->delay[$language['id_lang']] = utf8_encode('When you want... Dispatch rider, ' . $dejalaProduct['timelimit'] . 'H range'); } if ($language['iso_code'] == 'es') { $carrier->delay[$language['id_lang']] = utf8_encode('Cuando quiera... Por mensajero, ' . $dejalaProduct['timelimit'] . 'H'); } } $carrier->add(); $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'carrier_zone` (`id_carrier` , `id_zone`) VALUES (' . intval($carrier->id) . ', ' . intval($id_zone) . ')'; Db::getInstance()->Execute($sql); $rangeW = new RangeWeight(); $rangeW->id_carrier = $carrier->id; $rangeW->delimiter1 = 0; $rangeW->delimiter2 = $dejalaProduct['max_weight']; $rangeW->add(); $vat_factor = 1 + $dejalaProduct['vat'] / 100; $priceTTC = round($dejalaProduct['price'] * $vat_factor + $dejalaProduct['margin'], 2); $priceHT = round($priceTTC / $vat_factor, 2); $priceList = '(NULL' . ',' . $rangeW->id . ',' . $carrier->id . ',' . $id_zone . ',' . $priceHT . ')'; $carrier->addDeliveryPrice($priceList); return new Carrier($carrier->id); }
public static function getApplicableTax($id_tax, $productTax, $id_address_delivery = NULL) { global $cart, $cookie, $defaultCountry; if (!$id_address_delivery) { $id_address_delivery = intval((Validate::isLoadedObject($cart) and $cart->id_address_delivery) ? $cart->id_address_delivery : (isset($cookie->id_address_delivery) ? $cookie->id_address_delivery : 0)); } /* If customer has an address (implies that he is registered and logged) */ if ($id_address_delivery and $address_ids = Address::getCountryAndState($id_address_delivery)) { $id_zone_country = Country::getIdZone(intval($address_ids['id_country'])); /* If customer's invoice address is inside a state */ if ($address_ids['id_state']) { $state = new State(intval($address_ids['id_state'])); if (!Validate::isLoadedObject($state)) { die(Tools::displayError()); } /* Return tax value depending to the tax behavior */ $tax_behavior = intval($state->tax_behavior); if ($tax_behavior == PS_PRODUCT_TAX) { return $productTax * Tax::zoneHasTax(intval($id_tax), intval($id_zone_country)); } if ($tax_behavior == PS_STATE_TAX) { return Tax::getRateByState(intval($address_ids['id_state'])); } if ($tax_behavior == PS_BOTH_TAX) { return $productTax * Tax::zoneHasTax(intval($id_tax), intval($id_zone_country)) + Tax::getRateByState(intval($address_ids['id_state'])); } /* Unknown behavior */ die(Tools::displayError('Unknown tax behavior!')); } /* Else getting country zone tax */ if (!($id_zone = Address::getZoneById($id_address_delivery))) { die(Tools::displayError()); } return $productTax * Tax::zoneHasTax(intval($id_tax), intval($id_zone)); } /* Default tax application */ if (!Validate::isLoadedObject($defaultCountry)) { die(Tools::displayError()); } return $productTax * Tax::zoneHasTax(intval($id_tax), intval($defaultCountry->id_zone)); }
/** * Return shipping total * * @param integer $id_carrier Carrier ID (default : current carrier) * @return float Shipping total */ function getOrderShippingCost($id_carrier = NULL, $useTax = true) { global $defaultCountry; if ($this->isVirtualCart()) { return 0; } // Checking discounts in cart $products = $this->getProducts(); $discounts = $this->getDiscounts(true); if ($discounts) { foreach ($discounts as $id_discount) { $discount = new Discount(intval($id_discount['id_discount'])); if (!Validate::isLoadedObject($discount)) { die(Tools::displayError()); } if ($discount->id_discount_type == 3) { $total_cart = 0; $categories = Discount::getCategories($discount->id); foreach ($products as $product) { if (count($categories)) { if (Product::idIsOnCategoryId($product['id_product'], $categories)) { $total_cart += $product['total_wt']; } } } if ($total_cart >= $discount->minimal) { return 0; } } } } // Order total without fees $orderTotal = $this->getOrderTotal(true, 7); // Start with shipping cost at 0 $shipping_cost = 0; // If no product added, return 0 if ($orderTotal <= 0 and !intval(self::getNbProducts($this->id))) { return $shipping_cost; } // If no carrier, select default one if (!$id_carrier) { $id_carrier = $this->id_carrier; } if (empty($id_carrier)) { $id_carrier = Configuration::get('PS_CARRIER_DEFAULT'); } if (!isset(self::$_carriers[$id_carrier])) { self::$_carriers[$id_carrier] = new Carrier(intval($id_carrier)); } $carrier = self::$_carriers[$id_carrier]; if (!Validate::isLoadedObject($carrier)) { die(Tools::displayError('Hack attempt: "no default carrier"')); } if (!$carrier->active) { return $shipping_cost; } // Get id zone if (isset($this->id_address_delivery) and $this->id_address_delivery) { $id_zone = Address::getZoneById(intval($this->id_address_delivery)); } else { $id_zone = intval($defaultCountry->id_zone); } // Select carrier tax if ($useTax and $carrier->id_tax) { if (!isset(self::$_taxes[$carrier->id_tax])) { self::$_taxes[$carrier->id_tax] = new Tax(intval($carrier->id_tax)); } $tax = self::$_taxes[$carrier->id_tax]; if (Validate::isLoadedObject($tax) and Tax::zoneHasTax(intval($tax->id), intval($id_zone)) and !Tax::excludeTaxeOption()) { $carrierTax = $tax->rate; } } $configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT')); // Free fees if (isset($configuration['PS_SHIPPING_FREE_PRICE']) and $orderTotal >= floatval($configuration['PS_SHIPPING_FREE_PRICE']) and floatval($configuration['PS_SHIPPING_FREE_PRICE']) > 0) { return $shipping_cost; } if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) and $this->getTotalWeight() >= floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) and floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0) { return $shipping_cost; } // Get shipping cost using correct method if ($carrier->range_behavior) { // Get id zone if (isset($this->id_address_delivery) and $this->id_address_delivery) { $id_zone = Address::getZoneById(intval($this->id_address_delivery)); } else { $id_zone = intval($defaultCountry->id_zone); } if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice($carrier->id, $this->getOrderTotal(true, 4), $id_zone)) { $shipping_cost += 0; } else { if (intval($configuration['PS_SHIPPING_METHOD'])) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone); } else { $shipping_cost += $carrier->getDeliveryPriceByPrice($orderTotal, $id_zone); } } } else { if (intval($configuration['PS_SHIPPING_METHOD'])) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone); } else { $shipping_cost += $carrier->getDeliveryPriceByPrice($orderTotal, $id_zone); } } // Apply tax if (isset($carrierTax)) { $shipping_cost *= 1 + $carrierTax / 100; } // Adding handling charges if (isset($configuration['PS_SHIPPING_HANDLING']) and $carrier->shipping_handling) { $shipping_cost += floatval($configuration['PS_SHIPPING_HANDLING']); } return floatval($shipping_cost); }
/** * Tax table */ public function TaxTab(array &$priceBreakDown) { if (!($id_zone = Address::getZoneById(intval(self::$order->id_address_invoice)))) { die(Tools::displayError()); } if (self::$order->total_paid == '0.00' or !intval(Configuration::get('PS_TAX')) and self::$order->total_products == self::$order->total_products_wt) { return; } // Setting products tax if (isset(self::$order->products) and sizeof(self::$order->products)) { $products = self::$order->products; } else { $products = self::$order->getProducts(); } $carrier = new Carrier(self::$order->id_carrier); $carrierTax = new Tax($carrier->id_tax); if ($priceBreakDown['totalsWithoutTax'] == $priceBreakDown['totalsWithTax'] and (!$carrierTax->rate or $carrierTax->rate == '0.00') and (!self::$order->total_wrapping or self::$order->total_wrapping == '0.00')) { return; } // Displaying header tax $header = array(self::l('Tax detail'), self::l('Tax %'), self::l('Pre-Tax Total'), self::l('Total Tax'), self::l('Total with Tax')); $w = array(60, 30, 40, 30, 30); $this->SetFont(self::fontname(), 'B', 8); for ($i = 0; $i < sizeof($header); $i++) { $this->Cell($w[$i], 5, $header[$i], 0, 0, 'R'); } $this->Ln(); $this->SetFont(self::fontname(), '', 7); $nb_tax = 0; $total = 0; // Display product tax foreach ($priceBreakDown['taxes'] as $tax_rate => $vat) { if ($tax_rate != '0.00' and $priceBreakDown['totalsProductsWithTax'][$tax_rate] != '0.00') { $nb_tax++; $before = $this->GetY(); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX(), $this->GetY() - $lineSize + 3); $this->Cell($w[0], $lineSize, self::l('Products'), 0, 0, 'R'); $this->Cell($w[1], $lineSize, number_format($tax_rate, 3, ',', ' '), 0, 0, 'R'); $this->Cell($w[2], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['totalsProductsWithoutTax'][$tax_rate], self::$currency, true, false)), 0, 0, 'R'); $this->Cell($w[3], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['totalsProductsWithTax'][$tax_rate] - $priceBreakDown['totalsProductsWithoutTax'][$tax_rate], self::$currency, true, false)), 0, 0, 'R'); $this->Cell($w[4], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['totalsProductsWithTax'][$tax_rate], self::$currency, true, false)), 0, 0, 'R'); $this->Ln(); } } // Display carrier tax if ($carrierTax->rate and $carrierTax->rate != '0.00' and (self::$order->total_shipping != '0.00' and !self::$orderSlip or self::$orderSlip and self::$orderSlip->shipping_cost) and Tax::zoneHasTax(intval($carrier->id_tax), intval($id_zone))) { $nb_tax++; $before = $this->GetY(); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX(), $this->GetY() - $lineSize + 3); $this->Cell($w[0], $lineSize, self::l('Carrier'), 0, 0, 'R'); $this->Cell($w[1], $lineSize, number_format($carrierTax->rate, 3, ',', ' '), 0, 0, 'R'); $this->Cell($w[2], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['shippingCostWithoutTax'], self::$currency, true, false)), 0, 0, 'R'); $this->Cell($w[3], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$order->total_shipping - $priceBreakDown['shippingCostWithoutTax'], self::$currency, true, false)), 0, 0, 'R'); $this->Cell($w[4], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$order->total_shipping, self::$currency, true, false)), 0, 0, 'R'); $this->Ln(); } // Display wrapping tax if (self::$order->total_wrapping and self::$order->total_wrapping != '0.00') { $tax = new Tax(intval(Configuration::get('PS_GIFT_WRAPPING_TAX'))); $taxRate = $tax->rate; $nb_tax++; $before = $this->GetY(); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX(), $this->GetY() - $lineSize + 3); $this->Cell($w[0], $lineSize, self::l('Wrapping'), 0, 0, 'R'); $this->Cell($w[1], $lineSize, number_format($taxRate, 3, ',', ' '), 0, 0, 'R'); $this->Cell($w[2], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice($priceBreakDown['wrappingCostWithoutTax'], self::$currency, true, false)), 0, 0, 'R'); $this->Cell($w[3], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$order->total_wrapping - $priceBreakDown['wrappingCostWithoutTax'], self::$currency, true, false)), 0, 0, 'R'); $this->Cell($w[4], $lineSize, (self::$orderSlip ? '-' : '') . self::convertSign(Tools::displayPrice(self::$order->total_wrapping, self::$currency, true, false)), 0, 0, 'R'); } if (!$nb_tax) { $this->Cell(190, 10, self::l('No tax'), 0, 0, 'C'); } }
/** * Tax table */ public function TaxTab() { if (!($id_zone = Address::getZoneById(intval(self::$order->id_address_invoice)))) { die(Tools::displayError()); } if (self::$order->total_paid == '0.00' or !intval(Configuration::get('PS_TAX'))) { return; } // Setting products tax if (isset(self::$order->products) and sizeof(self::$order->products)) { $products = self::$order->products; } else { $products = self::$order->getProducts(); } $totalWithTax = array(); $totalWithoutTax = array(); $amountWithoutTax = 0; $taxes = array(); /* Firstly calculate all prices */ foreach ($products as &$product) { if (!isset($totalWithTax[$product['tax_rate']])) { $totalWithTax[$product['tax_rate']] = 0; } if (!isset($totalWithoutTax[$product['tax_rate']])) { $totalWithoutTax[$product['tax_rate']] = 0; } if (!isset($taxes[$product['tax_rate']])) { $taxes[$product['tax_rate']] = 0; } /* Without tax */ $product['priceWithoutTax'] = floatval($product['product_price']) * intval($product['product_quantity']); $amountWithoutTax += $product['priceWithoutTax']; /* With tax */ $product['priceWithTax'] = $product['priceWithoutTax'] * (1 + floatval($product['tax_rate']) / 100); } $tmp = 0; $product =& $tmp; /* And secondly assign to each tax its own reduction part */ $discountAmount = floatval(self::$order->total_discounts); foreach ($products as $product) { $ratio = $amountWithoutTax == 0 ? 0 : $product['priceWithoutTax'] / $amountWithoutTax; $priceWithTaxAndReduction = $product['priceWithTax'] - $discountAmount * $ratio; $vat = $priceWithTaxAndReduction - $priceWithTaxAndReduction / (floatval($product['tax_rate']) / 100 + 1); $taxes[$product['tax_rate']] += $vat; $totalWithTax[$product['tax_rate']] += $priceWithTaxAndReduction; $totalWithoutTax[$product['tax_rate']] += $priceWithTaxAndReduction - $vat; } $carrier = new Carrier(self::$order->id_carrier); $carrierTax = new Tax($carrier->id_tax); if ($totalWithoutTax == $totalWithTax and (!$carrierTax->rate or $carrierTax->rate == '0.00') and (!self::$order->total_wrapping or self::$order->total_wrapping == '0.00')) { return; } // Displaying header tax $header = array(self::l('Tax detail'), self::l('Tax %'), self::l('Pre-Tax Total'), self::l('Total Tax'), self::l('Total with Tax')); $w = array(60, 30, 40, 30, 30); $this->SetFont(self::fontname(), 'B', 8); for ($i = 0; $i < sizeof($header); $i++) { $this->Cell($w[$i], 5, $header[$i], 0, 0, 'R'); } $this->Ln(); $this->SetFont(self::fontname(), '', 7); $nb_tax = 0; // Display product tax if (intval(Configuration::get('PS_TAX')) and self::$order->total_paid != '0.00') { foreach ($taxes as $tax_rate => $vat) { if ($tax_rate == '0.00' or $totalWithTax[$tax_rate] == '0.00') { continue; } $nb_tax++; $before = $this->GetY(); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX(), $this->GetY() - $lineSize + 3); $this->Cell($w[0], $lineSize, self::l('Products'), 0, 0, 'R'); $this->Cell($w[1], $lineSize, number_format($tax_rate, 2, ',', ' '), 0, 0, 'R'); $this->Cell($w[2], $lineSize, self::convertSign(Tools::displayPrice($totalWithoutTax[$tax_rate], self::$currency, true, false)), 0, 0, 'R'); $this->Cell($w[3], $lineSize, self::convertSign(Tools::displayPrice($vat, self::$currency, true, false)), 0, 0, 'R'); $this->Cell($w[4], $lineSize, self::convertSign(Tools::displayPrice($totalWithTax[$tax_rate], self::$currency, true, false)), 0, 0, 'R'); $this->Ln(); } } // Display carrier tax if ($carrierTax->rate and $carrierTax->rate != '0.00' and self::$order->total_shipping != '0.00' and Tax::zoneHasTax(intval($carrier->id_tax), intval($id_zone))) { $nb_tax++; $total_shipping_wt = self::$order->total_shipping / (1 + $carrierTax->rate / 100); $before = $this->GetY(); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX(), $this->GetY() - $lineSize + 3); $this->Cell($w[0], $lineSize, self::l('Carrier'), 0, 0, 'R'); $this->Cell($w[1], $lineSize, number_format($carrierTax->rate, 2, ',', ' '), 0, 0, 'R'); $this->Cell($w[2], $lineSize, self::convertSign(Tools::displayPrice($total_shipping_wt, self::$currency, true, false)), 0, 0, 'R'); $this->Cell($w[3], $lineSize, self::convertSign(Tools::displayPrice(self::$order->total_shipping - $total_shipping_wt, self::$currency, true, false)), 0, 0, 'R'); $this->Cell($w[4], $lineSize, self::convertSign(Tools::displayPrice(self::$order->total_shipping, self::$currency, true, false)), 0, 0, 'R'); $this->Ln(); } // Display wrapping tax if (self::$order->total_wrapping and self::$order->total_wrapping != '0.00') { $nb_tax++; $total_wrapping_wt = self::$order->total_wrapping / (1 + $tax_rate / 100); $before = $this->GetY(); $lineSize = $this->GetY() - $before; $this->SetXY($this->GetX(), $this->GetY() - $lineSize + 3); $this->Cell($w[0], $lineSize, self::l('Wrapping'), 0, 0, 'R'); $this->Cell($w[1], $lineSize, number_format($tax_rate, 2, ',', ' '), 0, 0, 'R'); $this->Cell($w[2], $lineSize, self::convertSign(Tools::displayPrice($total_wrapping_wt, self::$currency, true, false)), 0, 0, 'R'); $this->Cell($w[3], $lineSize, self::convertSign(Tools::displayPrice(self::$order->total_wrapping - $total_wrapping_wt, self::$currency, true, false)), 0, 0, 'R'); $this->Cell($w[4], $lineSize, self::convertSign(Tools::displayPrice(self::$order->total_wrapping, self::$currency, true, false)), 0, 0, 'R'); } if (!$nb_tax) { $this->Cell(190, 10, self::l('No tax'), 0, 0, 'C'); } }
/** * Return shipping total * * @param integer $id_carrier Carrier ID (default : current carrier) * @return float Shipping total */ function getOrderShippingCost($id_carrier = NULL, $useTax = true) { global $defaultCountry; if ($this->isVirtualCart()) { return 0; } // Checking discounts in cart $products = $this->getProducts(); $discounts = $this->getDiscounts(true); if ($discounts) { foreach ($discounts as $id_discount) { if ($id_discount['id_discount_type'] == 3) { if ($id_discount['minimal'] > 0) { $total_cart = 0; $categories = Discount::getCategories(intval($id_discount['id_discount'])); if (sizeof($categories)) { foreach ($products as $product) { if (Product::idIsOnCategoryId(intval($product['id_product']), $categories)) { $total_cart += $product['total_wt']; } } } if ($total_cart >= $id_discount['minimal']) { return 0; } } else { return 0; } } } } // Order total without fees $orderTotal = $this->getOrderTotal(true, 7); // Start with shipping cost at 0 $shipping_cost = 0; // If no product added, return 0 if ($orderTotal <= 0 and !intval(self::getNbProducts($this->id))) { return $shipping_cost; } // Get id zone if (isset($this->id_address_delivery) and $this->id_address_delivery) { $id_zone = Address::getZoneById(intval($this->id_address_delivery)); } else { $id_zone = intval($defaultCountry->id_zone); } // If no carrier, select default one if (!$id_carrier) { $id_carrier = $this->id_carrier; } if (empty($id_carrier)) { if (Configuration::get('PS_SHIPPING_METHOD') and Carrier::checkDeliveryPriceByWeight(intval(Configuration::get('PS_CARRIER_DEFAULT')), $this->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and Carrier::checkDeliveryPriceByPrice(intval(Configuration::get('PS_CARRIER_DEFAULT')), $this->getOrderTotal(true, 4), $id_zone)) { $id_carrier = intval(Configuration::get('PS_CARRIER_DEFAULT')); } } if (empty($id_carrier)) { if (intval($this->id_customer)) { $customer = new Customer(intval($this->id_customer)); $result = Carrier::getCarriers(intval(Configuration::get('PS_LANG_DEFAULT')), true, false, intval($id_zone), $customer->getGroups()); unset($customer); } else { $result = Carrier::getCarriers(intval(Configuration::get('PS_LANG_DEFAULT')), true, false, intval($id_zone)); } $resultsArray = array(); foreach ($result as $k => $row) { if ($row['id_carrier'] == Configuration::get('PS_CARRIER_DEFAULT')) { continue; } if (!isset(self::$_carriers[$row['id_carrier']])) { self::$_carriers[$row['id_carrier']] = new Carrier(intval($row['id_carrier'])); } $carrier = self::$_carriers[$row['id_carrier']]; // Get only carriers that are compliant with shipping method if (Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false or !Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) { unset($result[$k]); continue; } // If out-of-range behavior carrier is set on "Desactivate carrier" if ($row['range_behavior']) { // Get only carriers that have a range compatible with cart if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->getOrderTotal(true, 4), $id_zone)) { unset($result[$k]); continue; } } if (intval(Configuration::get('PS_SHIPPING_METHOD'))) { $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone); if (!isset($tmp)) { $tmp = $shipping; } if ($shipping <= $tmp) { $id_carrier = intval($row['id_carrier']); } } else { $shipping = $carrier->getDeliveryPriceByPrice($orderTotal, $id_zone); if (!isset($tmp)) { $tmp = $shipping; } if ($shipping <= $tmp) { $id_carrier = intval($row['id_carrier']); } } } } if (empty($id_carrier)) { $id_carrier = Configuration::get('PS_CARRIER_DEFAULT'); } if (!isset(self::$_carriers[$id_carrier])) { self::$_carriers[$id_carrier] = new Carrier(intval($id_carrier)); } $carrier = self::$_carriers[$id_carrier]; if (!Validate::isLoadedObject($carrier)) { die(Tools::displayError('Fatal error: "no default carrier"')); } if (!$carrier->active) { return $shipping_cost; } // Select carrier tax if ($useTax and $carrier->id_tax) { if (!isset(self::$_taxes[$carrier->id_tax])) { self::$_taxes[$carrier->id_tax] = new Tax(intval($carrier->id_tax)); } $tax = self::$_taxes[$carrier->id_tax]; if (Validate::isLoadedObject($tax) and Tax::zoneHasTax(intval($tax->id), intval($id_zone)) and !Tax::excludeTaxeOption()) { $carrierTax = $tax->rate; } } $configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT')); // Free fees $free_fees_price = 0; if (isset($configuration['PS_SHIPPING_FREE_PRICE'])) { $free_fees_price = Tools::convertPrice(floatval($configuration['PS_SHIPPING_FREE_PRICE']), new Currency(intval($this->id_currency))); } $orderTotalwithDiscounts = $this->getOrderTotal(true, 4); if ($orderTotalwithDiscounts >= floatval($free_fees_price) and floatval($free_fees_price) > 0) { return $shipping_cost; } if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) and $this->getTotalWeight() >= floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) and floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0) { return $shipping_cost; } // Get shipping cost using correct method if ($carrier->range_behavior) { // Get id zone if (isset($this->id_address_delivery) and $this->id_address_delivery) { $id_zone = Address::getZoneById(intval($this->id_address_delivery)); } else { $id_zone = intval($defaultCountry->id_zone); } if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice($carrier->id, $this->getOrderTotal(true, 4), $id_zone)) { $shipping_cost += 0; } else { if (intval($configuration['PS_SHIPPING_METHOD'])) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone); } else { $shipping_cost += $carrier->getDeliveryPriceByPrice($orderTotal, $id_zone); } } } else { if (intval($configuration['PS_SHIPPING_METHOD'])) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone); } else { $shipping_cost += $carrier->getDeliveryPriceByPrice($orderTotal, $id_zone); } } // Adding handling charges if (isset($configuration['PS_SHIPPING_HANDLING']) and $carrier->shipping_handling) { $shipping_cost += floatval($configuration['PS_SHIPPING_HANDLING']); } $shipping_cost = Tools::convertPrice($shipping_cost, new Currency(intval($this->id_currency))); // Apply tax if (isset($carrierTax)) { $shipping_cost *= 1 + $carrierTax / 100; } return floatval(Tools::ps_round(floatval($shipping_cost), 2)); }