/** * Récupération du prix de shipping pour un produit id * @param $shipping * @return float */ public function getShippingPrice($product_id, $attribute_id, $id_carrier = 0, $id_zone = 0) { $product = new Product($product_id); $shipping = 0; $carrier = new Carrier((int) $id_carrier); if ($id_zone == 0) { $defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT')); $id_zone = (int) $defaultCountry->id_zone; } $carrierTax = Tax::getCarrierTaxRate((int) $carrier->id); $free_weight = Configuration::get('PS_SHIPPING_FREE_WEIGHT'); $shipping_handling = Configuration::get('PS_SHIPPING_HANDLING'); if ($product->getPrice(true, $attribute_id, 2, NULL, false, true, 1) >= (double) $free_weight and (double) $free_weight > 0) { $shipping = 0; } elseif (isset($free_weight) and $product->weight >= (double) $free_weight and (double) $free_weight > 0) { $shipping = 0; } else { if (isset($shipping_handling) and $carrier->shipping_handling) { $shipping = (double) $shipping_handling; } if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping += $carrier->getDeliveryPriceByWeight($product->weight, $id_zone); } else { $shipping += $carrier->getDeliveryPriceByPrice($product->getPrice(true, $attribute_id, 2, NULL, false, true, 1), $id_zone); } $shipping *= 1 + $carrierTax / 100; $shipping = (double) Tools::ps_round((double) $shipping, 2); } unset($product); return $shipping; }
private static function _getShippingPriceForProduct($product, $zone, $carrier_id) { $carrier = new Carrier($carrier_id); if ($carrier->shipping_method == 0) { // Default if (Configuration::get('PS_SHIPPING_METHOD') == 1) { // Shipping by weight $price = $carrier->getDeliveryPriceByWeight($product->weight, $zone); } else { // Shipping by price $price = $carrier->getDeliveryPriceByPrice($product->price, $zone); } } else { if ($carrier->shipping_method == 1) { // Shipping by weight $price = $carrier->getDeliveryPriceByWeight($product->weight, $zone); } else { if ($carrier->shipping_method == 2) { // Shipping by price $price = $carrier->getDeliveryPriceByPrice($product->price, $zone); } else { // return 0 if is an other shipping method return 0; } } } if ($carrier->shipping_handling) { //Add shipping handling fee $price += Configuration::get('PS_SHIPPING_HANDLING'); } $price += $price * Tax::getCarrierTaxRate($carrier_id) / 100; return $price; }
public function generateFlux() { if (Tools::getValue('token') == '' || Tools::getValue('token') != Configuration::get('SHOPPING_FLUX_TOKEN')) { die('Invalid Token'); } $titles = array(0 => 'id_produit', 1 => 'nom_produit', 2 => 'url_produit', 3 => 'url_image', 4 => 'description', 5 => 'description_courte', 6 => 'prix', 7 => 'prix_barre', 8 => 'frais_de_port', 9 => 'delaiLiv', 10 => 'marque', 11 => 'rayon', 12 => 'stock', 13 => 'qte_stock', 14 => 'EAN', 15 => 'poids', 16 => 'ecotaxe', 17 => 'TVA', 18 => 'Reference constructeur', 19 => 'Reference fournisseur'); echo implode("|", $titles) . "\r\n"; //For Shipping $configuration = Configuration::getMultiple(array('PS_TAX_ADDRESS_TYPE', 'PS_CARRIER_DEFAULT', 'PS_COUNTRY_DEFAULT', 'PS_LANG_DEFAULT', 'PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT')); $products = Product::getSimpleProducts($configuration['PS_LANG_DEFAULT']); $defaultCountry = new Country($configuration['PS_COUNTRY_DEFAULT'], Configuration::get('PS_LANG_DEFAULT')); $id_zone = (int) $defaultCountry->id_zone; $carrier = new Carrier((int) $configuration['PS_CARRIER_DEFAULT']); $carrierTax = Tax::getCarrierTaxRate((int) $carrier->id, (int) $this->{$configuration['PS_TAX_ADDRESS_TYPE']}); foreach ($products as $key => $produit) { $product = new Product((int) $produit['id_product'], true, $configuration['PS_LANG_DEFAULT']); //For links $link = new Link(); //For images $cover = $product->getCover($product->id); $ids = $product->id . '-' . $cover['id_image']; //For shipping if ($product->getPrice(true, NULL, 2, NULL, false, true, 1) >= (double) $configuration['PS_SHIPPING_FREE_PRICE'] and (double) $configuration['PS_SHIPPING_FREE_PRICE'] > 0) { $shipping = 0; } elseif (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) and $product->weight >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] and (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) { $shipping = 0; } else { if (isset($configuration['PS_SHIPPING_HANDLING']) and $carrier->shipping_handling) { $shipping = (double) $configuration['PS_SHIPPING_HANDLING']; } if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping += $carrier->getDeliveryPriceByWeight($product->weight, $id_zone); } else { $shipping += $carrier->getDeliveryPriceByPrice($product->getPrice(true, NULL, 2, NULL, false, true, 1), $id_zone); } $shipping *= 1 + $carrierTax / 100; $shipping = (double) Tools::ps_round((double) $shipping, 2); } $data = array(); $data[0] = $product->id; $data[1] = $product->name; $data[2] = $link->getProductLink($product); $data[3] = $link->getImageLink($product->link_rewrite, $ids, 'large'); $data[4] = $product->description; $data[5] = $product->description_short; $data[6] = $product->getPrice(true, NULL, 2, NULL, false, true, 1); $data[7] = $product->getPrice(true, NULL, 2, NULL, false, false, 1); $data[8] = $shipping; $data[9] = $carrier->delay[2]; $data[10] = $product->manufacturer_name; $data[11] = $product->category; $data[12] = $product->quantity > 0 ? 'oui' : 'non'; $data[13] = $product->quantity; $data[14] = $product->ean13; $data[15] = $product->weight; $data[16] = $product->ecotax; $data[17] = $product->tax_rate; $data[18] = $product->reference; $data[19] = $product->supplier_reference; foreach ($data as $key => $value) { $data[$key] = $this->clean($value); } echo implode("|", $data) . "\r\n"; } }
private function getPriceByPrestaShopCalculationType($carrier_shipping_method, Carrier $carrier, $cart_total, $zone, $additional_shipping_cost, $handling_charges, $is_cod_method, $order_total_price, DpdGroupConfiguration $configuration, $price_rule) { if ($carrier_shipping_method == Carrier::SHIPPING_METHOD_WEIGHT) { $carrier_price = $carrier->getDeliveryPriceByWeight($cart_total, $zone); } else { $carrier_price = $carrier->getDeliveryPriceByPrice($cart_total, $zone); } $default_currency = new Currency((int) Configuration::get('PS_CURRENCY_DEFAULT', null, null, 0)); $carrier_price = $this->convertPriceByCurrency($carrier_price, $default_currency->iso_code); $shipping_price_with_charges = $carrier_price + $additional_shipping_cost + $handling_charges; $cod_price = 0; if (!empty($price_rule) && $is_cod_method) { if ($price_rule['cod_surcharge'] !== '') { $cod_price = $this->convertPriceByCurrency($price_rule['cod_surcharge'], $price_rule['currency']); } elseif ($price_rule['cod_surcharge_percentage'] !== '') { $percentage_starting_price = $configuration->cod_percentage_calculation == DpdGroupConfiguration::COD_PERCENTAGE_CALCULATION_CART ? $order_total_price : $order_total_price + $shipping_price_with_charges; $cod_price = $this->calculateCODSurchargePercentage($percentage_starting_price, $price_rule['cod_surcharge_percentage'], $price_rule['cod_min_surcharge'], $price_rule['currency']); } } return $shipping_price_with_charges + $cod_price; }
public function getOrderShippingCostPerSellerCarrier($id_seller, $use_tax, $id_zone, $id_carrier, $carrier_amount, $carrier_weight) { $shipping_cost = 0; $carrier = new Carrier($id_carrier, $this->id_lang); if ($carrier->is_free == 1) { return 0; } if ($use_tax 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_FREE_WEIGHT')); $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)); } $free_fees_weight = 0; if (isset($configuration['PS_SHIPPING_FREE_WEIGHT'])) { $free_fees_weight = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_WEIGHT'], Currency::getCurrencyInstance((int) $this->id_currency)); } $shipping_method = $carrier->getShippingMethod(); if ($shipping_method == Carrier::SHIPPING_METHOD_PRICE and $carrier_amount >= (double) $free_fees_price and (double) $free_fees_price > 0) { } else { if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT and $carrier_weight >= (double) $free_fees_weight and (double) $free_fees_weight > 0) { } else { if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT) { $seller_shipping = $carrier->getDeliveryPriceByWeight($carrier_weight, $id_zone); $shipping_cost += $seller_shipping; } else { $seller_shipping = $carrier->getDeliveryPriceByPrice($carrier_amount, $id_zone, (int) $this->id_currency); $shipping_cost += $seller_shipping; } } } $shipping_cost += $this->getAdditionalShippingCostOfSeller($id_carrier); if ($carrier->shipping_handling) { $shipping_cost += (double) Configuration::get('PS_SHIPPING_HANDLING'); } if (isset($carrierTax)) { $shipping_cost *= 1 + $carrierTax / 100; } $shipping_cost = Tools::convertPrice($shipping_cost); return $shipping_cost; }
public function getOrderShippingCostExternal($cart) { if (!$this->soapClientExists() || !$this->checkModuleAvailability()) { return false; } $disabled_countries_ids = DpdPolandCountry::getDisabledCountriesIDs(); $id_country = (int) Tools::getValue('id_country'); if (!$id_country) { $country = Address::getCountryAndState((int) $cart->id_address_delivery); $id_country = $country['id_country']; } if (!($id_method = self::getMethodIdByCarrierId($this->id_carrier))) { self::$carriers[$this->id_carrier] = false; return false; } if (!$id_country || in_array($id_country, $disabled_countries_ids) && $id_method == _DPDPOLAND_CLASSIC_ID_) { return false; } if ($id_country) { $zone = Country::getIdZone($id_country); } else { return false; } if (!$this->id_carrier) { return false; } if ($id_country == Country::getByIso(self::POLAND_ISO_CODE) && $id_method == _DPDPOLAND_CLASSIC_ID_ || $id_country != Country::getByIso(self::POLAND_ISO_CODE) && $id_method == _DPDPOLAND_STANDARD_COD_ID_ || $id_country != Country::getByIso(self::POLAND_ISO_CODE) && $id_method == _DPDPOLAND_STANDARD_ID_) { return false; } if (isset(self::$carriers[$this->id_carrier])) { return self::$carriers[$this->id_carrier]; } $total_weight = self::convertWeight($cart->getTotalWeight()); if (Configuration::get(DpdPolandConfiguration::PRICE_CALCULATION_TYPE) == DpdPolandConfiguration::PRICE_CALCULATION_PRESTASHOP) { $carrier = new Carrier($this->id_carrier); $price = $carrier->getDeliveryPriceByWeight($total_weight, $zone); self::$carriers[$this->id_carrier] = $price; return self::$carriers[$this->id_carrier]; } $price = DpdPolandCSV::getPrice($total_weight, $id_method, $cart); if ($price === false) { return false; } $id_currency_pl = Currency::getIdByIsoCode(_DPDPOLAND_CURRENCY_ISO_, (int) $this->context->shop->id); $currency_from = new Currency((int) $id_currency_pl); $currency_to = $this->context->currency; self::$carriers[$this->id_carrier] = Tools::convertPriceFull($price, $currency_from, $currency_to); return self::$carriers[$this->id_carrier]; }
/** * Return price calculated by PrestaShop system * * @param $id_carrier string | int - carrier id * @param $id_cart string | int - cart id * @param $id_zone string | int - Zone Id 1 -> Global? * @return string - Price */ public static function systemPriceCalculate($id_carrier, $id_cart, $id_zone) { $cart = new Cart($id_cart); $total_weight = $cart->getTotalWeight(); $carrier = new Carrier($id_carrier); $price = $carrier->getDeliveryPriceByWeight($total_weight, $id_zone); return $price; }
function getCarriersByZoneID($id_zone) { global $cookie, $cart; $id_groups = array(1); $islogged = _PS_VERSION_ > '1.5' ? Context::getContext()->customer->isLogged() : $cookie->isLogged(); if ($islogged) { $customer = new Customer((int) $cookie->id_customer); $id_groups = $customer->getGroups(); } $result = Carrier::getCarriers(intval($cookie->id_lang), true, false, intval($id_zone), $id_groups, Carrier::ALL_CARRIERS); $resultsArray = array(); foreach ($result as $k => $row) { $carrier = new Carrier(intval($row['id_carrier'])); $shipping_method = $carrier->getShippingMethod(); if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT and $carrier->getMaxDeliveryPriceByWeight($id_zone) === false or $shipping_method == Carrier::SHIPPING_METHOD_PRICE and $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) { unset($result[$k]); continue; } if ($row['range_behavior']) { 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, Cart::BOTH_WITHOUT_SHIPPING), $id_zone)) { unset($result[$k]); continue; } } $row['name'] = strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME'); $method = $carrier->getShippingMethod(); $row['price'] = 0; if ($method == Carrier::SHIPPING_METHOD_PRICE) { $row['price'] = $carrier->getDeliveryPriceByPrice($cart->getOrderTotal(Cart::BOTH_WITHOUT_SHIPPING), $id_zone); } else { if ($method == Carrier::SHIPPING_METHOD_WEIGHT) { $row['price'] = $carrier->getDeliveryPriceByWeight($cart->getTotalWeight(), $id_zone); } } if ((int) $row['shipping_handling'] == 1) { $row['price'] = (double) $row['price'] + (double) Configuration::get('PS_SHIPPING_HANDLING'); } if ((int) $row['is_free']) { $row['price'] = 0; } $row['price_tax_exc'] = $row['price']; $address = new Address($cart->id_address_delivery); $tax_rate = $carrier->getTaxesRate($address); $currency = new Currency($cart->id_currency); $row['price'] = $row['price'] * $currency->conversion_rate * (1 + (double) $tax_rate / 100); $row['img'] = file_exists(_PS_SHIP_IMG_DIR_ . intval($row['id_carrier']) . '.jpg') ? _THEME_SHIP_DIR_ . intval($row['id_carrier']) . '.jpg' : ''; $resultsArray[] = $row; } return $resultsArray; }
private function getShippingPriceForProduct($product, $zone, $carrierid) { $carrier = new Carrier($carrierid); if (Configuration::get('PS_SHIPPING_METHOD') == 1) { //Shipping by weight $price = $carrier->getDeliveryPriceByWeight($product->weight, $zone); } else { //Shipping by price $price = $carrier->getDeliveryPriceByPrice($product->price, $zone); } if ($carrier->shipping_handling) { //Add shipping handling fee (frais de manutention) $price += Configuration::get('PS_SHIPPING_HANDLING'); } $taxrate = Tax::getCarrierTaxRate($carrierid); $price += $price * $taxrate / 100; return $price; }
/** * gets of a dejala carrier corresponding to $dejalaProduct */ public static function getDejalaCarrier($dejalaConfig, $dejalaProduct) { global $cookie; $electedCarrier = NULL; $totalCartWeight = floatval($dejalaProduct['max_weight']); if ($totalCartWeight <= 0) { $totalCartWeight = 3.99; } else { $totalCartWeight -= 0.01; } /** MFR090828 - compare to HT price (since DejalaCarrier has a tax_id) */ $vat_factor = 1 + $dejalaProduct['vat'] / 100; $priceTTC = round($dejalaProduct['price'] * $vat_factor + $dejalaProduct['margin'], 2); $priceHT = round($priceTTC / $vat_factor, 2); $productPrice = $priceHT; // MFR091130 - get id zone from the country used in the module (if the store zones were customized) // default (Europe) $id_zone = 1; $moduleCountryIsoCode = strtoupper($dejalaConfig->country); $countryID = Country::getByIso($moduleCountryIsoCode); if (intval($countryID)) { $id_zone = Country::getIdZone($countryID); } $allCarriers = DejalaCarrierUtils::getCarriers(intval($cookie->id_lang), true, false, $id_zone, true); $electedCarrier = NULL; foreach ($allCarriers as $carrier) { if ($carrier['name'] == 'dejala' && $carrier['range_behavior'] && Configuration::get('PS_SHIPPING_METHOD') && Carrier::checkDeliveryPriceByWeight($carrier['id_carrier'], $totalCartWeight, $id_zone)) { $mCarrier = new Carrier($carrier['id_carrier']); if ($productPrice == $mCarrier->getDeliveryPriceByWeight($totalCartWeight, $id_zone)) { if ($electedCarrier == NULL) { $electedCarrier = $mCarrier; } else { if ($mCarrier->id < $electedCarrier->id) { $electedCarrier = $mCarrier; } } } } } return $electedCarrier; }