public function run() { $this->init(); $this->preProcess(); if (Tools::getValue('ajax') == 'true') { if (Tools::getIsset('summary')) { $result = array(); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { if (self::$cookie->id_customer) { $customer = new Customer((int) self::$cookie->id_customer); $groups = $customer->getGroups(); } else { $groups = array(1); } if ((int) self::$cart->id_address_delivery) { $deliveryAddress = new Address((int) self::$cart->id_address_delivery); $id_zone = Address::getZoneById((int) $deliveryAddress->id); } if (!isset($id_zone)) { $id_zone = (int) Country::getIdZone(isset($deliveryAddress) && (int) $deliveryAddress->id ? (int) $deliveryAddress->id_country : (int) _PS_COUNTRY_DEFAULT_); } $result['carriers'] = Carrier::getCarriersForOrder($id_zone, $groups); $result['checked'] = Carrier::getDefaultCarrierSelection($result['carriers'], (int) self::$cart->id_carrier); $result['HOOK_EXTRACARRIER'] = Module::hookExec('extraCarrier', array('address' => isset($deliveryAddress) && (int) $deliveryAddress->id ? $deliveryAddress : null)); } $result['summary'] = self::$cart->getSummaryDetails(); $result['customizedDatas'] = Product::getAllCustomizedDatas((int) self::$cart->id); $result['HOOK_SHOPPING_CART'] = Module::hookExec('shoppingCart', $result['summary']); $result['HOOK_SHOPPING_CART_EXTRA'] = Module::hookExec('shoppingCartExtra', $result['summary']); die(Tools::jsonEncode($result)); } else { $this->includeCartModule(); } } else { $this->setMedia(); $this->displayHeader(); $this->process(); $this->displayContent(); $this->displayFooter(); } }
private function cartToOrder($items, $foreignKey) { $this->alterTable('order'); foreach ($items as $item) { $order = new Order(); $order->id_carrier = (int) $item['id_carrier']; $order->id_customer = (int) $foreignKey['id_customer'][$item['id_customer']]; $order->id_address_invoice = (int) $foreignKey['id_address_invoice'][$item['id_address_invoice']]; $order->id_address_delivery = (int) $foreignKey['id_address_delivery'][$item['id_address_delivery']]; $vat_address = new Address((int) $foreignKey['id_address_delivery'][$item['id_address_delivery']]); $id_zone = Address::getZoneById((int) $vat_address->id); $order->id_currency = (int) $item['id_currency']; $order->id_lang = (int) $item['id_lang']; $order->id_cart = (int) $foreignKey['id_cart'][$item['id_cart']]; $customer = new Customer((int) $order->id_customer); $order->secure_key = pSQL($customer->secure_key); $order->payment = Tools::substr($item['payment'], 0, 32); if (isset($this->name)) { $order->module = $this->name; } $currency = new Currency($order->id_currency); $order->conversion_rate = $currency->conversion_rate; $order->total_products = (double) $item['total_products']; $order->total_products_wt = (double) $item['total_products_wt']; $order->total_discounts = (double) $item['total_discounts']; $order->total_shipping = (double) $item['total_shipping']; $order->carrier_tax_rate = (double) Tax::getCarrierTaxRate((int) $item['id_carrier'], (int) $item[Configuration::get('PS_TAX_ADDRESS_TYPE')]); $order->total_wrapping = (double) $item['total_wrapping']; $order->total_paid = (double) $item['total_paid']; $order->total_paid_real = (double) $item['total_paid_real']; $order->invoice_date = '0000-00-00 00:00:00'; $order->delivery_date = '0000-00-00 00:00:00'; $order->add(); $this->saveMatchId('order', (int) $order->id, (int) $item['id_cart']); } }
private function cartToOrder($items, $foreignKey) { $this->alterTable('order'); foreach ($items as $item) { $order = new Order(); $order->id_carrier = (int) $item['id_carrier']; $order->id_customer = (int) $foreignKey['id_customer'][$item['id_customer']]; $order->id_address_invoice = (int) $foreignKey['id_address_invoice'][$item['id_address_invoice']]; $order->id_address_delivery = (int) $foreignKey['id_address_delivery'][$item['id_address_delivery']]; $vat_address = new Address((int) $foreignKey['id_address_delivery'][$item['id_address_delivery']]); $id_zone = Address::getZoneById((int) $vat_address->id); $order->id_currency = (int) $item['id_currency']; $order->id_lang = (int) $item['id_lang']; $order->id_cart = (int) $foreignKey['id_cart'][$item['id_cart']]; $customer = new Customer((int) $order->id_customer); $order->secure_key = pSQL($customer->secure_key); if (!strlen(trim($item['payment']))) { $order->payment = 'payment' . Tools::getValue('moduleName'); } else { $order->payment = utf8_encode(html_entity_decode(strip_tags(Tools::substr($item['payment'], 0, 32)))); } if (isset($this->name)) { $order->module = $this->name; } $carrier = new Carrier((int) $item['id_carrier']); $currency = new Currency($order->id_currency); $order->conversion_rate = !empty($currency->conversion_rate) ? $currency->conversion_rate : 1; $order->total_products = (double) $item['total_products']; $order->total_products_wt = (double) $item['total_products_wt']; $order->total_discounts = (double) $item['total_discounts']; $order->total_shipping = (double) $item['total_shipping']; $order->carrier_tax_rate = (double) $carrier->getTaxesRate(new Address((int) $item[Configuration::get('PS_TAX_ADDRESS_TYPE')])); $order->total_wrapping = (double) $item['total_wrapping']; $order->total_paid = (double) $item['total_paid']; $order->total_paid_real = (double) $item['total_paid_real']; $order->invoice_date = '0000-00-00 00:00:00'; $order->delivery_date = '0000-00-00 00:00:00'; if (array_key_exists('date_add', $item)) { $order->date_add = $item['date_add']; } if (array_key_exists('date_upd', $item)) { $order->date_upd = $item['date_upd']; } //test valid paid if ($item['total_paid'] == $item['total_paid_real']) { $order->valid = 1; } else { $order->valid = 0; } $order->save(false, false); $this->saveMatchId('order', (int) $order->id, (int) $item['id_cart']); } }
public function hookExtraCarrier($params) { // TODO : Makes it work with multi-shipping if (!MondialRelay::isAccountSet()) { return ''; } $id_carrier = false; $preSelectedRelay = $this->getRelayPointSelected($this->context->cart->id); $carriersList = MondialRelay::_getCarriers(); $address = new Address($this->context->cart->id_address_delivery); $id_zone = Address::getZoneById((int) $address->id); // Check if the defined carrier are ok foreach ($carriersList as $k => $row) { // For now works only with single shipping (>= 1.5 compatibility) if (method_exists($this->context->cart, 'carrierIsSelected')) { if ($this->context->cart->carrierIsSelected($row['id_carrier'], $params['address']->id)) { $id_carrier = $row['id_carrier']; } } // Temporary carrier for some test $carrier = new Carrier((int) $row['id_carrier']); if (Configuration::get('PS_SHIPPING_METHOD') && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false || !Configuration::get('PS_SHIPPING_METHOD') && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) { unset($carriersList[$k]); } else { if ($row['range_behavior']) { // Get id zone $id_zone = isset($this->context->cart->id_address_delivery) && $this->context->cart->id_address_delivery ? Address::getZoneById((int) $this->context->cart->id_address_delivery) : (int) $this->context->country->id_zone; if (Configuration::get('PS_SHIPPING_METHOD') && !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->context->cart->getTotalWeight(), $id_zone) || !Configuration::get('PS_SHIPPING_METHOD') && (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->context->cart->getOrderTotal(true, MondialRelay::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency) || !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->context->cart->getOrderTotal(true, MondialRelay::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency))) { unset($carriersList[$k]); } } } } $carrier = NULL; if (_PS_VERSION_ >= '1.5') { $id_carrier = (int) $this->context->cart->id_carrier; } if ($id_carrier && ($method = MondialRelay::getMethodByIdCarrier($id_carrier))) { $carrier = new Carrier((int) $id_carrier); // Add dynamically a new field $carrier->id_mr_method = $method['id_mr_method']; $carrier->mr_dlv_mode = $method['dlv_mode']; } $this->context->smarty->assign(array('MR_Data' => MRTools::jsonEncode(array('carrier_list' => $carriersList, 'carrier' => $carrier, 'PS_VERSION' => _PS_VERSION_, 'pre_selected_relay' => isset($preSelectedRelay['MR_selected_num']) ? $preSelectedRelay['MR_selected_num'] : 0)))); return $this->fetchTemplate('/tpl/', 'checkout_process'); }
protected function _assignCarrier() { $address = new Address($this->context->cart->id_address_delivery); $id_zone = Address::getZoneById($address->id); $carriers = $this->context->cart->simulateCarriersOutput(null, true); $checked = $this->context->cart->simulateCarrierSelectedOutput(false); $delivery_option_list = $this->context->cart->getDeliveryOptionList(); $this->setDefaultCarrierSelection($delivery_option_list); $this->context->smarty->assign(array('address_collection' => $this->context->cart->getAddressCollection(), 'delivery_option_list' => $delivery_option_list, 'carriers' => $carriers, 'checked' => $checked, 'delivery_option' => $this->context->cart->getDeliveryOption(null, false))); $vars = array('HOOK_BEFORECARRIER' => Hook::exec('displayBeforeCarrier', array('carriers' => $carriers, 'checked' => $checked, 'delivery_option_list' => $delivery_option_list, 'delivery_option' => $this->context->cart->getDeliveryOption(null, false)))); Cart::addExtraCarriers($vars); $this->context->smarty->assign($vars); }
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)); }
private function checkSoCarrierAvailable($id_carrier) { global $cart, $defaultCountry; $carrier = new Carrier((int) $id_carrier); $address = new Address((int) $cart->id_address_delivery); $id_zone = Address::getZoneById((int) $address->id); // 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) { return false; } // If out-of-range behavior carrier is set on "Desactivate carrier" if ($carrier->range_behavior) { // Get id zone if (isset($cart->id_address_delivery) and $cart->id_address_delivery) { $id_zone = Address::getZoneById((int) $cart->id_address_delivery); } else { $id_zone = (int) $defaultCountry->id_zone; } // Get only carriers that have a range compatible with cart if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight((int) $carrier->id, $cart->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice((int) $carrier->id, $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $cart->id_currency)) { return false; } } return true; }
public function getOrderShippingCostExternal($cart, $products = array()) { if (!$this->id_carrier || !$cart instanceof Cart) { return false; } $cache_key = $this->getCacheKey($cart, $products); if (isset(self::$carriers[$this->id_carrier][$cache_key])) { return self::$carriers[$this->id_carrier][$cache_key]; } $id_address_delivery = empty($products) ? (int) $cart->id_address_delivery : (int) $this->getIdAddressDeliveryByProducts($products); $id_customer_country = (int) Tools::getValue('id_country'); if (!$id_customer_country) { $customer_country = Address::getCountryAndState((int) $id_address_delivery); $id_customer_country = (int) $customer_country['id_country']; } $zone = $id_customer_country ? Country::getIdZone((int) $id_customer_country) : Address::getZoneById((int) $id_address_delivery); if (!($id_method = self::getMethodIdByCarrierId($this->id_carrier))) { self::$carriers[$this->id_carrier][$cache_key] = false; return false; } $carrier = new Carrier((int) $this->id_carrier); if (!Validate::isLoadedObject($carrier)) { return false; } $configuration = new DpdGroupConfiguration(); $is_cod_method = $this->isCODCarrier((int) $this->id_carrier); if ($is_cod_method && !$this->isCODCarrierAvailable($cart, $configuration, (int) $id_customer_country)) { self::$carriers[$this->id_carrier][$cache_key] = false; return false; } $carrier_shipping_method = $carrier->getShippingMethod(); $order_total_price = empty($products) ? $cart->getOrderTotal(false, Cart::BOTH_WITHOUT_SHIPPING) : $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $products, $this->id_carrier); $total_weight = empty($products) ? $cart->getTotalWeight() : $cart->getTotalWeight($products); $cart_total = $carrier_shipping_method == Carrier::SHIPPING_METHOD_WEIGHT ? DpdGroupShipment::convertWeight($total_weight) : $order_total_price; $price_rule = DpdGroupShipment::getPriceRule($cart_total, $id_method, $id_address_delivery, $is_cod_method); $additional_shipping_cost = $this->calculateAdditionalShippingCost($cart, $products); $additional_shipping_cost = Tools::convertPrice($additional_shipping_cost); $handling_charges = $carrier->shipping_handling ? Configuration::get('PS_SHIPPING_HANDLING') : 0; $handling_charges = Tools::convertPrice($handling_charges); $price = false; switch ($configuration->price_calculation_method) { case DpdGroupConfiguration::PRICE_CALCULATION_PRESTASHOP: $price = $this->getPriceByPrestaShopCalculationType($carrier_shipping_method, $carrier, $total_weight, $zone, $additional_shipping_cost, $handling_charges, $is_cod_method, $order_total_price, $configuration, $price_rule); break; case DpdGroupConfiguration::PRICE_CALCULATION_WEB_SERVICES: $price = $this->getPriceByWebServicesCalculationType($cart, $is_cod_method, $order_total_price, $id_method, $id_address_delivery, $additional_shipping_cost, $handling_charges, $configuration, $price_rule, $products); break; case DpdGroupConfiguration::PRICE_CALCULATION_CSV: $price = $this->getPriceByCSVCalculationType($price_rule, $order_total_price, $additional_shipping_cost, $handling_charges, $is_cod_method, $configuration); break; } self::$carriers[$this->id_carrier][$cache_key] = $price; return self::$carriers[$this->id_carrier][$cache_key]; }
protected function _assignCarrier() { $address = new Address($this->context->cart->id_address_delivery); $id_zone = Address::getZoneById($address->id); if (!Address::isCountryActiveById((int) $this->context->cart->id_address_delivery) || !Address::isCountryActiveById((int) $this->context->cart->id_address_invoice)) { Tools::redirect('index.php?controller=order&step=1'); } $carriers = $this->context->cart->simulateCarriersOutput(); $checked = $this->context->cart->simulateCarrierSelectedOutput(); $delivery_option_list = $this->context->cart->getDeliveryOptionList(); $this->setDefaultCarrierSelection($delivery_option_list); $this->context->smarty->assign(array('address_collection' => $this->context->cart->getAddressCollection(), 'delivery_option_list' => $delivery_option_list, 'carriers' => $carriers, 'checked' => $checked, 'delivery_option' => $this->context->cart->getDeliveryOption(null, false))); $vars = array('HOOK_BEFORECARRIER' => Hook::exec('displayBeforeCarrier', array('carriers' => $carriers, 'checked' => $checked, 'delivery_option_list' => $delivery_option_list, 'delivery_option' => $this->context->cart->getDeliveryOption(null, false)))); Cart::addExtraCarriers($vars); $this->context->smarty->assign($vars); }
public function getCarriers() { global $cookie, $cart; // code taken from ParentOrderController::_assignCarrier() $customer = new Customer((int) $cookie->id_customer); $address = new Address((int) $cart->id_address_delivery); $id_zone = Address::getZoneById((int) $address->id); $carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups()); return $carriers; }
/** * 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'); } }
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()); self::$smarty->assign(array('checked' => $this->_setDefaultCarrierSelection($carriers), 'carriers' => $carriers, 'default_carrier' => (int) Configuration::get('PS_CARRIER_DEFAULT'), 'HOOK_EXTRACARRIER' => Module::hookExec('extraCarrier', array('address' => $address)), 'HOOK_BEFORECARRIER' => Module::hookExec('beforeCarrier', array('carriers' => $carriers)))); }
function displayCarrier() { global $smarty, $cart, $cookie, $defaultCountry, $link; $address = new Address(intval($cart->id_address_delivery)); $id_zone = Address::getZoneById(intval($address->id)); if (isset($cookie->id_customer)) { $customer = new Customer(intval($cookie->id_customer)); } else { die(Tools::displayError($this->l('Fatal error: No customer'))); } $result = Carrier::getCarriers(intval($cookie->id_lang), true, false, intval($id_zone), $customer->getGroups()); if (!$result) { $result = Carrier::getCarriers(intval($cookie->id_lang), true, false, intval($id_zone)); } $resultsArray = array(); foreach ($result as $k => $row) { $carrier = new Carrier(intval($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 id zone if (isset($cart->id_address_delivery) and $cart->id_address_delivery) { $id_zone = Address::getZoneById(intval($cart->id_address_delivery)); } else { $id_zone = intval($defaultCountry->id_zone); } // Get only carriers that have a range compatible with cart if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, 4), $id_zone)) { unset($result[$k]); continue; } } $row['name'] = strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME'); $row['price'] = $cart->getOrderShippingCost(intval($row['id_carrier'])); $row['price_tax_exc'] = $cart->getOrderShippingCost(intval($row['id_carrier']), false); $row['img'] = file_exists(_PS_SHIP_IMG_DIR_ . intval($row['id_carrier']) . '.jpg') ? _THEME_SHIP_DIR_ . intval($row['id_carrier']) . '.jpg' : ''; $resultsArray[] = $row; } // Wrapping fees $wrapping_fees = floatval(Configuration::get('PS_GIFT_WRAPPING_PRICE')); $wrapping_fees_tax = new Tax(intval(Configuration::get('PS_GIFT_WRAPPING_TAX'))); $wrapping_fees_tax_inc = $wrapping_fees * (1 + floatval($wrapping_fees_tax->rate) / 100); if (Validate::isUnsignedInt($cart->id_carrier) and $cart->id_carrier) { $carrier = new Carrier(intval($cart->id_carrier)); if ($carrier->active and !$carrier->deleted) { $checked = intval($cart->id_carrier); } } $cms = new CMS(3, intval($cookie->id_lang)); $link_conditions = $link->getCMSLink($cms, $cms->link_rewrite); if (!strpos($link_conditions, '?')) { $link_conditions .= '?content_only=1&TB_iframe=true&width=450&height=500&thickbox=true'; } else { $link_conditions .= '&content_only=1&TB_iframe=true&width=450&height=500&thickbox=true'; } if (!isset($checked) or intval($checked) == 0) { $checked = intval(Configuration::get('PS_CARRIER_DEFAULT')); } $smarty->assign(array('checkedTOS' => intval($cookie->checkedTOS), 'recyclablePackAllowed' => intval(Configuration::get('PS_RECYCLABLE_PACK')), 'giftAllowed' => intval(Configuration::get('PS_GIFT_WRAPPING')), 'conditions' => intval(Configuration::get('PS_CONDITIONS')), 'link_conditions' => $link_conditions, 'recyclable' => intval($cart->recyclable), 'gift_wrapping_price' => floatval(Configuration::get('PS_GIFT_WRAPPING_PRICE')), 'carriers' => $resultsArray, 'HOOK_EXTRACARRIER' => Module::hookExec('extraCarrier', array('address' => $address)), 'checked' => intval($checked), 'total_wrapping' => Tools::convertPrice($wrapping_fees_tax_inc, new Currency(intval($cookie->id_currency))), 'total_wrapping_tax_exc' => Tools::convertPrice($wrapping_fees, new Currency(intval($cookie->id_currency))))); Tools::safePostVars(); $css_files = array(__PS_BASE_URI__ . 'css/thickbox.css' => 'all'); $js_files = array(__PS_BASE_URI__ . 'js/jquery/thickbox-modified.js'); include_once dirname(__FILE__) . '/header.php'; $smarty->display(_PS_THEME_DIR_ . 'order-carrier.tpl'); }
public function hookextraCarrier($params) { global $smarty, $cart, $cookie, $defaultCountry, $nbcarriers; if (Configuration::get('MR_ENSEIGNE_WEBSERVICE') == '' || Configuration::get('MR_CODE_MARQUE') == '' || Configuration::get('MR_KEY_WEBSERVICE') == '' || Configuration::get('MR_LANGUAGE') == '') { return ''; } $address = new Address((int) $cart->id_address_delivery); $id_zone = Address::getZoneById((int) $address->id); $carriersList = self::_getCarriers(); // Check if the defined carrier are ok foreach ($carriersList as $k => $row) { $carrier = new Carrier((int) $row['id_carrier']); if ((Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false) || (!Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByPrice($id_zone) === false)) { unset($carriersList[$k]); } else { if ($row['range_behavior']) { // Get id zone $id_zone = (isset($cart->id_address_delivery) and $cart->id_address_delivery) ? Address::getZoneById((int) $cart->id_address_delivery) : (int) $defaultCountry->id_zone; if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, self::BOTH_WITHOUT_SHIPPING), $id_zone, $cart->id_currency)) { unset($carriersList[$k]); } } } } $preSelectedRelay = $this->getRelayPointSelected($params['cart']->id); $smarty->assign(array('one_page_checkout' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? Configuration::get('PS_ORDER_PROCESS_TYPE') : 0, 'new_base_dir' => self::$moduleURL, 'MRToken' => self::$MRFrontToken, 'carriersextra' => $carriersList, 'preSelectedRelay' => isset($preSelectedRelay['MR_selected_num']) ? $preSelectedRelay['MR_selected_num'] : '', 'jQueryOverload' => self::getJqueryCompatibility(false))); return $this->display(__FILE__, 'mondialrelay.tpl'); }
public function hookextraCarrier($params) { global $smarty, $cart, $cookie, $defaultCountry, $nbcarriers; if (Configuration::get('MR_ENSEIGNE_WEBSERVICE') == '' or Configuration::get('MR_CODE_MARQUE') == '' or Configuration::get('MR_KEY_WEBSERVICE') == '' or Configuration::get('MR_LANGUAGE') == '') { return ''; } $totalweight = Configuration::get('MR_WEIGHT_COEF') * $cart->getTotalWeight(); if (Validate::isUnsignedInt($cart->id_carrier)) { $carrier = new Carrier((int) $cart->id_carrier); if ($carrier->active and !$carrier->deleted) { $checked = (int) $cart->id_carrier; } } if (!isset($checked) or $checked == 0) { $checked = (int) Configuration::get('PS_CARRIER_DEFAULT'); } $address = new Address((int) $cart->id_address_delivery); $id_zone = Address::getZoneById((int) $address->id); $country = new Country((int) $address->id_country); $query = self::getmrth((int) $cookie->id_lang, true, (int) $country->id_zone, $country->iso_code); $resultsArray = array(); $i = 0; foreach ($query as $k => $row) { $carrier = new Carrier((int) $row['id_carrier']); 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 ($row['range_behavior']) { // Get id zone if (isset($cart->id_address_delivery) and $cart->id_address_delivery) { $id_zone = Address::getZoneById((int) $cart->id_address_delivery); } else { $id_zone = (int) $defaultCountry->id_zone; } if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, self::BOTH_WITHOUT_SHIPPING), $id_zone, $cart->id_currency)) { unset($result[$k]); continue; } } $settings = Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'mr_method` WHERE `id_carrier` = ' . (int) $row['id_carrier']); $row['name'] = $settings[0]['mr_Name']; $row['col'] = $settings[0]['mr_ModeCol']; $row['liv'] = $settings[0]['mr_ModeLiv']; $row['ass'] = $settings[0]['mr_ModeAss']; $row['price'] = $cart->getOrderShippingCost((int) $row['id_carrier']); $row['img'] = file_exists(_PS_SHIP_IMG_DIR_ . (int) $row['id_carrier'] . '.jpg') ? _THEME_SHIP_DIR_ . (int) $row['id_carrier'] . '.jpg' : ''; $resultsArray[] = $row; $i++; } if ($i > 0) { include_once _PS_MODULE_DIR_ . 'mondialrelay/page_iso.php'; $smarty->assign(array('address_map' => $address->address1 . ', ' . $address->postcode . ', ' . ote_accent($address->city) . ', ' . $country->iso_code, 'input_cp' => $address->postcode, 'input_ville' => ote_accent($address->city), 'input_pays' => $country->iso_code, 'input_poids' => Configuration::get('MR_WEIGHT_COEF') * $cart->getTotalWeight(), 'nbcarriers' => $nbcarriers, 'checked' => (int) $checked, 'google_api_key' => Configuration::get('MR_GOOGLE_MAP'), 'one_page_checkout' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? Configuration::get('PS_ORDER_PROCESS_TYPE') : 0, 'new_base_dir' => self::$moduleURL, 'carriersextra' => $resultsArray)); $nbcarriers = $nbcarriers + $i; return $this->display(__FILE__, 'mondialrelay.tpl'); } }
protected function _getCarrierList() { $address_delivery = new Address(self::$cart->id_address_delivery); if (self::$cookie->id_customer) { $customer = new Customer((int) self::$cookie->id_customer); $groups = $customer->getGroups(); } else { $groups = array(1); } if (!Address::isCountryActiveById((int) self::$cart->id_address_delivery)) { $this->errors[] = Tools::displayError('This address is not in a valid area.'); } elseif (!Validate::isLoadedObject($address_delivery) or $address_delivery->deleted) { $this->errors[] = Tools::displayError('This address is invalid.'); } else { $carriers = Carrier::getCarriersForOrder((int) Address::getZoneById((int) $address_delivery->id), $groups); $result = array('checked' => $this->_setDefaultCarrierSelection($carriers), 'carriers' => $carriers, 'HOOK_BEFORECARRIER' => Module::hookExec('beforeCarrier', array('carriers' => $carriers)), 'HOOK_EXTRACARRIER' => Module::hookExec('extraCarrier', array('address' => $address_delivery))); return $result; } if (sizeof($this->errors)) { return array('hasError' => true, 'errors' => $this->errors); } }
/** * 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); }
public function hookextraCarrier($params) { if (!MondialRelay::isAccountSet()) { return ''; } $carrier = false; $id_carrier = false; $id_mr_method = false; $preSelectedRelay = $this->getRelayPointSelected($params['cart']->id); $carriersList = MondialRelay::_getCarriers(); $address = new Address($this->context->cart->id_address_delivery); $id_zone = Address::getZoneById((int) $address->id); // Check if the defined carrier are ok foreach ($carriersList as $k => $row) { // For now works only with single shipping ! if (method_exists($params['cart'], 'carrierIsSelected')) { if ($params['cart']->carrierIsSelected($row['id_carrier'], $params['address']->id)) { $id_carrier = $row['id_carrier']; } } $carrier = new Carrier((int) $row['id_carrier']); if ((Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false) || (!Configuration::get('PS_SHIPPING_METHOD') and $carrier->getMaxDeliveryPriceByPrice($id_zone) === false)) { unset($carriersList[$k]); } else { if ($row['range_behavior']) { // Get id zone $id_zone = (isset($this->context->cart->id_address_delivery) and $this->context->cart->id_address_delivery) ? Address::getZoneById((int) $this->context->cart->id_address_delivery) : (int) $this->context->country->id_zone; if (Configuration::get('PS_SHIPPING_METHOD') && !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->context->cart->getTotalWeight(), $id_zone) || !Configuration::get('PS_SHIPPING_METHOD') && (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->context->cart->getOrderTotal(true, MondialRelay::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency) || !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->context->cart->getOrderTotal(true, MondialRelay::BOTH_WITHOUT_SHIPPING), $id_zone, $this->context->cart->id_currency))) { unset($carriersList[$k]); } } } } $carrier = MondialRelay::getMethodByIdCarrier($id_carrier); $this->context->smarty->assign(array('carriersextra' => $carriersList, 'preSelectedRelay' => isset($preSelectedRelay['MR_selected_num']) ? $preSelectedRelay['MR_selected_num'] : '', 'MR_carrier' => $carrier, 'MR_PS_VERSION' => _PS_VERSION_, 'MR_dlv_mode' => $id_carrier ? $carrier['dlv_mode'] : '')); return $this->fetchTemplate('/tpl/', 'checkout_process'); }
public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null) { global $defaultCountry; if (!Module::isInstalled('agilesellershipping') or !Module::isInstalled('agilemultipleseller')) { return parent::getPackageShippingCost($id_carrier, $use_tax, $default_country, $product_list, $id_zone); } $order_total = $this->getOrderTotal($use_tax, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING); if ($order_total <= 0 and !(int) self::getNbProducts($this->id)) { return 0; } include_once _PS_ROOT_DIR_ . "/modules/agilemultipleseller/agilemultipleseller.php"; include_once _PS_ROOT_DIR_ . "/modules/agilesellershipping/SellerShipping.php"; $sellers = AgileMultipleSeller::getSellersByCart($this->id); if (empty($sellers)) { return parent::getPackageShippingCost($id_carrier, $use_tax, $default_country, $product_list, $id_zone); } if (isset($this->id_address_delivery) and $this->id_address_delivery and Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) { $id_zone = Address::getZoneById((int) $this->id_address_delivery); } else { if (!Validate::isLoadedObject($defaultCountry)) { $defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT')); } $id_zone = (int) $defaultCountry->id_zone; } $shipping_cost = 0; foreach ($sellers as $seller) { $seller_cost = $this->getOrderShippingCostPerSeller($id_zone, intval($seller['id_seller']), $use_tax); $shipping_cost += $seller_cost; } return $shipping_cost; }
/** * Validate an order in database * Function called from a payment module * * @param integer $id_cart Value * @param integer $id_order_state Value * @param float $amountPaid Amount really paid by customer (in the default currency) * @param string $paymentMethod Payment method (eg. 'Credit cart') * @param string $message Message to attach to order */ function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false) { global $cart; $cart = new Cart(intval($id_cart)); // Does order already exists ? if (Validate::isLoadedObject($cart) and $cart->OrderExists() === 0) { // Copying data from cart $order = new Order(); $order->id_carrier = intval($cart->id_carrier); $order->id_customer = intval($cart->id_customer); $order->id_address_invoice = intval($cart->id_address_invoice); $order->id_address_delivery = intval($cart->id_address_delivery); $vat_address = new Address(intval($order->id_address_delivery)); $id_zone = Address::getZoneById(intval($vat_address->id)); $order->id_currency = $currency_special ? intval($currency_special) : intval($cart->id_currency); $order->id_lang = intval($cart->id_lang); $order->id_cart = intval($cart->id); $customer = new Customer(intval($order->id_customer)); $order->secure_key = pSQL($customer->secure_key); $order->payment = Tools::substr($paymentMethod, 0, 32); if (isset($this->name)) { $order->module = $this->name; } $order->recyclable = $cart->recyclable; $order->gift = intval($cart->gift); $order->gift_message = $cart->gift_message; $currency = new Currency($order->id_currency); $amountPaid = !$dont_touch_amount ? Tools::ps_round(floatval($amountPaid), 2) : $amountPaid; $order->total_paid_real = $amountPaid; $order->total_products = floatval($cart->getOrderTotal(false, 1)); $order->total_products_wt = floatval($cart->getOrderTotal(true, 1)); $order->total_discounts = floatval(abs($cart->getOrderTotal(true, 2))); $order->total_shipping = floatval($cart->getOrderShippingCost()); $order->total_wrapping = floatval(abs($cart->getOrderTotal(true, 6))); $order->total_paid = floatval(Tools::ps_round(floatval($cart->getOrderTotal(true, 3)), 2)); $order->invoice_date = '0000-00-00 00:00:00'; $order->delivery_date = '0000-00-00 00:00:00'; // Amount paid by customer is not the right one -> Status = payment error if ($order->total_paid != $order->total_paid_real) { $id_order_state = _PS_OS_ERROR_; } // Creating order if ($cart->OrderExists() === 0) { $result = $order->add(); } else { die(Tools::displayError('An order has already been placed using this cart')); } // Next ! if ($result and isset($order->id)) { // Optional message to attach to this order if (isset($message) and !empty($message)) { $msg = new Message(); $message = strip_tags($message, '<br>'); if (!Validate::isCleanHtml($message)) { $message = $this->l('Payment message is not valid, please check your module!'); } $msg->message = $message; $msg->id_order = intval($order->id); $msg->private = 1; $msg->add(); } // Insert products from cart into order_detail table $products = $cart->getProducts(); $productsList = ''; $db = Db::getInstance(); $query = 'INSERT INTO `' . _DB_PREFIX_ . 'order_detail` (`id_order`, `product_id`, `product_attribute_id`, `product_name`, `product_quantity`, `product_quantity_in_stock`, `product_price`, `reduction_percent`, `reduction_amount`, `product_quantity_discount`, `product_ean13`, `product_reference`, `product_supplier_reference`, `product_weight`, `tax_name`, `tax_rate`, `ecotax`, `discount_quantity_applied`, `download_deadline`, `download_hash`) VALUES '; $customizedDatas = Product::getAllCustomizedDatas(intval($order->id_cart)); Product::addCustomizationPrice($products, $customizedDatas); foreach ($products as $key => $product) { $outOfStock = false; $productQuantity = intval(Product::getQuantity(intval($product['id_product']), $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL)); $quantityInStock = $productQuantity - intval($product['cart_quantity']) < 0 ? $productQuantity : intval($product['cart_quantity']); if ($id_order_state != _PS_OS_CANCELED_ and $id_order_state != _PS_OS_ERROR_) { if (($updateResult = Product::updateQuantity($product)) === false or $updateResult === -1) { $outOfStock = true; } if (!$outOfStock) { $product['stock_quantity'] -= $product['cart_quantity']; } Hook::updateQuantity($product, $order); } $price = Product::getPriceStatic(intval($product['id_product']), false, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 6, NULL, false, true, $product['cart_quantity'], false, intval($order->id_customer), intval($order->id_cart), intval($order->id_address_delivery)); $price_wt = Product::getPriceStatic(intval($product['id_product']), true, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, 2, NULL, false, true, $product['cart_quantity'], false, intval($order->id_customer), intval($order->id_cart), intval($order->id_address_delivery)); // Add some informations for virtual products $deadline = '0000-00-00 00:00:00'; $download_hash = NULL; if ($id_product_download = ProductDownload::getIdFromIdProduct(intval($product['id_product']))) { $productDownload = new ProductDownload(intval($id_product_download)); $deadline = $productDownload->getDeadLine(); $download_hash = $productDownload->getHash(); } // Exclude VAT if (Tax::excludeTaxeOption()) { $product['tax'] = 0; $product['rate'] = 0; $tax = 0; } else { $tax = Tax::getApplicableTax(intval($product['id_tax']), floatval($product['rate']), intval($order->id_address_delivery)); } $currentDate = date('Y-m-d H:m:i'); if ($product['reduction_from'] != $product['reduction_to'] and ($currentDate > $product['reduction_to'] or $currentDate < $product['reduction_from'])) { $reduction_percent = 0.0; $reduction_amount = 0.0; } else { $reduction_percent = floatval($product['reduction_percent']); $reduction_amount = Tools::ps_round(floatval($product['reduction_price']) / (1 + floatval($tax) / 100), 6); } // Quantity discount $reduc = 0.0; if ($product['cart_quantity'] > 1 and $qtyD = QuantityDiscount::getDiscountFromQuantity($product['id_product'], $product['cart_quantity'])) { $reduc = QuantityDiscount::getValue($price_wt, $qtyD->id_discount_type, $qtyD->value, new Currency(intval($order->id_currency))); } $query .= '(' . intval($order->id) . ', ' . intval($product['id_product']) . ', ' . (isset($product['id_product_attribute']) ? intval($product['id_product_attribute']) : 'NULL') . ', \'' . pSQL($product['name'] . ((isset($product['attributes']) and $product['attributes'] != NULL) ? ' - ' . $product['attributes'] : '')) . '\', ' . intval($product['cart_quantity']) . ', ' . $quantityInStock . ', ' . floatval(Product::getPriceStatic(intval($product['id_product']), false, $product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL, Product::getTaxCalculationMethod(intval($order->id_customer)) == PS_TAX_EXC ? 2 : 6, NULL, false, false, $product['cart_quantity'], false, intval($order->id_customer), intval($order->id_cart), intval($order->id_address_delivery))) . ', ' . floatval($reduction_percent) . ', ' . floatval($reduction_amount) . ', ' . floatval($reduc) . ', ' . (empty($product['ean13']) ? 'NULL' : '\'' . pSQL($product['ean13']) . '\'') . ', ' . (empty($product['reference']) ? 'NULL' : '\'' . pSQL($product['reference']) . '\'') . ', ' . (empty($product['supplier_reference']) ? 'NULL' : '\'' . pSQL($product['supplier_reference']) . '\'') . ', ' . floatval($product['id_product_attribute'] ? $product['weight_attribute'] : $product['weight']) . ', \'' . (!$tax ? '' : pSQL($product['tax'])) . '\', ' . floatval($tax) . ', ' . floatval($product['ecotax']) . ', ' . (int) QuantityDiscount::getDiscountFromQuantity(intval($product['id_product']), intval($product['cart_quantity'])) . ', \'' . pSQL($deadline) . '\', \'' . pSQL($download_hash) . '\'),'; $priceWithTax = number_format($price * (($tax + 100) / 100), 2, '.', ''); $customizationQuantity = 0; if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']])) { $customizationText = ''; foreach ($customizedDatas[$product['id_product']][$product['id_product_attribute']] as $customization) { if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_])) { foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] as $text) { $customizationText .= $text['name'] . $this->l(':') . ' ' . $text['value'] . ', '; } } } $customizationText = rtrim($customizationText, ', '); $customizationQuantity = intval($product['customizationQuantityTotal']); $productsList .= '<tr style="background-color: ' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding: 0.6em 0.4em;">' . $product['reference'] . '</td> <td style="padding: 0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . ' - ' . $this->l('Customized') . (!empty($customizationText) ? ' - ' . $customizationText : '') . '</strong></td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt, $currency, false, false) . '</td> <td style="padding: 0.6em 0.4em; text-align: center;">' . $customizationQuantity . '</td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice($customizationQuantity * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false, false) . '</td> </tr>'; } if (!$customizationQuantity or intval($product['cart_quantity']) > $customizationQuantity) { $productsList .= '<tr style="background-color: ' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding: 0.6em 0.4em;">' . $product['reference'] . '</td> <td style="padding: 0.6em 0.4em;"><strong>' . $product['name'] . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . '</strong></td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt, $currency, false, false) . '</td> <td style="padding: 0.6em 0.4em; text-align: center;">' . (intval($product['cart_quantity']) - $customizationQuantity) . '</td> <td style="padding: 0.6em 0.4em; text-align: right;">' . Tools::displayPrice((intval($product['cart_quantity']) - $customizationQuantity) * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false, false) . '</td> </tr>'; } } // end foreach ($products) $query = rtrim($query, ','); $result = $db->Execute($query); // Insert discounts from cart into order_discount table $discounts = $cart->getDiscounts(); $discountsList = ''; foreach ($discounts as $discount) { $objDiscount = new Discount(intval($discount['id_discount'])); $value = $objDiscount->getValue(sizeof($discounts), $cart->getOrderTotal(true, 1), $order->total_shipping, $cart->id); $order->addDiscount($objDiscount->id, $objDiscount->name, $value); if ($id_order_state != _PS_OS_ERROR_ and $id_order_state != _PS_OS_CANCELED_) { $objDiscount->quantity = $objDiscount->quantity - 1; } $objDiscount->update(); $discountsList .= '<tr style="background-color:#EBECEE;"> <td colspan="4" style="padding: 0.6em 0.4em; text-align: right;">' . $this->l('Voucher code:') . ' ' . $objDiscount->name . '</td> <td style="padding: 0.6em 0.4em; text-align: right;">-' . Tools::displayPrice($value, $currency, false, false) . '</td> </tr>'; } // Specify order id for message $oldMessage = Message::getMessageByCartId(intval($cart->id)); if ($oldMessage) { $message = new Message(intval($oldMessage['id_message'])); $message->id_order = intval($order->id); $message->update(); } // Hook new order $orderStatus = new OrderState(intval($id_order_state)); if (Validate::isLoadedObject($orderStatus)) { Hook::newOrder($cart, $order, $customer, $currency, $orderStatus); foreach ($cart->getProducts() as $product) { if ($orderStatus->logable) { ProductSale::addProductSale(intval($product['id_product']), intval($product['cart_quantity'])); } } } if (isset($outOfStock) and $outOfStock) { $history = new OrderHistory(); $history->id_order = intval($order->id); $history->changeIdOrderState(_PS_OS_OUTOFSTOCK_, intval($order->id)); $history->addWithemail(); } // Set order state in order history ONLY even if the "out of stock" status has not been yet reached // So you migth have two order states $new_history = new OrderHistory(); $new_history->id_order = intval($order->id); $new_history->changeIdOrderState(intval($id_order_state), intval($order->id)); $new_history->addWithemail(true, $extraVars); // Send an e-mail to customer if ($id_order_state != _PS_OS_ERROR_ and $id_order_state != _PS_OS_CANCELED_ and $customer->id) { $invoice = new Address(intval($order->id_address_invoice)); $delivery = new Address(intval($order->id_address_delivery)); $carrier = new Carrier(intval($order->id_carrier)); $delivery_state = $delivery->id_state ? new State(intval($delivery->id_state)) : false; $invoice_state = $invoice->id_state ? new State(intval($invoice->id_state)) : false; $data = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone, '{invoice_other}' => $invoice->other, '{order_name}' => sprintf("#%06d", intval($order->id)), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), intval($order->id_lang), 1), '{carrier}' => strval($carrier->name) != '0' ? $carrier->name : Configuration::get('PS_SHOP_NAME'), '{payment}' => $order->payment, '{products}' => $productsList, '{discounts}' => $discountsList, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $currency, false, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false, false)); if (is_array($extraVars)) { $data = array_merge($data, $extraVars); } // Join PDF invoice if (intval(Configuration::get('PS_INVOICE')) and Validate::isLoadedObject($orderStatus) and $orderStatus->invoice and $order->invoice_number) { $fileAttachment['content'] = PDF::invoice($order, 'S'); $fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', intval($order->id_lang)) . sprintf('%06d', $order->invoice_number) . '.pdf'; $fileAttachment['mime'] = 'application/pdf'; } else { $fileAttachment = NULL; } if ($orderStatus->send_email and Validate::isEmail($customer->email)) { Mail::Send(intval($order->id_lang), 'order_conf', 'Order confirmation', $data, $customer->email, $customer->firstname . ' ' . $customer->lastname, NULL, NULL, $fileAttachment); } $this->currentOrder = intval($order->id); return true; } $this->currentOrder = intval($order->id); return true; } else { die(Tools::displayError('Order creation failed')); } } else { die(Tools::displayError('An order has already been placed using this cart')); } }
public static function get_seller_sales_from_cart($id_cart, $include_shppingcost = true, $after_discounts = false, $include_tax = true) { $uaqhymrtjtx = "product"; ${"GLOBALS"}["eyqzktf"] = "seller_sales_amount"; ${"GLOBALS"}["teitwlrl"] = "seller_sales_amount"; ${${"GLOBALS"}["esvngpfotb"]} = new Cart(${${"GLOBALS"}["frpscuel"]}); if (!Validate::isLoadedObject(${${"GLOBALS"}["esvngpfotb"]})) { return; } ${${"GLOBALS"}["teitwlrl"]} = array(); ${${"GLOBALS"}["vgnwuvdfsxef"]} = 0; foreach ($theCart->getProducts() as ${${"GLOBALS"}["uhwljodynle"]} => ${$uaqhymrtjtx}) { ${"GLOBALS"}["acnijoxrqy"] = "id_owner"; ${${"GLOBALS"}["qdndcj"]} = intval(AgileSellerManager::getObjectOwnerID("product", ${${"GLOBALS"}["cloygkl"]}["id_product"])); if (!isset(${${"GLOBALS"}["xiinmwl"]}[${${"GLOBALS"}["qdndcj"]}])) { ${${"GLOBALS"}["xiinmwl"]}[${${"GLOBALS"}["acnijoxrqy"]}] = 0; } ${"GLOBALS"}["uqojbaqsiz"] = "id_owner"; if (${${"GLOBALS"}["vckxyex"]}) { $zbnxgflvgb = "lineamount"; ${$zbnxgflvgb} = ${${"GLOBALS"}["cloygkl"]}["total_wt"]; } else { ${${"GLOBALS"}["xxkdmsnb"]} = ${${"GLOBALS"}["cloygkl"]}["total"]; } ${${"GLOBALS"}["xiinmwl"]}[${${"GLOBALS"}["qdndcj"]}] += ${${"GLOBALS"}["xxkdmsnb"]}; ${${"GLOBALS"}["vgnwuvdfsxef"]} += ${${"GLOBALS"}["xxkdmsnb"]}; self::log_message("seller_sales_amount=" . ${${"GLOBALS"}["xiinmwl"]}[${${"GLOBALS"}["uqojbaqsiz"]}]); } if (${${"GLOBALS"}["vgnwuvdfsxef"]} == 0) { return ${${"GLOBALS"}["eyqzktf"]}; } ${${"GLOBALS"}["jkqbidncw"]} = abs($theCart->getOrderTotal(true, CART::ONLY_DISCOUNTS)); ${"GLOBALS"}["leuhuri"] = "include_tax"; $wbpixfqq = "total_shipping"; $hszxeuoysyqb = "seller_sales_amount"; if (${${"GLOBALS"}["mnciypinfgc"]} and ${${"GLOBALS"}["jkqbidncw"]} > 0) { foreach (${${"GLOBALS"}["xiinmwl"]} as ${${"GLOBALS"}["uhwljodynle"]} => ${${"GLOBALS"}["oktrbptlq"]}) { $dtpouqmcs = "seller_discount"; ${"GLOBALS"}["fnnrgrqqtjav"] = "amount"; $dmncdfpm = "amount"; ${$dtpouqmcs} = ${$dmncdfpm} * ${${"GLOBALS"}["jkqbidncw"]} / ${${"GLOBALS"}["vgnwuvdfsxef"]}; $ebwribgtkx = "seller_discount"; $njucvdl = "seller_sales_amount"; ${$njucvdl}[${${"GLOBALS"}["uhwljodynle"]}] = Tools::ps_round(${${"GLOBALS"}["fnnrgrqqtjav"]} - ${$ebwribgtkx}, 2); } } ${${"GLOBALS"}["xokzcouuhc"]} = floatval($theCart->getOrderTotal(${${"GLOBALS"}["leuhuri"]}, Cart::ONLY_SHIPPING)) + floatval($theCart->getOrderTotal(${${"GLOBALS"}["vckxyex"]}, Cart::ONLY_WRAPPING)); if (${${"GLOBALS"}["qxkibmpljxt"]} and ${$wbpixfqq} > 0) { $tymywmbyl = "id_zone"; ${"GLOBALS"}["lnmqfsnuf"] = "seller_sales_amount"; if (isset($theCart->id_address_delivery) and $theCart->id_address_delivery and Customer::customerHasAddress($theCart->id_customer, $theCart->id_address_delivery)) { ${$tymywmbyl} = Address::getZoneById((int) $theCart->id_address_delivery); } else { ${${"GLOBALS"}["jnnsdlrv"]} = new Country(Configuration::get("PS_COUNTRY_DEFAULT"), Configuration::get("PS_LANG_DEFAULT")); ${${"GLOBALS"}["lgkbdx"]} = (int) $defaultCountry->id_zone; } foreach (${${"GLOBALS"}["lnmqfsnuf"]} as ${${"GLOBALS"}["uhwljodynle"]} => ${${"GLOBALS"}["oktrbptlq"]}) { if (Module::isInstalled("agilesellershipping")) { $xiywykxt = "key"; ${"GLOBALS"}["vylrbmxbekw"] = "shipping"; ${${"GLOBALS"}["vylrbmxbekw"]} = $theCart->getOrderShippingCostPerSeller(${${"GLOBALS"}["lgkbdx"]}, ${$xiywykxt}, ${${"GLOBALS"}["vckxyex"]}); } else { $adrgkkd = "shipping"; ${"GLOBALS"}["yksuovho"] = "amount"; ${$adrgkkd} = ${${"GLOBALS"}["yksuovho"]} * ${${"GLOBALS"}["xokzcouuhc"]} / ${${"GLOBALS"}["vgnwuvdfsxef"]}; } $yiahovnnapvj = "seller_sales_amount"; ${$yiahovnnapvj}[${${"GLOBALS"}["uhwljodynle"]}] = Tools::ps_round(${${"GLOBALS"}["oktrbptlq"]} + ${${"GLOBALS"}["oglsjlnajq"]}, 2); } } return ${$hszxeuoysyqb}; }
/** * 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'); } }
/** * 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((int) $id_discount['id_discount']); if (sizeof($categories)) { foreach ($products as $product) { if (Product::idIsOnCategoryId((int) $product['id_product'], $categories)) { $total_cart += $product['total_wt']; } } } if ($total_cart >= $id_discount['minimal']) { return 0; } } else { return 0; } } } } // Order total in default currency without fees $order_total = $this->getOrderTotal(true, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING); // Start with shipping cost at 0 $shipping_cost = 0; // If no product added, return 0 if ($order_total <= 0 and !(int) self::getNbProducts($this->id)) { return $shipping_cost; } // Get id zone if (isset($this->id_address_delivery) and $this->id_address_delivery and Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) { $id_zone = Address::getZoneById((int) $this->id_address_delivery); } else { // This method can be called from the backend, and $defaultCountry won't be defined if (!Validate::isLoadedObject($defaultCountry)) { $defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT')); } $id_zone = (int) $defaultCountry->id_zone; } // If no carrier, select default one if (!$id_carrier) { $id_carrier = $this->id_carrier; } if ($id_carrier && !$this->isCarrierInRange($id_carrier, $id_zone)) { $id_carrier = ''; } 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 ((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()); unset($customer); } else { $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone); } 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((int) $row['id_carrier']); } $carrier = self::$_carriers[$row['id_carrier']]; // Get only carriers that are compliant with shipping method if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false or $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE 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 ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT and !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), $id_zone) or $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE and !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, (int) $this->id_currency)) { unset($result[$k]); continue; } } if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone); } else { $shipping = $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency); } if (!isset($minShippingPrice)) { $minShippingPrice = $shipping; } if ($shipping <= $minShippingPrice) { $id_carrier = (int) $row['id_carrier']; $minShippingPrice = $shipping; } } } if (empty($id_carrier)) { $id_carrier = Configuration::get('PS_CARRIER_DEFAULT'); } 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) { return $shipping_cost; } // Free fees if free carrier if ($carrier->is_free == 1) { return 0; } // Select carrier tax if ($useTax and !Tax::excludeTaxeOption()) { $carrierTax = Tax::getCarrierTaxRate((int) $carrier->id, (int) $this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); } $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((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency)); } $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING); if ($orderTotalwithDiscounts >= (double) $free_fees_price and (double) $free_fees_price > 0) { return $shipping_cost; } if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) and $this->getTotalWeight() >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] and (double) $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 and Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) { $id_zone = Address::getZoneById((int) $this->id_address_delivery); } else { $id_zone = (int) $defaultCountry->id_zone; } if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT and !Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), $id_zone) or $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE and !Carrier::checkDeliveryPriceByPrice($carrier->id, $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, (int) $this->id_currency)) { $shipping_cost += 0; } else { if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone); } else { // by price $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency); } } } else { if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone); } else { $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency); } } // Adding handling charges if (isset($configuration['PS_SHIPPING_HANDLING']) and $carrier->shipping_handling) { $shipping_cost += (double) $configuration['PS_SHIPPING_HANDLING']; } // Additional Shipping Cost per product foreach ($products as $product) { $shipping_cost += $product['additional_shipping_cost'] * $product['cart_quantity']; } $shipping_cost = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int) $this->id_currency)); //get external shipping cost from module if ($carrier->shipping_external) { $moduleName = $carrier->external_module_name; $module = Module::getInstanceByName($moduleName); if (Validate::isLoadedObject($module)) { if (array_key_exists('id_carrier', $module)) { $module->id_carrier = $carrier->id; } if ($carrier->need_range) { $shipping_cost = $module->getOrderShippingCost($this, $shipping_cost); } else { $shipping_cost = $module->getOrderShippingCostExternal($this); } // Check if carrier is available if ($shipping_cost === false) { return false; } } else { return false; } } // Apply tax if (isset($carrierTax)) { $shipping_cost *= 1 + $carrierTax / 100; } return (double) Tools::ps_round((double) $shipping_cost, 2); }
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()); $checked = 0; if (Validate::isUnsignedInt(self::$cart->id_carrier) and self::$cart->id_carrier) { $carrier = new Carrier((int) self::$cart->id_carrier); if ($carrier->active and !$carrier->deleted) { $checked = (int) self::$cart->id_carrier; } } self::$smarty->assign(array('checked' => (int) $checked, 'carriers' => $carriers, 'default_carrier' => (int) Configuration::get('PS_CARRIER_DEFAULT'), 'HOOK_EXTRACARRIER' => Module::hookExec('extraCarrier', array('address' => $address)), 'HOOK_BEFORECARRIER' => Module::hookExec('beforeCarrier', array('carriers' => $carriers)))); }
/** * For a given {product, warehouse}, gets the carrier available * * @since 1.5.0 * @param Product $product The id of the product, or an array with at least the package size and weight * @return array */ public static function getAvailableCarrierList(Product $product, $id_warehouse, $id_address_delivery = null, $id_shop = null, $cart = null) { if (is_null($id_shop)) { $id_shop = Context::getContext()->shop->id; } if (is_null($cart)) { $cart = Context::getContext()->cart; } $id_address = (int) (!is_null($id_address_delivery) && $id_address_delivery != 0 ? $id_address_delivery : $cart->id_address_delivery); if ($id_address) { $address = new Address($id_address); $id_zone = Address::getZoneById($address->id); // Check the country of the address is activated if (!Address::isCountryActiveById($address->id)) { return array(); } } else { $country = new Country(Configuration::get('PS_COUNTRY_DEFAULT')); $id_zone = $country->id_zone; } // Does the product is linked with carriers? $query = new DbQuery(); $query->select('id_carrier'); $query->from('product_carrier', 'pc'); $query->innerJoin('carrier', 'c', 'c.id_reference = pc.id_carrier_reference AND c.deleted = 0'); $query->where('pc.id_product = ' . (int) $product->id); $query->where('pc.id_shop = ' . (int) $id_shop); $carriers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); if (!empty($carriers)) { //the product is linked with carriers $carrier_list = array(); foreach ($carriers as $carrier) { //check if the linked carriers are available in current zone if (Carrier::checkCarrierZone($carrier['id_carrier'], $id_zone)) { $carrier_list[] = $carrier['id_carrier']; } } if (!empty($carrier_list)) { return $carrier_list; } else { return array(); } //no linked carrier are available for this zone } $carrier_list = array(); // The product is not dirrectly linked with a carrier // Get all the carriers linked to a warehouse if ($id_warehouse) { $warehouse = new Warehouse($id_warehouse); $warehouse_carrier_list = $warehouse->getCarriers(); } $available_carrier_list = array(); $customer = new Customer($cart->id_customer); $carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups(), $cart); foreach ($carriers as $carrier) { $available_carrier_list[] = $carrier['id_carrier']; } if (empty($warehouse_carrier_list)) { $carrier_list = $available_carrier_list; } else { $carrier_list = array_intersect($warehouse_carrier_list, $available_carrier_list); } if ($product->width > 0 || $product->height > 0 || $product->depth > 0 || $product->weight > 0) { foreach ($carrier_list as $key => $id_carrier) { $carrier = new Carrier($id_carrier); if ($carrier->max_width > 0 && $carrier->max_width < $product->width || $carrier->max_height > 0 && $carrier->max_height < $product->height || $carrier->max_depth > 0 && $carrier->max_depth < $product->depth || $carrier->max_weight > 0 && $carrier->max_weight < $product->weight) { unset($carrier_list[$key]); } } } return $carrier_list; }
/** ** Affiche le transporteur Dejala.com dans la liste des transporteurs sur le Front Office */ public function hookExtraCarrier($params) { global $smarty, $defaultCountry; $cart = $params['cart']; $cookie = $params['cookie']; $this->hooklog("ExtraCarrier", $params); // Check if Dejala should be visible if ($this->dejalaConfig->visibility_status == "invisible") { return; } if ($this->dejalaConfig->visibility_status == "visible_limited" && (int) $cookie->id_customer > 0) { $customer = new Customer((int) $cookie->id_customer); if (!in_array($customer->email, preg_split("/[\\s,]+/", $this->dejalaConfig->visible_users_list))) { return; } } $djlUtil = new DejalaUtils(); $responseGetStore = $djlUtil->getStoreAttributes($this->dejalaConfig, $store); if ($responseGetStore['status'] != '200') { return; } $isCartOutOfStock = '0'; if ($this->isCartOutOfStock($cart)) { $isCartOutOfStock = '1'; } $this->mylog('isCartOutOfStock=' . $isCartOutOfStock . ''); $acceptPartial = true; if (!isset($store['attributes']) || !isset($store['attributes']['delivery_partial']) || $store['attributes']['delivery_partial'] != '1') { $acceptPartial = false; } if ($isCartOutOfStock == '1' && !$acceptPartial) { return; } $electedProduct = $this->getDejalaProduct($cart); // Get id zone if (isset($cart->id_address_delivery) and $cart->id_address_delivery) { $id_zone = (int) Address::getZoneById((int) $cart->id_address_delivery); } else { $id_zone = (int) $defaultCountry->id_zone; } $djlCarrier = DejalaCarrierUtils::getCarrierByName($this->name); $this->mylog("electedCarrier=" . $this->logValue($djlCarrier, 1)); if ($djlCarrier == null) { return null; } // Calcul des dates dispo $productCalendar = $electedProduct['calendar']['entries']; // MFR090831 - add picking time : the store is open to (stop_hour - picking time), it is more natural to merchants to set opening hours instead of dejala delivery time if ($electedProduct['pickingtime']) { $pickingtime = (int) $electedProduct['pickingtime']; } else { $pickingtime = $electedProduct['timelimit']; } $djlUtil = new DejalaUtils(); $storeCalendar = array(); $calendar = array(); $response = $djlUtil->getStoreCalendar($this->dejalaConfig, $storeCalendar); $this->mylog("productCalendar=" . $this->logValue($productCalendar, 1)); $this->mylog("storeCalendar=" . $this->logValue($storeCalendar, 1)); $this->mylog("response['status']=" . $response['status']); if ($response['status'] == 200) { foreach ($storeCalendar['entries'] as $weekday => $calEntry) { if (isset($productCalendar[$weekday])) { $calendar[$weekday]["weekday"] = $weekday; $calendar[$weekday]["start_hour"] = max((int) $productCalendar[$weekday]["start_hour"], (int) $calEntry["start_hour"]); // MFR090831 - manage picking time : the store is open to (stop_hour - picking time) $calendar[$weekday]["stop_hour"] = min((int) ($productCalendar[$weekday]["stop_hour"] - 1), (int) ($calEntry["stop_hour"] - $pickingtime)); if ($calendar[$weekday]["stop_hour"] < $calendar[$weekday]["start_hour"]) { unset($calendar[$weekday]); } } } } // Calcul de la date de démarrage pour les créneaux : // Avancement jusque jour dispo & ouvert // Ajout du temps de préparation : 0.5 jour ou 1 nb de jours // Ajustement de l'heure sur l'ouverture ou l'heure suivante xxh00 $deliveryDelay = $store['attributes']['delivery_delay']; $skipCurDay = false; $calUtils = new CalendarUtils(); $all_exceptions = array_merge($storeCalendar['exceptions'], $electedProduct['calendar']['exceptions']); $dateUtc = $calUtils->getNextDateAvailable(time(), $calendar, $all_exceptions); if ($dateUtc == NULL) { return; } if ($deliveryDelay > 0) { if ($skipCurDay) { $dateUtc = $calUtils->skipCurDay($dateUtc); } $dateUtc = $calUtils->addDelay($dateUtc, $deliveryDelay, $calendar, $all_exceptions); } if ($dateUtc == NULL) { return; } $dateUtc = $calUtils->adjustHour($dateUtc, $calendar); $this->mylog("calendar=" . $this->logValue($calendar, 1)); $this->mylog("starting date=" . $this->logValue(date("d/m/Y - H:i:s", $dateUtc), 1)); $today = getDate(); $ctime = time(); $nbDeliveryDates = $deliveryDelay = $store['attributes']['nb_days_displayed']; $iDate = 0; $dates = array(); $balladUtc = $dateUtc; do { $wd = date("w", $balladUtc); if ((int) $calendar[$wd]['stop_hour'] < (int) $calendar[$wd]['start_hour']) { continue; } $dates[$iDate]['value'] = date("Y/m/d", $balladUtc); $dates[$iDate]['ts'] = $balladUtc; $dates[$iDate]['label'] = $this->wday_labels[$wd] . " " . date("j", $balladUtc); $dates[$iDate]['start_hour'] = (int) $calendar[$wd]['start_hour']; $dates[$iDate]['stop_hour'] = (int) $calendar[$wd]['stop_hour']; $balladUtc = strtotime(date("Y-m-d", $balladUtc) . " +1 day"); $balladUtc = mktime(0, 0, 0, date('m', $balladUtc), date('d', $balladUtc), date('Y', $balladUtc)); $balladUtc = $calUtils->getNextDateAvailable($balladUtc, $calendar, $all_exceptions); $iDate++; } while ($iDate < $nbDeliveryDates && $balladUtc); // impossibilité de trouver un jour dispo if (!isset($dates[0])) { return; } $now = (int) date("H", $ctime); if ((int) $dates[0]['stop_hour'] > $now && (int) $dates[0]['start_hour'] < $now) { $dates[0]['start_hour'] = $now; } elseif ((int) $dates[0]['ts'] == $now && (int) $dates[0]['stop_hour'] < $now) { array_shift($dates); } $this->mylog("date\$=" . $this->logValue($dates, 1)); $smarty->assign('nb_days', $nbDeliveryDates); $smarty->assign('dates', $dates); for ($i = 0; $i < 24; $i++) { $endHour = ($i + $electedProduct['timelimit']) % 24; if ($endHour == 0) { $endHour = 24; } $hourLabels[] = $i . 'h-' . $endHour . 'h'; } $smarty->assign('hourLabels', $hourLabels); $smarty->assign('timetable_css', _MODULE_DIR_ . $this->name . '/timetable.css'); $smarty->assign("timetable_js", _MODULE_DIR_ . $this->name . '/timetable.js'); $this->mylog("electedCarrier->id=" . $this->logValue($djlCarrier->id)); $mCarrier = $djlCarrier; $row['id_carrier'] = (int) $djlCarrier->id; $row['name'] = $this->l('Dejala.com'); $row['delay'] = $this->l('When you want... Dispatch rider') . ', ' . $electedProduct['timelimit'] . 'H'; $row['price'] = $cart->getOrderShippingCost($djlCarrier->id); $row['price_tax_exc'] = $cart->getOrderShippingCost($djlCarrier->id, false); $row['img'] = _MODULE_DIR_ . $this->name . '/dejala_carrier.gif'; $resultsArray[] = $row; $smarty->assign('carriers', $resultsArray); $smarty->assign('my_carrier_selected', isset($cart->id_carrier) && $cart->id_carrier == $djlCarrier->id); $smarty->assign('product', $electedProduct); $djlCart = new DejalaCart($cart->id); $setDefaultDate = TRUE; if ($djlCart && isset($djlCart->shipping_date) && !empty($djlCart->shipping_date)) { $mShippingDate = $djlCart->shipping_date; $this->mylog("shipping_date=" . $this->logValue($mShippingDate)); $m_day = date("d", $mShippingDate); $m_hour = date("H", $mShippingDate); $deliveryDateSelected = date("Y/m/d", $mShippingDate); $this->mylog("shipping_date=" . $this->logValue($deliveryDateSelected)); foreach ($dates as $l_key => $l_date) { if ($l_date['value'] == $deliveryDateSelected) { $smarty->assign("deliveryDateIndexSelected", $l_key); $smarty->assign("deliveryDateSelected", $deliveryDateSelected); $smarty->assign("deliveryHourSelected", $m_hour); $setDefaultDate = FALSE; } } } if ($setDefaultDate) { $smarty->assign("deliveryDateIndexSelected", 0); $smarty->assign("deliveryDateSelected", date("Y/m/d", $dateUtc)); $smarty->assign("deliveryHourSelected", (int) date("H", $dateUtc)); } $smarty->assign("isCartOutOfStock", $isCartOutOfStock); if (!$isCartOutOfStock) { $buffer = $this->display(__FILE__, 'dejala_carrier.tpl'); $buffer = $buffer . $this->display(__FILE__, 'dejala_timetable.tpl'); } else { $smarty->assign('nostock_info', $this->l('I will select my shipping date when my product is available.')); $buffer = $this->display(__FILE__, 'dejala_carrier_nostock.tpl'); } return $buffer; }
public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null) { if (!Configuration::get('LEGAL_SHIPTAXMETH')) { return parent::getPackageShippingCost($id_carrier, $use_tax, $default_country, $product_list, $id_zone); } if ($this->isVirtualCart()) { return 0; } if (!$default_country) { $default_country = Context::getContext()->country; } if (!is_null($product_list)) { foreach ($product_list as $key => $value) { if ($value['is_virtual'] == 1) { unset($product_list[$key]); } } } $complete_product_list = $this->getProducts(); if (is_null($product_list)) { $products = $complete_product_list; } else { $products = $product_list; } if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') { $address_id = (int) $this->id_address_invoice; } elseif (count($product_list)) { $prod = current($product_list); $address_id = (int) $prod['id_address_delivery']; } else { $address_id = null; } if (!Address::addressExists($address_id)) { $address_id = null; } $cache_id = 'getPackageShippingCost_' . (int) $this->id . '_' . (int) $address_id . '_' . (int) $id_carrier . '_' . (int) $use_tax . '_' . (int) $default_country->id; if ($products) { foreach ($products as $product) { $cache_id .= '_' . (int) $product['id_product'] . '_' . (int) $product['id_product_attribute']; } } if (Cache::isStored($cache_id)) { return Cache::retrieve($cache_id); } // Order total in default currency without fees $order_total = $this->getOrderTotal(true, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING, $product_list); // Start with shipping cost at 0 $shipping_cost = 0; // If no product added, return 0 if (!count($products)) { Cache::store($cache_id, $shipping_cost); return $shipping_cost; } if (!isset($id_zone)) { // Get id zone if (!$this->isMultiAddressDelivery() && 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); } else { if (!Validate::isLoadedObject($default_country)) { $default_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT')); } $id_zone = (int) $default_country->id_zone; } } if ($id_carrier && !$this->isCarrierInRange((int) $id_carrier, (int) $id_zone)) { $id_carrier = ''; } if (empty($id_carrier) && $this->isCarrierInRange((int) Configuration::get('PS_CARRIER_DEFAULT'), (int) $id_zone)) { $id_carrier = (int) Configuration::get('PS_CARRIER_DEFAULT'); } $total_package_without_shipping_tax_inc = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list); 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()); unset($customer); } else { $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone); } 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((int) $row['id_carrier']); } $carrier = self::$_carriers[$row['id_carrier']]; // Get only carriers that are compliant with shipping method if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight((int) $id_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice((int) $id_zone) === false) { unset($result[$k]); continue; } // If out-of-range behavior carrier is set on "Desactivate carrier" if ($row['range_behavior']) { $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), (int) $id_zone); $total_order = $total_package_without_shipping_tax_inc; $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $total_order, (int) $id_zone, (int) $this->id_currency); // Get only carriers that have a range compatible with cart if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) { unset($result[$k]); continue; } } if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), (int) $id_zone); } else { $shipping = $carrier->getDeliveryPriceByPrice($order_total, (int) $id_zone, (int) $this->id_currency); } if (!isset($min_shipping_price)) { $min_shipping_price = $shipping; } if ($shipping <= $min_shipping_price) { $id_carrier = (int) $row['id_carrier']; $min_shipping_price = $shipping; } } } if (empty($id_carrier)) { $id_carrier = Configuration::get('PS_CARRIER_DEFAULT'); } 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]; // No valid Carrier or $id_carrier <= 0 ? if (!Validate::isLoadedObject($carrier)) { Cache::store($cache_id, 0); return 0; } if (!$carrier->active) { Cache::store($cache_id, $shipping_cost); return $shipping_cost; } // Free fees if free carrier if ($carrier->is_free == 1) { Cache::store($cache_id, 0); return 0; } // Select carrier tax if ($use_tax && !Tax::excludeTaxeOption()) { $address = Address::initialize((int) $address_id); $carrier_tax = $carrier->getTaxesRate($address); } $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((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency)); } $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, null, null, false); if ($orderTotalwithDiscounts >= (double) $free_fees_price && (double) $free_fees_price > 0) { Cache::store($cache_id, $shipping_cost); return $shipping_cost; } if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $this->getTotalWeight() >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] && (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) { Cache::store($cache_id, $shipping_cost); return $shipping_cost; } // Get shipping cost using correct method if ($carrier->range_behavior) { if (!isset($id_zone)) { // Get id zone 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); } else { $id_zone = (int) $default_country->id_zone; } } if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), (int) $id_zone) || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !Carrier::checkDeliveryPriceByPrice($carrier->id, $total_package_without_shipping_tax_inc, $id_zone, (int) $this->id_currency)) { $shipping_cost += 0; } else { if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone); } else { // by price $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency); } } } else { if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone); } else { $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 += (double) $configuration['PS_SHIPPING_HANDLING']; } // Additional Shipping Cost per product foreach ($products as $product) { if (!$product['is_virtual']) { $shipping_cost += $product['additional_shipping_cost'] * $product['cart_quantity']; } } $shipping_cost = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int) $this->id_currency)); //get external shipping cost from module if ($carrier->shipping_external) { $module_name = $carrier->external_module_name; $module = Module::getInstanceByName($module_name); if (Validate::isLoadedObject($module)) { if (array_key_exists('id_carrier', $module)) { $module->id_carrier = $carrier->id; } if ($carrier->need_range) { if (method_exists($module, 'getPackageShippingCost')) { $shipping_cost = $module->getPackageShippingCost($this, $shipping_cost, $products); } else { $shipping_cost = $module->getOrderShippingCost($this, $shipping_cost); } } else { $shipping_cost = $module->getOrderShippingCostExternal($this); } // Check if carrier is available if ($shipping_cost === false) { Cache::store($cache_id, false); return false; } } else { Cache::store($cache_id, false); return false; } } $shipping_cost = (double) Tools::ps_round((double) $shipping_cost, 2); Cache::store($cache_id, $shipping_cost); return $shipping_cost; }
/** * Return package shipping cost * * @param integer $id_carrier Carrier ID (default : current carrier) * @param booleal $use_tax * @param Country $default_country * @param Array $product_list * @param array $product_list List of product concerned by the shipping. If null, all the product of the cart are used to calculate the shipping cost * * @return float Shipping total */ public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null) { if ($this->isVirtualCart()) { return 0; } if (!$default_country) { $default_country = Context::getContext()->country; } $complete_product_list = $this->getProducts(); if (is_null($product_list)) { $products = $complete_product_list; } else { $products = $product_list; } if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') { $address_id = (int) $this->id_address_invoice; } elseif (count($product_list)) { $prod = current($product_list); $address_id = (int) $prod['id_address_delivery']; } else { $address_id = null; } if (!Address::addressExists($address_id)) { $address_id = null; } $cache_id = 'getPackageShippingCost_' . (int) $this->id . '_' . (int) $address_id . '_' . (int) $id_carrier . '_' . (int) $use_tax . '_' . (int) $default_country->id; if ($products) { foreach ($products as $product) { $cache_id .= '_' . (int) $product['id_product'] . '_' . (int) $product['id_product_attribute']; } } if (Cache::isStored($cache_id)) { return Cache::retrieve($cache_id); } // Order total in default currency without fees $order_total = $this->getOrderTotal(true, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING, $product_list); // Start with shipping cost at 0 $shipping_cost = 0; // If no product added, return 0 if (!count($products)) { Cache::store($cache_id, $shipping_cost); return $shipping_cost; } // Get id zone if (!$this->isMultiAddressDelivery() && 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); } else { if (!Validate::isLoadedObject($default_country)) { $default_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT')); } $id_zone = (int) $default_country->id_zone; } if ($id_carrier && !$this->isCarrierInRange((int) $id_carrier, (int) $id_zone)) { $id_carrier = ''; } if (empty($id_carrier) && $this->isCarrierInRange((int) Configuration::get('PS_CARRIER_DEFAULT'), (int) $id_zone)) { $id_carrier = (int) Configuration::get('PS_CARRIER_DEFAULT'); } 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()); unset($customer); } else { $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone); } 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((int) $row['id_carrier']); } $carrier = self::$_carriers[$row['id_carrier']]; // Get only carriers that are compliant with shipping method if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight((int) $id_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice((int) $id_zone) === false) { unset($result[$k]); continue; } // If out-of-range behavior carrier is set on "Desactivate carrier" if ($row['range_behavior']) { $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), (int) $id_zone); $total_order = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list); $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $total_order, (int) $id_zone, (int) $this->id_currency); // Get only carriers that have a range compatible with cart if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) { unset($result[$k]); continue; } } if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), (int) $id_zone); } else { $shipping = $carrier->getDeliveryPriceByPrice($order_total, (int) $id_zone, (int) $this->id_currency); } if (!isset($min_shipping_price)) { $min_shipping_price = $shipping; } if ($shipping <= $min_shipping_price) { $id_carrier = (int) $row['id_carrier']; $min_shipping_price = $shipping; } } } if (empty($id_carrier)) { $id_carrier = Configuration::get('PS_CARRIER_DEFAULT'); } 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) { Cache::store($cache_id, $shipping_cost); return $shipping_cost; } // Free fees if free carrier if ($carrier->is_free == 1) { Cache::store($cache_id, 0); return 0; } // Select carrier tax if ($use_tax && !Tax::excludeTaxeOption()) { $address = Address::initialize((int) $address_id); $carrier_tax = $carrier->getTaxesRate($address); } $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((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency)); } $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, null, null, false); if ($orderTotalwithDiscounts >= (double) $free_fees_price && (double) $free_fees_price > 0) { Cache::store($cache_id, $shipping_cost); return $shipping_cost; } if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $this->getTotalWeight() >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] && (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) { Cache::store($cache_id, $shipping_cost); return $shipping_cost; } // Get shipping cost using correct method if ($carrier->range_behavior) { // Get id zone 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); } else { $id_zone = (int) $default_country->id_zone; } $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight((int) $carrier->id, $this->getTotalWeight(), (int) $id_zone); // Code Review V&V TO FINISH $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($carrier->id, $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list), $id_zone, (int) $this->id_currency); if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) { $shipping_cost += 0; } else { if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone); } else { // by price $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency); } } } else { if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone); } else { $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 += (double) $configuration['PS_SHIPPING_HANDLING']; } // Additional Shipping Cost per product foreach ($products as $product) { if (!$product['is_virtual']) { $shipping_cost += $product['additional_shipping_cost'] * $product['cart_quantity']; } } $shipping_cost = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int) $this->id_currency)); //get external shipping cost from module if ($carrier->shipping_external) { $module_name = $carrier->external_module_name; $module = Module::getInstanceByName($module_name); if (Validate::isLoadedObject($module)) { if (array_key_exists('id_carrier', $module)) { $module->id_carrier = $carrier->id; } if ($carrier->need_range) { if (method_exists($module, 'getPackageShippingCost')) { $shipping_cost = $module->getPackageShippingCost($this, $shipping_cost, $products); } else { $shipping_cost = $module->getOrderShippingCost($this, $shipping_cost); } } else { $shipping_cost = $module->getOrderShippingCostExternal($this); } // Check if carrier is available if ($shipping_cost === false) { Cache::store($cache_id, false); return false; } } else { Cache::store($cache_id, false); return false; } } // Apply tax if ($use_tax && isset($carrier_tax)) { $shipping_cost *= 1 + $carrier_tax / 100; } // ############################################################### $num = $this->getTotalWeight($product_list); $countryAndState = Address::getCountryAndState((int) $this->id_address_delivery); $state = $countryAndState['id_state']; $pri = false; if ($pri) { echo "carrierid =>" . $id_carrier . "-"; echo 'products => ' . $num . '-'; echo 'state => ' . $state . '-'; } //Ground //if( $id_carrier == 21 ){ if ($id_carrier == 31) { //NO CA if ($state == 313) { if ($num == 1) { $shipping_cost = 19.75; } elseif ($num == 2) { $shipping_cost = 20.5; } elseif ($num == 3) { $shipping_cost = 22.0; } elseif ($num == 4) { $shipping_cost = 24.5; } elseif ($num == 5) { $shipping_cost = 25.75; } elseif ($num == 6) { $shipping_cost = 27.0; } elseif ($num == 7) { $shipping_cost = 30.5; } elseif ($num == 8) { $shipping_cost = 31.5; } elseif ($num == 9) { $shipping_cost = 32.25; } elseif ($num == 10) { $shipping_cost = 33.5; } elseif ($num == 11) { $shipping_cost = 34.25; } else { $shipping_cost = 34.5; } } elseif ($state == 5 || $state == 28) { if ($num == 1) { $shipping_cost = 19.75; } elseif ($num == 2) { $shipping_cost = 20.5; } elseif ($num == 3) { $shipping_cost = 22.25; } elseif ($num == 4) { $shipping_cost = 25.25; } elseif ($num == 5) { $shipping_cost = 26.5; } elseif ($num == 6) { $shipping_cost = 28.0; } elseif ($num == 7) { $shipping_cost = 32.5; } elseif ($num == 8) { $shipping_cost = 33.25; } elseif ($num == 9) { $shipping_cost = 34.5; } elseif ($num == 10) { $shipping_cost = 35.25; } elseif ($num == 11) { $shipping_cost = 36.75; } else { $shipping_cost = 38.0; } } elseif ($state == 44 or $state == 37 or $state == 3 or $state == 47) { if ($num == 1) { $shipping_cost = 22.75; } elseif ($num == 2) { $shipping_cost = 23.75; } elseif ($num == 3) { $shipping_cost = 25.0; } elseif ($num == 4) { $shipping_cost = 25.75; } elseif ($num == 5) { $shipping_cost = 27.5; } elseif ($num == 6) { $shipping_cost = 28.25; } elseif ($num == 7) { $shipping_cost = 33.25; } elseif ($num == 8) { $shipping_cost = 34.5; } elseif ($num == 9) { $shipping_cost = 35.5; } elseif ($num == 10) { $shipping_cost = 36.75; } elseif ($num == 11) { $shipping_cost = 38.0; } else { $shipping_cost = 39.5; } } elseif ($state == 12 || $state == 26 || $state == 6 || $state == 31) { if ($num == 1) { $shipping_cost = 23.0; } elseif ($num == 2) { $shipping_cost = 24.5; } elseif ($num == 3) { $shipping_cost = 25.75; } elseif ($num == 4) { $shipping_cost = 26.5; } elseif ($num == 5) { $shipping_cost = 28.0; } elseif ($num == 6) { $shipping_cost = 29.5; } elseif ($num == 7) { $shipping_cost = 34.75; } elseif ($num == 8) { $shipping_cost = 36.75; } elseif ($num == 9) { $shipping_cost = 38.25; } elseif ($num == 10) { $shipping_cost = 39.5; } elseif ($num == 11) { $shipping_cost = 41.25; } else { $shipping_cost = 42.5; } } elseif ($state == 34 || $state == 41 || $state == 27 || $state == 16 || $state == 36 || $state == 50) { if ($num == 1) { $shipping_cost = 24.0; } elseif ($num == 2) { $shipping_cost = 24.75; } elseif ($num == 3) { $shipping_cost = 26.25; } elseif ($num == 4) { $shipping_cost = 27.75; } elseif ($num == 5) { $shipping_cost = 30.25; } elseif ($num == 6) { $shipping_cost = 33.25; } elseif ($num == 7) { $shipping_cost = 38.5; } elseif ($num == 8) { $shipping_cost = 41.25; } elseif ($num == 9) { $shipping_cost = 44.0; } elseif ($num == 10) { $shipping_cost = 45.75; } elseif ($num == 11) { $shipping_cost = 47.75; } else { $shipping_cost = 49.5; } } elseif ($state == 23 || $state == 15 || $state == 25 || $state == 4 || $state == 18 || $state == 24 || $state == 49) { if ($num == 1) { $shipping_cost = 24.0; } elseif ($num == 2) { $shipping_cost = 25.25; } elseif ($num == 3) { $shipping_cost = 27.5; } elseif ($num == 4) { $shipping_cost = 29.75; } elseif ($num == 5) { $shipping_cost = 32.75; } elseif ($num == 6) { $shipping_cost = 36.25; } elseif ($num == 7) { $shipping_cost = 42.25; } elseif ($num == 8) { $shipping_cost = 44.75; } elseif ($num == 9) { $shipping_cost = 47.0; } elseif ($num == 10) { $shipping_cost = 49.75; } elseif ($num == 11) { $shipping_cost = 52.0; } else { $shipping_cost = 54.0; } } elseif ($state == 2 || $state == 11) { if ($num == 1) { $shipping_cost = 46.0; } elseif ($num == 2) { $shipping_cost = 56.25; } elseif ($num == 3) { $shipping_cost = 64.75; } elseif ($num == 4) { $shipping_cost = 74.0; } elseif ($num == 5) { $shipping_cost = 77.25; } elseif ($num == 6) { $shipping_cost = 85.0; } elseif ($num == 7) { $shipping_cost = 91.5; } elseif ($num == 8) { $shipping_cost = 98.0; } elseif ($num == 9) { $shipping_cost = 105.25; } elseif ($num == 10) { $shipping_cost = 111.5; } elseif ($num == 11) { $shipping_cost = 117.5; } else { $shipping_cost = 124.25; } } else { if ($num == 1) { $shipping_cost = 24.75; } elseif ($num == 2) { $shipping_cost = 26.25; } elseif ($num == 3) { $shipping_cost = 28.75; } elseif ($num == 4) { $shipping_cost = 30.25; } elseif ($num == 5) { $shipping_cost = 35.0; } elseif ($num == 6) { $shipping_cost = 39.0; } elseif ($num == 7) { $shipping_cost = 45.5; } elseif ($num == 8) { $shipping_cost = 48.75; } elseif ($num == 9) { $shipping_cost = 51.75; } elseif ($num == 10) { $shipping_cost = 54.75; } elseif ($num == 11) { $shipping_cost = 58.0; } else { $shipping_cost = 60.5; } } } elseif ($id_carrier == 30) { //NO CA - 302 if ($state == 313) { if ($num == 1) { $shipping_cost = 24.0; } elseif ($num == 2) { $shipping_cost = 24.75; } elseif ($num == 3) { $shipping_cost = 25.25; } elseif ($num == 4) { $shipping_cost = 26.25; } elseif ($num == 5) { $shipping_cost = 27.75; } elseif ($num == 6) { $shipping_cost = 29.75; } elseif ($num == 7) { $shipping_cost = 32.25; } elseif ($num == 8) { $shipping_cost = 34.5; } elseif ($num == 9) { $shipping_cost = 36.25; } elseif ($num == 10) { $shipping_cost = 38.0; } elseif ($num == 11) { $shipping_cost = 40.0; } else { $shipping_cost = 42.0; } } elseif ($state == 5 || $state == 28) { if ($num == 1) { $shipping_cost = 24.0; } elseif ($num == 2) { $shipping_cost = 24.75; } elseif ($num == 3) { $shipping_cost = 25.75; } elseif ($num == 4) { $shipping_cost = 27.75; } elseif ($num == 5) { $shipping_cost = 30.25; } elseif ($num == 6) { $shipping_cost = 33.5; } elseif ($num == 7) { $shipping_cost = 38.0; } elseif ($num == 8) { $shipping_cost = 38.5; } elseif ($num == 9) { $shipping_cost = 40.0; } elseif ($num == 10) { $shipping_cost = 41.75; } elseif ($num == 11) { $shipping_cost = 45.5; } else { $shipping_cost = 47.75; } } elseif ($state == 44 or $state == 37 or $state == 3 or $state == 47) { if ($num == 1) { $shipping_cost = 24.75; } elseif ($num == 2) { $shipping_cost = 25.75; } elseif ($num == 3) { $shipping_cost = 27.0; } elseif ($num == 4) { $shipping_cost = 30.5; } elseif ($num == 5) { $shipping_cost = 34.0; } elseif ($num == 6) { $shipping_cost = 36.75; } elseif ($num == 7) { $shipping_cost = 40.25; } elseif ($num == 8) { $shipping_cost = 42.25; } elseif ($num == 9) { $shipping_cost = 45.25; } elseif ($num == 10) { $shipping_cost = 47.75; } elseif ($num == 11) { $shipping_cost = 50.75; } else { $shipping_cost = 53.5; } } elseif ($state == 12 || $state == 26 || $state == 6 || $state == 31) { if ($num == 1) { $shipping_cost = 24.75; } elseif ($num == 2) { $shipping_cost = 27.75; } elseif ($num == 3) { $shipping_cost = 29.5; } elseif ($num == 4) { $shipping_cost = 33.5; } elseif ($num == 5) { $shipping_cost = 38.0; } elseif ($num == 6) { $shipping_cost = 40.75; } elseif ($num == 7) { $shipping_cost = 45.25; } elseif ($num == 8) { $shipping_cost = 48.0; } elseif ($num == 9) { $shipping_cost = 52.25; } elseif ($num == 10) { $shipping_cost = 54.25; } elseif ($num == 11) { $shipping_cost = 57.25; } else { $shipping_cost = 62.25; } } elseif ($state == 34 || $state == 41 || $state == 27 || $state == 16 || $state == 36 || $state == 50) { if ($num == 1) { $shipping_cost = 25.5; } elseif ($num == 2) { $shipping_cost = 30.5; } elseif ($num == 3) { $shipping_cost = 36.0; } elseif ($num == 4) { $shipping_cost = 40.25; } elseif ($num == 5) { $shipping_cost = 47.75; } elseif ($num == 6) { $shipping_cost = 51.25; } elseif ($num == 7) { $shipping_cost = 56.25; } elseif ($num == 8) { $shipping_cost = 60.25; } elseif ($num == 9) { $shipping_cost = 65.0; } elseif ($num == 10) { $shipping_cost = 69.5; } elseif ($num == 11) { $shipping_cost = 74.25; } else { $shipping_cost = 78.5; } } elseif ($state == 23 || $state == 15 || $state == 25 || $state == 4 || $state == 18 || $state == 24 || $state == 49) { if ($num == 1) { $shipping_cost = 31.5; } elseif ($num == 2) { $shipping_cost = 33.25; } elseif ($num == 3) { $shipping_cost = 38.5; } elseif ($num == 4) { $shipping_cost = 43.75; } elseif ($num == 5) { $shipping_cost = 49.5; } elseif ($num == 6) { $shipping_cost = 54.75; } elseif ($num == 7) { $shipping_cost = 62.25; } elseif ($num == 8) { $shipping_cost = 67.0; } elseif ($num == 9) { $shipping_cost = 72.0; } elseif ($num == 10) { $shipping_cost = 77.25; } elseif ($num == 11) { $shipping_cost = 81.5; } else { $shipping_cost = 86.5; } } elseif ($state == 2 || $state == 11) { if ($num == 1) { $shipping_cost = -1; } elseif ($num == 2) { $shipping_cost = -1; } elseif ($num == 3) { $shipping_cost = -1; } elseif ($num == 4) { $shipping_cost = -1; } elseif ($num == 5) { $shipping_cost = -1; } elseif ($num == 6) { $shipping_cost = -1; } elseif ($num == 7) { $shipping_cost = -1; } elseif ($num == 8) { $shipping_cost = -1; } elseif ($num == 9) { $shipping_cost = -1; } elseif ($num == 10) { $shipping_cost = -1; } elseif ($num == 11) { $shipping_cost = -1; } else { $shipping_cost = -1; } } else { if ($num == 1) { $shipping_cost = 28.25; } elseif ($num == 2) { $shipping_cost = 34.25; } elseif ($num == 3) { $shipping_cost = 41.0; } elseif ($num == 4) { $shipping_cost = 48.25; } elseif ($num == 5) { $shipping_cost = 54.0; } elseif ($num == 6) { $shipping_cost = 59.0; } elseif ($num == 7) { $shipping_cost = 67.0; } elseif ($num == 8) { $shipping_cost = 73.75; } elseif ($num == 9) { $shipping_cost = 77.5; } elseif ($num == 10) { $shipping_cost = 83.25; } elseif ($num == 11) { $shipping_cost = 88.5; } else { $shipping_cost = 93.0; } } } elseif ($id_carrier == 32) { //NO CA - 202 if ($state == 313) { if ($num == 1) { $shipping_cost = 23.75; } elseif ($num == 2) { $shipping_cost = 23.75; } elseif ($num == 3) { $shipping_cost = 26.0; } elseif ($num == 4) { $shipping_cost = 27.5; } elseif ($num == 5) { $shipping_cost = 29.25; } elseif ($num == 6) { $shipping_cost = 30.75; } elseif ($num == 7) { $shipping_cost = 34.75; } elseif ($num == 8) { $shipping_cost = 37.5; } elseif ($num == 9) { $shipping_cost = 40.0; } elseif ($num == 10) { $shipping_cost = 40.75; } elseif ($num == 11) { $shipping_cost = 43.25; } else { $shipping_cost = 45.5; } } elseif ($state == 5 || $state == 28) { if ($num == 1) { $shipping_cost = 23.75; } elseif ($num == 2) { $shipping_cost = 24.25; } elseif ($num == 3) { $shipping_cost = 28.0; } elseif ($num == 4) { $shipping_cost = 29.25; } elseif ($num == 5) { $shipping_cost = 31.75; } elseif ($num == 6) { $shipping_cost = 34.75; } elseif ($num == 7) { $shipping_cost = 38.75; } elseif ($num == 8) { $shipping_cost = 41.25; } elseif ($num == 9) { $shipping_cost = 43.75; } elseif ($num == 10) { $shipping_cost = 46.25; } elseif ($num == 11) { $shipping_cost = 48.25; } else { $shipping_cost = 50.5; } } elseif ($state == 44 or $state == 37 or $state == 3 or $state == 47) { if ($num == 1) { $shipping_cost = 23.75; } elseif ($num == 2) { $shipping_cost = 25.5; } elseif ($num == 3) { $shipping_cost = 30.75; } elseif ($num == 4) { $shipping_cost = 33.0; } elseif ($num == 5) { $shipping_cost = 36.25; } elseif ($num == 6) { $shipping_cost = 40.5; } elseif ($num == 7) { $shipping_cost = 44.75; } elseif ($num == 8) { $shipping_cost = 46.5; } elseif ($num == 9) { $shipping_cost = 50.25; } elseif ($num == 10) { $shipping_cost = 52.5; } elseif ($num == 11) { $shipping_cost = 55.25; } else { $shipping_cost = 59.0; } } elseif ($state == 12 || $state == 26 || $state == 6 || $state == 31) { if ($num == 1) { $shipping_cost = 27.25; } elseif ($num == 2) { $shipping_cost = 30.75; } elseif ($num == 3) { $shipping_cost = 36.0; } elseif ($num == 4) { $shipping_cost = 41.0; } elseif ($num == 5) { $shipping_cost = 46.0; } elseif ($num == 6) { $shipping_cost = 50.5; } elseif ($num == 7) { $shipping_cost = 57.25; } elseif ($num == 8) { $shipping_cost = 61.75; } elseif ($num == 9) { $shipping_cost = 65.0; } elseif ($num == 10) { $shipping_cost = 68.75; } elseif ($num == 11) { $shipping_cost = 72.25; } else { $shipping_cost = 76.75; } } elseif ($state == 34 || $state == 41 || $state == 27 || $state == 16 || $state == 36 || $state == 50) { if ($num == 1) { $shipping_cost = 29.25; } elseif ($num == 2) { $shipping_cost = 38.75; } elseif ($num == 3) { $shipping_cost = 46.5; } elseif ($num == 4) { $shipping_cost = 54.75; } elseif ($num == 5) { $shipping_cost = 62.75; } elseif ($num == 6) { $shipping_cost = 69.75; } elseif ($num == 7) { $shipping_cost = 77.75; } elseif ($num == 8) { $shipping_cost = 84.25; } elseif ($num == 9) { $shipping_cost = 90.75; } elseif ($num == 10) { $shipping_cost = 96.75; } elseif ($num == 11) { $shipping_cost = 105.0; } else { $shipping_cost = 111.25; } } elseif ($state == 23 || $state == 15 || $state == 25 || $state == 4 || $state == 18 || $state == 24 || $state == 49) { if ($num == 1) { $shipping_cost = 32.0; } elseif ($num == 2) { $shipping_cost = 40.25; } elseif ($num == 3) { $shipping_cost = 49.75; } elseif ($num == 4) { $shipping_cost = 58.0; } elseif ($num == 5) { $shipping_cost = 65.5; } elseif ($num == 6) { $shipping_cost = 74.25; } elseif ($num == 7) { $shipping_cost = 82.5; } elseif ($num == 8) { $shipping_cost = 89.5; } elseif ($num == 9) { $shipping_cost = 96.5; } elseif ($num == 10) { $shipping_cost = 102.5; } elseif ($num == 11) { $shipping_cost = 109.25; } else { $shipping_cost = 116.75; } } elseif ($state == 2 || $state == 11) { if ($num == 1) { $shipping_cost = -1; } elseif ($num == 2) { $shipping_cost = -1; } elseif ($num == 3) { $shipping_cost = -1; } elseif ($num == 4) { $shipping_cost = -1; } elseif ($num == 5) { $shipping_cost = -1; } elseif ($num == 6) { $shipping_cost = -1; } elseif ($num == 7) { $shipping_cost = -1; } elseif ($num == 8) { $shipping_cost = -1; } elseif ($num == 9) { $shipping_cost = -1; } elseif ($num == 10) { $shipping_cost = -1; } elseif ($num == 11) { $shipping_cost = -1; } else { $shipping_cost = -1; } } else { if ($num == 1) { $shipping_cost = 34.75; } elseif ($num == 2) { $shipping_cost = 41.0; } elseif ($num == 3) { $shipping_cost = 50.25; } elseif ($num == 4) { $shipping_cost = 59.75; } elseif ($num == 5) { $shipping_cost = 66.5; } elseif ($num == 6) { $shipping_cost = 75.25; } elseif ($num == 7) { $shipping_cost = 84.5; } elseif ($num == 8) { $shipping_cost = 92.25; } elseif ($num == 9) { $shipping_cost = 98.5; } elseif ($num == 10) { $shipping_cost = 105.5; } elseif ($num == 11) { $shipping_cost = 112.0; } else { $shipping_cost = 119.25; } } } elseif ($id_carrier == 29) { //NO CA - 102 if ($state == 313) { if ($num == 1) { $shipping_cost = 27.25; } elseif ($num == 2) { $shipping_cost = 29.0; } elseif ($num == 3) { $shipping_cost = 32.75; } elseif ($num == 4) { $shipping_cost = 36.25; } elseif ($num == 5) { $shipping_cost = 38.75; } elseif ($num == 6) { $shipping_cost = 40.75; } elseif ($num == 7) { $shipping_cost = 45.25; } elseif ($num == 8) { $shipping_cost = 48.25; } elseif ($num == 9) { $shipping_cost = 50.5; } elseif ($num == 10) { $shipping_cost = 54.75; } elseif ($num == 11) { $shipping_cost = 56.25; } else { $shipping_cost = 60.5; } } elseif ($state == 5 || $state == 28) { if ($num == 1) { $shipping_cost = 31.75; } elseif ($num == 2) { $shipping_cost = 37.5; } elseif ($num == 3) { $shipping_cost = 39.5; } elseif ($num == 4) { $shipping_cost = 44.25; } elseif ($num == 5) { $shipping_cost = 48.0; } elseif ($num == 6) { $shipping_cost = 52.75; } elseif ($num == 7) { $shipping_cost = 56.75; } elseif ($num == 8) { $shipping_cost = 59.5; } elseif ($num == 9) { $shipping_cost = 65.0; } elseif ($num == 10) { $shipping_cost = 67.5; } elseif ($num == 11) { $shipping_cost = 71.25; } else { $shipping_cost = 76.5; } } elseif ($state == 44 or $state == 37 or $state == 3 or $state == 47) { if ($num == 1) { $shipping_cost = 38.75; } elseif ($num == 2) { $shipping_cost = 47.75; } elseif ($num == 3) { $shipping_cost = 57.75; } elseif ($num == 4) { $shipping_cost = 64.0; } elseif ($num == 5) { $shipping_cost = 71.25; } elseif ($num == 6) { $shipping_cost = 80.75; } elseif ($num == 7) { $shipping_cost = 85.75; } elseif ($num == 8) { $shipping_cost = 92.5; } elseif ($num == 9) { $shipping_cost = 100.75; } elseif ($num == 10) { $shipping_cost = 105.25; } elseif ($num == 11) { $shipping_cost = 111.5; } else { $shipping_cost = 117.75; } } elseif ($state == 12 || $state == 26 || $state == 6 || $state == 31) { if ($num == 1) { $shipping_cost = 41.25; } elseif ($num == 2) { $shipping_cost = 50.75; } elseif ($num == 3) { $shipping_cost = 61.75; } elseif ($num == 4) { $shipping_cost = 70.75; } elseif ($num == 5) { $shipping_cost = 78.75; } elseif ($num == 6) { $shipping_cost = 86.75; } elseif ($num == 7) { $shipping_cost = 91.5; } elseif ($num == 8) { $shipping_cost = 99.0; } elseif ($num == 9) { $shipping_cost = 105.5; } elseif ($num == 10) { $shipping_cost = 113.0; } elseif ($num == 11) { $shipping_cost = 119.75; } else { $shipping_cost = 126.5; } } elseif ($state == 34 || $state == 41 || $state == 27 || $state == 16 || $state == 36 || $state == 50) { if ($num == 1) { $shipping_cost = 46.75; } elseif ($num == 2) { $shipping_cost = 53.75; } elseif ($num == 3) { $shipping_cost = 67.25; } elseif ($num == 4) { $shipping_cost = 77.0; } elseif ($num == 5) { $shipping_cost = 83.75; } elseif ($num == 6) { $shipping_cost = 93.0; } elseif ($num == 7) { $shipping_cost = 100.25; } elseif ($num == 8) { $shipping_cost = 103.0; } elseif ($num == 9) { $shipping_cost = 112.25; } elseif ($num == 10) { $shipping_cost = 120.5; } elseif ($num == 11) { $shipping_cost = 126.25; } else { $shipping_cost = 132.0; } } elseif ($state == 23 || $state == 15 || $state == 25 || $state == 4 || $state == 18 || $state == 24 || $state == 49) { if ($num == 1) { $shipping_cost = 49.25; } elseif ($num == 2) { $shipping_cost = 56.25; } elseif ($num == 3) { $shipping_cost = 69.0; } elseif ($num == 4) { $shipping_cost = 79.25; } elseif ($num == 5) { $shipping_cost = 88.25; } elseif ($num == 6) { $shipping_cost = 95.75; } elseif ($num == 7) { $shipping_cost = 101.5; } elseif ($num == 8) { $shipping_cost = 109.25; } elseif ($num == 9) { $shipping_cost = 116.0; } elseif ($num == 10) { $shipping_cost = 123.25; } elseif ($num == 11) { $shipping_cost = 130.0; } else { $shipping_cost = 138.75; } } elseif ($state == 2 || $state == 11) { if ($num == 1) { $shipping_cost = 53.75; } elseif ($num == 2) { $shipping_cost = 67.5; } elseif ($num == 3) { $shipping_cost = 78.75; } elseif ($num == 4) { $shipping_cost = 85.5; } elseif ($num == 5) { $shipping_cost = 96.75; } elseif ($num == 6) { $shipping_cost = 101.5; } elseif ($num == 7) { $shipping_cost = 116.25; } elseif ($num == 8) { $shipping_cost = 130.0; } elseif ($num == 9) { $shipping_cost = 142.5; } elseif ($num == 10) { $shipping_cost = 152.5; } elseif ($num == 11) { $shipping_cost = 159.75; } else { $shipping_cost = 168.25; } } else { if ($num == 1) { $shipping_cost = 50.75; } elseif ($num == 2) { $shipping_cost = 60.5; } elseif ($num == 3) { $shipping_cost = 70.5; } elseif ($num == 4) { $shipping_cost = 81.0; } elseif ($num == 5) { $shipping_cost = 90.25; } elseif ($num == 6) { $shipping_cost = 98.5; } elseif ($num == 7) { $shipping_cost = 104.5; } elseif ($num == 8) { $shipping_cost = 113.0; } elseif ($num == 9) { $shipping_cost = 119.25; } elseif ($num == 10) { $shipping_cost = 127.0; } elseif ($num == 11) { $shipping_cost = 133.75; } else { $shipping_cost = 139.75; } } } elseif ($id_carrier == 16) { //NO CA if ($state == 313) { if ($num == 1) { $shipping_cost = 11.0; } elseif ($num == 2) { $shipping_cost = 12.0; } elseif ($num == 3) { $shipping_cost = 12.75; } elseif ($num == 4) { $shipping_cost = 14.75; } elseif ($num == 5) { $shipping_cost = 15.75; } elseif ($num == 6) { $shipping_cost = 16.0; } elseif ($num == 7) { $shipping_cost = 19.0; } elseif ($num == 8) { $shipping_cost = 19.25; } elseif ($num == 9) { $shipping_cost = 20.0; } elseif ($num == 10) { $shipping_cost = 20.75; } elseif ($num == 11) { $shipping_cost = 22.0; } else { $shipping_cost = 22.25; } } elseif ($state == 314) { if ($num == 1) { $shipping_cost = 11.75; } elseif ($num == 2) { $shipping_cost = 12.5; } elseif ($num == 3) { $shipping_cost = 13.75; } elseif ($num == 4) { $shipping_cost = 14.75; } elseif ($num == 5) { $shipping_cost = 16.0; } elseif ($num == 6) { $shipping_cost = 16.75; } elseif ($num == 7) { $shipping_cost = 20.0; } elseif ($num == 8) { $shipping_cost = 20.75; } elseif ($num == 9) { $shipping_cost = 22.0; } elseif ($num == 10) { $shipping_cost = 22.75; } elseif ($num == 11) { $shipping_cost = 24.0; } else { $shipping_cost = 24.0; } } elseif ($state == 315) { if ($num == 1) { $shipping_cost = 12.25; } elseif ($num == 2) { $shipping_cost = 13.75; } elseif ($num == 3) { $shipping_cost = 14.5; } elseif ($num == 4) { $shipping_cost = 15.75; } elseif ($num == 5) { $shipping_cost = 16.5; } elseif ($num == 6) { $shipping_cost = 17.0; } elseif ($num == 7) { $shipping_cost = 20.5; } elseif ($num == 8) { $shipping_cost = 22.0; } elseif ($num == 9) { $shipping_cost = 22.75; } elseif ($num == 10) { $shipping_cost = 24.0; } elseif ($num == 11) { $shipping_cost = 25.25; } else { $shipping_cost = 26.0; } } elseif ($state == 3 || $state == 28) { if ($num == 1) { $shipping_cost = 12.25; } elseif ($num == 2) { $shipping_cost = 14.0; } elseif ($num == 3) { $shipping_cost = 14.75; } elseif ($num == 4) { $shipping_cost = 16.25; } elseif ($num == 5) { $shipping_cost = 17.75; } elseif ($num == 6) { $shipping_cost = 18.75; } elseif ($num == 7) { $shipping_cost = 22.5; } elseif ($num == 8) { $shipping_cost = 24.0; } elseif ($num == 9) { $shipping_cost = 25.25; } elseif ($num == 10) { $shipping_cost = 26.75; } elseif ($num == 11) { $shipping_cost = 28.25; } else { $shipping_cost = 29.0; } } else { if ($num == 1) { $shipping_cost = -1; } elseif ($num == 2) { $shipping_cost = -1; } elseif ($num == 3) { $shipping_cost = -1; } elseif ($num == 4) { $shipping_cost = -1; } elseif ($num == 5) { $shipping_cost = -1; } elseif ($num == 6) { $shipping_cost = -1; } elseif ($num == 7) { $shipping_cost = -1; } elseif ($num == 8) { $shipping_cost = -1; } elseif ($num == 9) { $shipping_cost = -1; } elseif ($num == 10) { $shipping_cost = -1; } elseif ($num == 11) { $shipping_cost = -1; } else { $shipping_cost = -1; } } } //############################################################### $shipping_cost = (double) Tools::ps_round((double) $shipping_cost, 2); Cache::store($cache_id, $shipping_cost); return $shipping_cost; }
/** * For a given {product, warehouse}, gets the carrier available * * @since 1.5.0 * * @param Product $product The id of the product, or an array with at least the package size and weight * @param int $id_warehouse Warehouse ID * @param int $id_address_delivery Delivery Address ID * @param int $id_shop Shop ID * @param Cart $cart Cart object * @param array &$error contain an error message if an error occurs * * @return array Available Carriers * @throws PrestaShopDatabaseException */ public static function getAvailableCarrierList(Product $product, $id_warehouse, $id_address_delivery = null, $id_shop = null, $cart = null, &$error = array()) { static $ps_country_default = null; if ($ps_country_default === null) { $ps_country_default = Configuration::get('PS_COUNTRY_DEFAULT'); } if (is_null($id_shop)) { $id_shop = Context::getContext()->shop->id; } if (is_null($cart)) { $cart = Context::getContext()->cart; } if (is_null($error) || !is_array($error)) { $error = array(); } $id_address = (int) (!is_null($id_address_delivery) && $id_address_delivery != 0 ? $id_address_delivery : $cart->id_address_delivery); if ($id_address) { $id_zone = Address::getZoneById($id_address); // Check the country of the address is activated if (!Address::isCountryActiveById($id_address)) { return array(); } } else { $country = new Country($ps_country_default); $id_zone = $country->id_zone; } // Does the product is linked with carriers? $cache_id = 'Carrier::getAvailableCarrierList_' . (int) $product->id . '-' . (int) $id_shop; if (!Cache::isStored($cache_id)) { $query = new DbQuery(); $query->select('id_carrier'); $query->from('product_carrier', 'pc'); $query->innerJoin('carrier', 'c', 'c.id_reference = pc.id_carrier_reference AND c.deleted = 0 AND c.active = 1'); $query->where('pc.id_product = ' . (int) $product->id); $query->where('pc.id_shop = ' . (int) $id_shop); $carriers_for_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); Cache::store($cache_id, $carriers_for_product); } else { $carriers_for_product = Cache::retrieve($cache_id); } $carrier_list = array(); if (!empty($carriers_for_product)) { //the product is linked with carriers foreach ($carriers_for_product as $carrier) { //check if the linked carriers are available in current zone if (Carrier::checkCarrierZone($carrier['id_carrier'], $id_zone)) { $carrier_list[$carrier['id_carrier']] = $carrier['id_carrier']; } } if (empty($carrier_list)) { return array(); } //no linked carrier are available for this zone } // The product is not directly linked with a carrier // Get all the carriers linked to a warehouse if ($id_warehouse) { $warehouse = new Warehouse($id_warehouse); $warehouse_carrier_list = $warehouse->getCarriers(); } $available_carrier_list = array(); $cache_id = 'Carrier::getAvailableCarrierList_getCarriersForOrder_' . (int) $id_zone . '-' . (int) $cart->id; if (!Cache::isStored($cache_id)) { $customer = new Customer($cart->id_customer); $carrier_error = array(); $carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups(), $cart, $carrier_error); Cache::store($cache_id, array($carriers, $carrier_error)); } else { list($carriers, $carrier_error) = Cache::retrieve($cache_id); } $error = array_merge($error, $carrier_error); foreach ($carriers as $carrier) { $available_carrier_list[$carrier['id_carrier']] = $carrier['id_carrier']; } if ($carrier_list) { $carrier_list = array_intersect($available_carrier_list, $carrier_list); } else { $carrier_list = $available_carrier_list; } if (isset($warehouse_carrier_list)) { $carrier_list = array_intersect($carrier_list, $warehouse_carrier_list); } $cart_quantity = 0; $cart_weight = 0; foreach ($cart->getProducts(false, false) as $cart_product) { if ($cart_product['id_product'] == $product->id) { $cart_quantity += $cart_product['cart_quantity']; } if (isset($cart_product['weight_attribute']) && $cart_product['weight_attribute'] > 0) { $cart_weight += $cart_product['weight_attribute'] * $cart_product['cart_quantity']; } else { $cart_weight += $cart_product['weight'] * $cart_product['cart_quantity']; } } if ($product->width > 0 || $product->height > 0 || $product->depth > 0 || $product->weight > 0 || $cart_weight > 0) { foreach ($carrier_list as $key => $id_carrier) { $carrier = new Carrier($id_carrier); // Get the sizes of the carrier and the product and sort them to check if the carrier can take the product. $carrier_sizes = array((int) $carrier->max_width, (int) $carrier->max_height, (int) $carrier->max_depth); $product_sizes = array((int) $product->width, (int) $product->height, (int) $product->depth); rsort($carrier_sizes, SORT_NUMERIC); rsort($product_sizes, SORT_NUMERIC); if ($carrier_sizes[0] > 0 && $carrier_sizes[0] < $product_sizes[0] || $carrier_sizes[1] > 0 && $carrier_sizes[1] < $product_sizes[1] || $carrier_sizes[2] > 0 && $carrier_sizes[2] < $product_sizes[2]) { $error[$carrier->id] = Carrier::SHIPPING_SIZE_EXCEPTION; unset($carrier_list[$key]); } if ($carrier->max_weight > 0 && ($carrier->max_weight < $product->weight * $cart_quantity || $carrier->max_weight < $cart_weight)) { $error[$carrier->id] = Carrier::SHIPPING_WEIGHT_EXCEPTION; unset($carrier_list[$key]); } } } return $carrier_list; }
function displayOrderStep($params) { global $smarty, $cart, $cookie, $defaultCountry; if ($isVirtualCart = $cart->isVirtualCart()) { $cart->id_carrier = 0; $cart->update(); } $smarty->assign('virtual_cart', $isVirtualCart); $address = new Address(intval($cart->id_address_delivery)); $id_zone = Address::getZoneById($address->id); $result = Carrier::getCarriers(intval($cookie->id_lang), true, false, intval($id_zone)); $resultsArray = array(); foreach ($result as $k => $row) { $carrier = new Carrier(intval($row['id_carrier'])); if (Configuration::get('PS_SHIPPING_METHOD') and !$carrier->getMaxDeliveryPriceByWeight($id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !$carrier->getMaxDeliveryPriceByPrice($id_zone)) { unset($result[$k]); continue; } if ($row['range_behavior']) { // Get id zone if (isset($cart->id_address_delivery) and $cart->id_address_delivery) { $id_zone = Address::getZoneById(intval($cart->id_address_delivery)); } else { $id_zone = intval($defaultCountry->id_zone); } if (Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone) or !Configuration::get('PS_SHIPPING_METHOD') and !Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotalLC(true, 4), $id_zone)) { unset($result[$k]); continue; } } $row['name'] = strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME'); $row['price'] = $cart->getOrderShippingCostLC(intval($row['id_carrier'])); $row['price_tax_exc'] = $cart->getOrderShippingCostLC(intval($row['id_carrier']), false); $row['img'] = file_exists(_PS_SHIP_IMG_DIR_ . intval($row['id_carrier']) . '.jpg') ? _THEME_SHIP_DIR_ . intval($row['id_carrier']) . '.jpg' : ''; $row['extra'] = Module::hookExec('extraCarrierDetails', array("row" => $row, "carrier" => $carrier)); $resultsArray[] = $row; } // Wrapping fees $wrapping_fees = floatval(Configuration::get('PS_GIFT_WRAPPING_PRICE')); $wrapping_fees_tax = new Tax(intval(Configuration::get('PS_GIFT_WRAPPING_TAX'))); $wrapping_fees_tax_exc = $wrapping_fees / (1 + floatval($wrapping_fees_tax->rate) / 100); if (Validate::isUnsignedInt($cart->id_carrier)) { $carrier = new Carrier(intval($cart->id_carrier)); if ($carrier->active and !$carrier->deleted) { $checked = intval($cart->id_carrier); } } if (!isset($checked)) { $checked = intval(Configuration::get('PS_CARRIER_DEFAULT')); } $smarty->assign(array('checkedTOS' => intval($cookie->checkedTOS), 'recyclablePackAllowed' => intval(Configuration::get('PS_RECYCLABLE_PACK')), 'giftAllowed' => intval(Configuration::get('PS_GIFT_WRAPPING')), 'conditions' => intval(Configuration::get('PS_CONDITIONS')), 'recyclable' => intval($cart->recyclable), 'gift_wrapping_price' => floatval(Configuration::get('PS_GIFT_WRAPPING_PRICE')), 'carriers' => $resultsArray, 'HOOK_EXTRACARRIER' => Module::hookExec('extraCarrier', array('address' => $address)), 'checked' => intval($checked), 'back' => strval(Tools::getValue('back')), 'total_wrapping' => number_format($wrapping_fees, 2, '.', ''), 'total_wrapping_tax_exc' => number_format($wrapping_fees_tax_exc, 2, '.', ''))); Tools::safePostVars(); $css_files = array(__PS_BASE_URI__ . 'css/thickbox.css' => 'all'); $js_files = array(__PS_BASE_URI__ . 'js/jquery/thickbox-modified.js'); include_once dirname(__FILE__) . '/../../header.php'; echo $this->display(__FILE__, 'ordercarrier.tpl'); }