/** * Return price with currency sign for a given product * * @param float $price Product price * @param object|array $currency Current currency (object, id_currency, NULL => context currency) * @return string Price correctly formatted (sign, decimal separator...) */ public static function displayPrice($price, $currency = null, $no_utf8 = false, JeproshopContext $context = null) { if (!is_numeric($price)) { return $price; } if (!$context) { $context = JeproshopContext::getContext(); } if ($currency === null) { $currency = $context->currency; } elseif (is_int($currency)) { // if you modified this function, don't forget to modify the Javascript function formatCurrency (in Tools.js) $currency = JeproshopCurrencyModelCurrency::getCurrencyInstance((int) $currency); } if (is_object($currency)) { $c_char = $currency->sign; $c_format = $currency->format; $c_decimals = (int) $currency->decimals * COM_JEPROSHOP_PRICE_DISPLAY_PRECISION; $c_blank = $currency->blank; } else { return false; } $blank = $c_blank ? ' ' : ''; $ret = 0; if ($is_negative = $price < 0) { $price *= -1; } $price = JeproshopTools::roundPrice($price, $c_decimals); /* * If the language is RTL and the selected currency format contains spaces as thousands separator * then the number will be printed in reverse since the space is interpreted as separating words. * To avoid this we replace the currency format containing a space with the one containing a comma (,) as thousand * separator when the language is RTL. * * TODO: This is not ideal, a currency format should probably be tied to a language, not to a currency. */ if ($c_format == 2 && $context->language->is_rtl == 1) { $c_format = 4; } switch ($c_format) { /* X 0,000.00 */ case 1: $ret = $c_char . $blank . number_format($price, $c_decimals, '.', ','); break; /* 0 000,00 X*/ /* 0 000,00 X*/ case 2: $ret = number_format($price, $c_decimals, ',', ' ') . $blank . $c_char; break; /* X 0.000,00 */ /* X 0.000,00 */ case 3: $ret = $c_char . $blank . number_format($price, $c_decimals, ',', '.'); break; /* 0,000.00 X */ /* 0,000.00 X */ case 4: $ret = number_format($price, $c_decimals, '.', ',') . $blank . $c_char; break; /* X 0'000.00 Added for the switzerland currency */ /* X 0'000.00 Added for the switzerland currency */ case 5: $ret = $c_char . $blank . number_format($price, $c_decimals, '.', "'"); break; } if ($is_negative) { $ret = '-' . $ret; } if ($no_utf8) { return str_replace('�', chr(128), $ret); } return $ret; }
/** * Return available currencies * * @param bool $object * @param bool $published * @param bool $group_by * @return array Currencies */ public static function getStaticCurrencies($object = false, $published = true, $group_by = false) { $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_currency') . " AS currency " . JeproshopShopModelShop::addSqlAssociation('currency'); $query .= " WHERE " . $db->quoteName('deleted') . " = 0" . ($published ? " AND currency." . $db->quoteName('published') . " = 1" : ""); $query .= ($group_by ? " GROUP BY currency." . $db->quoteName('currency_id') : "") . " ORDER BY " . $db->quoteName('name') . " ASC"; $db->setQuery($query); $tab = $db->loadObjectList(); if ($object) { foreach ($tab as $key => $currency) { $tab[$key] = JeproshopCurrencyModelCurrency::getCurrencyInstance($currency->currency_id); } } return $tab; }
/** * This function returns the total cart amount * * Possible values for $type: * JeproshopCartModelCart::ONLY_PRODUCTS * JeproshopCartModelCart::ONLY_DISCOUNTS * JeproshopCartModelCart::BOTH * JeproshopCartModelCart::BOTH_WITHOUT_SHIPPING * JeproshopCartModelCart::ONLY_SHIPPING * JeproshopCartModelCart::ONLY_WRAPPING * JeproshopCartModelCart::ONLY_PRODUCTS_WITHOUT_SHIPPING * JeproshopCartModelCart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING * * @param boolean $withTaxes With or without taxes * @param integer $type Total type * @param null $products * @param null $carrier_id * @param boolean $use_cache Allow using cache of the method CartRule::getContextualValue * @return float Order total */ public function getOrderTotal($withTaxes = true, $type = JeproshopCartModelCart::BOTH, $products = null, $carrier_id = null, $use_cache = true) { if (!$this->cart_id) { return 0; } $type = (int) $type; $array_type = array(JeproshopCartModelCart::ONLY_PRODUCTS, JeproshopCartModelCart::ONLY_DISCOUNTS, JeproshopCartModelCart::BOTH, JeproshopCartModelCart::BOTH_WITHOUT_SHIPPING, JeproshopCartModelCart::ONLY_SHIPPING, JeproshopCartModelCart::ONLY_WRAPPING, JeproshopCartModelCart::ONLY_PRODUCTS_WITHOUT_SHIPPING, JeproshopCartModelCart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING); // Define virtual context to prevent case where the cart is not the in the global context $virtual_context = JeproshopContext::getContext()->cloneContext(); $virtual_context->cart = $this; if (!in_array($type, $array_type)) { die(Tools::displayError()); } $with_shipping = in_array($type, array(JeproshopCartModelCart::BOTH, JeproshopCartModelCart::ONLY_SHIPPING)); // if cart rules are not used if ($type == JeproshopCartModelCart::ONLY_DISCOUNTS && !JeproshopCartRuleModelCartRule::isFeaturePublished()) { return 0; } // no shipping cost if is a cart with only virtual products $virtual = $this->isVirtualCart(); if ($virtual && $type == JeproshopCartModelCart::ONLY_SHIPPING) { return 0; } if ($virtual && $type == JeproshopCartModelCart::BOTH) { $type = JeproshopCartModelCart::BOTH_WITHOUT_SHIPPING; } if ($with_shipping || $type == JeproshopCartModelCart::ONLY_DISCOUNTS) { if (is_null($products) && is_null($carrier_id)) { $shipping_fees = $this->getTotalShippingCost(null, (bool) $withTaxes); } else { $shipping_fees = $this->getPackageShippingCost($carrier_id, (bool) $withTaxes, null, $products); } } else { $shipping_fees = 0; } if ($type == JeproshopCartModelCart::ONLY_SHIPPING) { return $shipping_fees; } if ($type == JeproshopCartModelCart::ONLY_PRODUCTS_WITHOUT_SHIPPING) { $type = JeproshopCartModelCart::ONLY_PRODUCTS; } $param_product = true; if (is_null($products)) { $param_product = false; $products = $this->getProducts(); } if ($type == JeproshopCartModelCart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING) { foreach ($products as $key => $product) { if ($product->is_virtual) { unset($products[$key]); } } $type = JeproshopCartModelCart::ONLY_PRODUCTS; } $order_total = 0; if (JeproshopTaxModelTax::taxExcludedOption()) { $with_taxes = false; } foreach ($products as $product) { // products refer to the cart details if ($virtual_context->shop->shop_id != $product->shop_id) { $virtual_context->shop = new JeproshopShopModelShop((int) $product->shop_id); } if (JeproshopSettingModelSetting::getValue('PS_TAX_ADDRESS_TYPE') == 'address_invoice_id') { $address_id = (int) $this->address_invoice_id; } else { $address_id = (int) $product->address_delivery_id; } // Get delivery address of the product from the cart if (!JeproshopAddressModelAddress::addressExists($address_id)) { $address_id = null; } $null = null; if ($this->_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED) { // Here taxes are computed only once the quantity has been applied to the product price $price = JeproshopProductModelProduct::getStaticPrice((int) $product->product_id, false, (int) $product->product_attribute_id, 2, null, false, true, $product->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, $address_id, $null, true, true, $virtual_context); $total_ecotax = $product->ecotax * (int) $product->cart_quantity; $total_price = $price * (int) $product->cart_quantity; if ($withTaxes) { $product_tax_rate = (double) JeproshopTaxModelTax::getProductTaxRate((int) $product->product_id, (int) $address_id, $virtual_context); $product_eco_tax_rate = JeproshopTaxModelTax::getProductEcotaxRate((int) $address_id); $total_price = ($total_price - $total_ecotax) * (1 + $product_tax_rate / 100); $total_ecotax = $total_ecotax * (1 + $product_eco_tax_rate / 100); $total_price = JeproshopTools::roundPrice($total_price + $total_ecotax, 2); } } else { if ($withTaxes) { $price = JeproshopProductModelProduct::getStaticPrice((int) $product->product_id, true, (int) $product->product_attribute_id, 2, null, false, true, $product->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $null, true, true, $virtual_context); } else { $price = JeproshopProductModelProduct::getStaticPrice((int) $product->product_id, false, (int) $product->product_attribute_id, 2, null, false, true, $product->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $null, true, true, $virtual_context); } $total_price = JeproshopTools::roundPrice($price * (int) $product->cart_quantity, 2); } $order_total += $total_price; } $order_total_products = $order_total; if ($type == JeproshopCartModelCart::ONLY_DISCOUNTS) { $order_total = 0; } // Wrapping Fees $wrapping_fees = 0; if ($this->gift) { $wrapping_fees = JeproshopTools::convertPrice(JeproshopTools::roundPrice($this->getGiftWrappingPrice($withTaxes), 2), JeproshopCurrencyModelCurrency::getCurrencyInstance((int) $this->currency_id)); } if ($type == JeproshopCartModelCart::ONLY_WRAPPING) { return $wrapping_fees; } $order_total_discount = 0; if (!in_array($type, array(JeproshopCartModelCart::ONLY_SHIPPING, JeproshopCartModelCart::ONLY_PRODUCTS)) && JeproshopCartRuleModelCartRule::isFeaturePublished()) { // First, retrieve the cart rules associated to this "getOrderTotal" if ($with_shipping || $type == JeproshopCartModelCart::ONLY_DISCOUNTS) { $cart_rules = $this->getCartRules(JeproshopCartRuleModelCartRule::FILTER_ACTION_ALL); } else { $cart_rules = $this->getCartRules(CartRule::FILTER_ACTION_REDUCTION); // Cart Rules array are merged manually in order to avoid doubles foreach ($this->getCartRules(JeproshopCartRuleModelCartRule::FILTER_ACTION_GIFT) as $tmp_cart_rule) { $flag = false; foreach ($cart_rules as $cart_rule) { if ($tmp_cart_rule->cart_rule_id == $cart_rule->cart_rule_id) { $flag = true; } } if (!$flag) { $cart_rules[] = $tmp_cart_rule; } } } $id_address_delivery = 0; if (isset($products[0])) { $id_address_delivery = is_null($products) ? $this->address_delivery_id : $products[0]->address_delivery_id; } $package = array('id_carrier' => $carrier_id, 'id_address' => $id_address_delivery, 'products' => $products); // Then, calculate the contextual value for each one foreach ($cart_rules as $cart_rule) { // If the cart rule offers free shipping, add the shipping cost if (($with_shipping || $type == Cart::ONLY_DISCOUNTS) && $cart_rule['obj']->free_shipping) { $order_total_discount += Tools::ps_round($cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_SHIPPING, $param_product ? $package : null, $use_cache), 2); } // If the cart rule is a free gift, then add the free gift value only if the gift is in this package if ((int) $cart_rule['obj']->gift_product) { $in_order = false; if (is_null($products)) { $in_order = true; } else { foreach ($products as $product) { if ($cart_rule['obj']->gift_product == $product['id_product'] && $cart_rule['obj']->gift_product_attribute == $product['id_product_attribute']) { $in_order = true; } } } if ($in_order) { $order_total_discount += $cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_GIFT, $package, $use_cache); } } // If the cart rule offers a reduction, the amount is prorated (with the products in the package) if ($cart_rule['obj']->reduction_percent > 0 || $cart_rule['obj']->reduction_amount > 0) { $order_total_discount += Tools::ps_round($cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_REDUCTION, $package, $use_cache), 2); } } $order_total_discount = min(JeproshopTools::roundPrice($order_total_discount, 2), $wrapping_fees + $order_total_products + $shipping_fees); $order_total -= $order_total_discount; } if ($type == JeproshopCartModelCart::BOTH) { $order_total += $shipping_fees + $wrapping_fees; } if ($order_total < 0 && $type != JeproshopCartModelCart::ONLY_DISCOUNTS) { return 0; } if ($type == JeproshopCartModelCart::ONLY_DISCOUNTS) { return $order_total_discount; } return JeproshopTools::roundPrice((double) $order_total, 2); }
/** * Return package shipping cost * * @param integer $carrier_id Carrier ID (default : current carrier) * @param boolean $use_tax * @param JeproshopCountryModelCountry $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($carrier_id = null, $use_tax = true, JeproshopCountryModelCountry $default_country = null, $product_list = null, $zone_id = null) { if ($this->isVirtualCart()) { return 0; } if (!$default_country) { $default_country = JeproshopContext::getContext()->country; } $complete_product_list = $this->getProducts(); if (is_null($product_list)) { $products = $complete_product_list; } else { $products = $product_list; } if (JeproshopSettingModelSetting::getValue('tax_address_type') == 'address_invoice_id') { $address_id = (int) $this->address_invoice_id; } elseif (count($product_list)) { $prod = current($product_list); $address_id = (int) $prod->address_delivery_id; } else { $address_id = null; } if (!JeproshopAddressModelAddress::addressExists($address_id)) { $address_id = null; } $cache_id = 'get_package_shipping_cost_' . (int) $this->cart_id . '_' . (int) $address_id . '_' . (int) $carrier_id . '_' . (int) $use_tax . '_' . (int) $default_country->country_id; if ($products) { foreach ($products as $product) { $cache_id .= '_' . (int) $product->product_id . '_' . (int) $product->product_attribute_id; } } if (JeproshopCache::isStored($cache_id)) { return JeproshopCache::retrieve($cache_id); } // Order total in default currency without fees $order_total = $this->getOrderTotal(true, JeproshopCartModelCart::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)) { JeproshopCache::store($cache_id, $shipping_cost); return $shipping_cost; } if (!isset($zone_id)) { // Get id zone if (!$this->isMultiAddressDelivery() && isset($this->address_delivery_id) && $this->address_delivery_id && JeproshopCustomerModelCustomer::customerHasAddress($this->customer_id, $this->address_delivery_id)) { $zone_id = JeproshopAddressModelAddress::getZoneIdByAddressId((int) $this->address_delivery_id); } else { if (!JeproshopValidator::isLoadedObject($default_country, 'country_id')) { $default_country = new Country(JeproshopSettingModelSeting::getValue('PS_COUNTRY_DEFAULT'), JeproshopSettingModelSeting::getValue('PS_LANG_DEFAULT')); } $zone_id = (int) $default_country->zone_id; } } if ($carrier_id && !$this->isCarrierInRange((int) $carrier_id, (int) $zone_id)) { $carrier_id = ''; } if (empty($carrier_id) && $this->isCarrierInRange((int) JeproshopSettingModelSeting::getValue('default_carrier'), (int) $zone_id)) { $carrier_id = (int) JeproshopSettingModelSeting::getValue('default_carrier'); } $total_package_without_shipping_tax_inc = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list); if (empty($carrier_id)) { if ((int) $this->customer_id) { $customer = new JeproshopCustomerModelCustomer((int) $this->customer_id); $result = JeproshopCarrierModelCarrier::getCarriers((int) JeproshopSettingModelSeting::getValue('default_lang'), true, false, (int) $zone_id, $customer->getGroups()); unset($customer); } else { $result = JeproshopCarrierModelCarrier::getCarriers((int) JeproshopSettingModelSeting::getValue('default_lang'), true, false, (int) $zone_id); } foreach ($result as $k => $row) { if ($row->carrier_id == JeproshopSettingModelSeting::getValue('default_carrier')) { continue; } if (!isset(self::$_carriers[$row->carrier_id])) { self::$_carriers[$row->carrier_id] = new JeproshopCarrierModelCarrier((int) $row->carrier_id); } $carrier = self::$_carriers[$row->carrier_id]; // Get only carriers that are compliant with shipping method if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD && $carrier->getMaxDeliveryPriceByWeight((int) $zone_id) === false || $carrier->getShippingMethod() == JeproshopCarrierModelCarrier::PRICE_SHIPPING_METHOD && $carrier->getMaxDeliveryPriceByPrice((int) $zone_id) === false) { unset($result[$k]); continue; } // If out-of-range behavior carrier is set on "Deactivated carrier" if ($row->range_behavior) { $check_delivery_price_by_weight = JeproshopCarrierModelCarrier::checkDeliveryPriceByWeight($row->carrier_id, $this->getTotalWeight(), (int) $zone_id); $total_order = $total_package_without_shipping_tax_inc; $check_delivery_price_by_price = JeproshopCarrierModelCarrier::checkDeliveryPriceByPrice($row->carrier_id, $total_order, (int) $zone_id, (int) $this->currency_id); // Get only carriers that have a range compatible with cart if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == JeproshopCarrierModelCarrier::PRICE_SHIPPING_METHOD && !$check_delivery_price_by_price) { unset($result[$k]); continue; } } if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD) { $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), (int) $zone_id); } else { $shipping = $carrier->getDeliveryPriceByPrice($order_total, (int) $zone_id, (int) $this->currency_id); } if (!isset($min_shipping_price)) { $min_shipping_price = $shipping; } if ($shipping <= $min_shipping_price) { $carrier_id = (int) $row->carrier_id; $min_shipping_price = $shipping; } } } if (empty($carrier_id)) { $carrier_id = JeproshopSettingModelSeting::getValue('default_carrier'); } if (!isset(self::$_carriers[$carrier_id])) { self::$_carriers[$carrier_id] = new JeproshopCarrierModelCarrier((int) $carrier_id, JeproshopSettingModelSeting::getValue('default_lang')); } $carrier = self::$_carriers[$carrier_id]; // No valid Carrier or $carrier_id <= 0 ? if (!JeproshopValidator::isLoadedObject($carrier, 'carrier_id')) { JeproshopCache::store($cache_id, 0); return 0; } if (!$carrier->published) { JeproshopCache::store($cache_id, $shipping_cost); return $shipping_cost; } // Free fees if free carrier if ($carrier->is_free == 1) { JeproshopCache::store($cache_id, 0); return 0; } // Select carrier tax if ($use_tax && !JeproshopTaxModelTax::excludedTaxOption()) { $address = JeproshopAddressModelAddress::initialize((int) $address_id); $carrier_tax = $carrier->getTaxesRate($address); } $configuration = JeproshopSettingModelSeting::getValueMultiple(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 = JeproshopValidator::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], JeproshopCurrencyModelCurrency::getCurrencyInstance((int) $this->currency_id)); } $orderTotalWithDiscounts = $this->getOrderTotal(true, JeproshopCartModelCart::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) { JeproshopCache::store($cache_id, $shipping_cost); return $shipping_cost; } // Get shipping cost using correct method if ($carrier->range_behavior) { if (!isset($zone_id)) { // Get id zone if (isset($this->address_delivery_id) && $this->address_delivery_id && JeproshopCustomerModelCustomer::customerHasAddress($this->customer_id, $this->address_delivery_id)) { $zone_id = JeproshopAddressModelAddress::getZoneIdByAddressId((int) $this->address_delivery_id); } else { $zone_id = (int) $default_country->zone_id; } } if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD && !JeproshopCarrierModelCarrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), (int) $zone_id) || $carrier->getShippingMethod() == JeproshopCarrierModelCarrier::PRICE_SHIPPING_METHOD && !JeproshopCarrierModelCarrier::checkDeliveryPriceByPrice($carrier->id, $total_package_without_shipping_tax_inc, $zone_id, (int) $this->currency_id)) { $shipping_cost += 0; } else { if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $zone_id); } else { // by price $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $zone_id, (int) $this->currency_id); } } } else { if ($carrier->getShippingMethod() == JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD) { $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $zone_id); } else { $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $zone_id, (int) $this->currency_id); } } // 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 = JeproshopValidator::convertPrice($shipping_cost, JeproshopCurrencyModelCurrency::getCurrencyInstance((int) $this->currency_id)); /*/get external shipping cost from module if ($carrier->shipping_external) { $module_name = $carrier->external_module_name; $module = Module::getInstanceByName($module_name); if (JeproshopValidator::isLoadedObject($module)) { if (array_key_exists('carrier_id', $module)) $module->carrier_id = $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) { JeproshopCache::store($cache_id, false); return false; } } else { JeproshopCache::store($cache_id, false); return false; } } */ // Apply tax if ($use_tax && isset($carrier_tax)) { $shipping_cost *= 1 + $carrier_tax / 100; } $shipping_cost = (double) JeproshopValidator::roundPrice((double) $shipping_cost, 2); JeproshopCache::store($cache_id, $shipping_cost); return $shipping_cost; }