diff --git a/classes/Carrier.php b/classes/Carrier.php index df57179cb..ebe39f9e9 100644 --- a/classes/Carrier.php +++ b/classes/Carrier.php @@ -565,8 +565,8 @@ class CarrierCore extends ObjectModel } $row['name'] = (strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME')); - $row['price'] = ($shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getPackageShippingCost((int)$row['id_carrier'])); - $row['price_tax_exc'] = ($shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getPackageShippingCost((int)$row['id_carrier'], false)); + $row['price'] = ($shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getPackageShippingCost((int)$row['id_carrier'], true, null, null, $id_zone)); + $row['price_tax_exc'] = ($shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getPackageShippingCost((int)$row['id_carrier'], false, null, null, $id_zone)); $row['img'] = file_exists(_PS_SHIP_IMG_DIR_.(int)$row['id_carrier']).'.jpg' ? _THEME_SHIP_DIR_.(int)$row['id_carrier'].'.jpg' : ''; // If price is false, then the carrier is unavailable (carrier module) diff --git a/classes/Cart.php b/classes/Cart.php index 7fd6c9a8d..792c0d490 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -2393,11 +2393,13 @@ class CartCore extends ObjectModel */ public function getTotalShippingCost($delivery_option = null, $use_tax = true, Country $default_country = null) { + if(isset(Context::getContext()->cookie->id_country)) + $default_country = new Country(Context::getContext()->cookie->id_country); if (is_null($delivery_option)) $delivery_option = $this->getDeliveryOption($default_country, false, false); $total_shipping = 0; - $delivery_option_list = $this->getDeliveryOptionList(); + $delivery_option_list = $this->getDeliveryOptionList($default_country); foreach ($delivery_option as $id_address => $key) { if (!isset($delivery_option_list[$id_address]) || !isset($delivery_option_list[$id_address][$key])) @@ -2465,7 +2467,7 @@ class CartCore extends ObjectModel * * @return float Shipping total */ - public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null) + public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null) { if ($this->isVirtualCart()) return 0; @@ -2511,19 +2513,22 @@ class CartCore extends ObjectModel return $shipping_cost; } - // Get id zone - if (!$this->isMultiAddressDelivery() - && isset($this->id_address_delivery) // Be carefull, id_address_delivery is not usefull one 1.5 - && $this->id_address_delivery - && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery - )) - $id_zone = Address::getZoneById((int)$this->id_address_delivery); - else + if(!isset($id_zone)) { - 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; + // Get id zone + if (!$this->isMultiAddressDelivery() + && isset($this->id_address_delivery) // Be carefull, id_address_delivery is not usefull one 1.5 + && $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)) @@ -2658,13 +2663,16 @@ class CartCore extends ObjectModel // 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; + 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; + } $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight((int)$carrier->id, $this->getTotalWeight(), (int)$id_zone); diff --git a/controllers/front/OrderController.php b/controllers/front/OrderController.php index 08bc08b65..1ffdd1dac 100644 --- a/controllers/front/OrderController.php +++ b/controllers/front/OrderController.php @@ -39,6 +39,8 @@ class OrderControllerCore extends ParentOrderController parent::init(); $this->step = (int)(Tools::getValue('step')); + if (!$this->nbProducts) + $this->step = -1; // If some products have disappear if (!$this->context->cart->checkQuantities()) diff --git a/controllers/front/ParentOrderController.php b/controllers/front/ParentOrderController.php index 9efcf582c..039f36e7c 100644 --- a/controllers/front/ParentOrderController.php +++ b/controllers/front/ParentOrderController.php @@ -241,7 +241,15 @@ class ParentOrderControllerCore extends FrontController $key = Cart::desintifier(Tools::getValue('id_carrier')); foreach ($delivery_option_list as $id_address => $options) if (isset($options[$key])) + { + $this->context->cart->id_carrier = (int)Tools::getValue('id_carrier'); $this->context->cart->setDeliveryOption(array($id_address => $key)); + if(isset($this->context->cookie->id_country)) + unset($this->context->cookie->id_country); + if(isset($this->context->cookie->id_state)) + unset($this->context->cookie->id_state); + + } } } diff --git a/modules/carriercompare/carriercompare.php b/modules/carriercompare/carriercompare.php index b3e6a29ec..2f581a64b 100755 --- a/modules/carriercompare/carriercompare.php +++ b/modules/carriercompare/carriercompare.php @@ -104,6 +104,9 @@ class CarrierCompare extends Module { if (!$this->isModuleAvailable()) return; + + if (!isset($this->context->cart) || !$this->context->cart->nbProducts) + return; $protocol = (Configuration::get('PS_SSL_ENABLED') || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://'; @@ -117,12 +120,33 @@ class CarrierCompare extends Module $refresh_method = Configuration::get('SE_RERESH_METHOD'); + if(isset($this->context->cookie->id_country) && $this->context->cookie->id_country > 0) + $id_country = (int)$this->context->cookie->id_country; + if(!isset($id_country)) + $id_country = (isset($this->context->customer->geoloc_id_country) ? (int)$this->context->customer->geoloc_id_country : (int)Configuration::get('PS_COUNTRY_DEFAULT')); + if (isset($this->context->customer->id) && $this->context->customer->id && isset($this->context->cart->id_address_delivery) && $this->context->cart->id_address_delivery) + { + $address = new Address((int)($this->context->cart->id_address_delivery)); + $id_country = (int)$address->id_country; + } + + + if(isset($this->context->cookie->id_state) && $this->context->cookie->id_state > 0) + $id_state = (int)$this->context->cookie->id_state; + if(!isset($id_state)) + $id_state = (isset($this->context->customer->geoloc_id_state) ? (int)$this->context->customer->geoloc_id_state : 0); + + if(isset($this->context->cookie->postcode) && $this->context->cookie->postcode > 0) + $zipcode = Tools::safeOutput($this->context->cookie->postcode); + if(!isset($zipcode)) + $zipcode = (isset($this->context->customer->geoloc_postcode) ? $this->context->customer->geoloc_postcode : ''); + $this->smarty->assign(array( 'countries' => Country::getCountries((int)$this->context->cookie->id_lang, true), 'id_carrier' => ($params['cart']->id_carrier ? $params['cart']->id_carrier : Configuration::get('PS_CARRIER_DEFAULT')), - 'id_country' => (isset($this->context->customer->geoloc_id_country) ? $this->context->customer->geoloc_id_country : Configuration::get('PS_COUNTRY_DEFAULT')), - 'id_state' => (isset($this->context->customer->geoloc_id_state) ? $this->context->customer->geoloc_id_state : 0), - 'zipcode' => (isset($this->context->customer->geoloc_postcode) ? $this->context->customer->geoloc_postcode : ''), + 'id_country' => $id_country, + 'id_state' => $id_state, + 'zipcode' => $zipcode, 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, @@ -162,14 +186,14 @@ class CarrierCompare extends Module $id_zone = State::getIdZone($id_state); if (!$id_zone) $id_zone = Country::getIdZone($id_country); - + // Need to set the infos for carrier module ! $this->context->cookie->id_country = $id_country; $this->context->cookie->id_state = $id_state; $this->context->cookie->postcode = $zipcode; $carriers = Carrier::getCarriersForOrder((int)$id_zone); - + return (sizeof($carriers) ? $carriers : array()); }