diff --git a/classes/Carrier.php b/classes/Carrier.php index bafdc7bb4..55f665341 100644 --- a/classes/Carrier.php +++ b/classes/Carrier.php @@ -1124,6 +1124,10 @@ class CarrierCore extends ObjectModel { $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 { diff --git a/classes/Cart.php b/classes/Cart.php index 96bce49db..eb01cb4f4 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -3307,4 +3307,31 @@ class CartCore extends ObjectModel ); } } + + /** + * Get all the ids of the delivery addresses without carriers + * + * @param bool $return_collection Return a collection + * + * @return array Array of address id or of address object + */ + public function getDeliveryAddressesWithoutCarriers($return_collection = false) + { + $addresses_without_carriers = array(); + foreach ($this->getProducts() as $product) + { + if (!in_array($product['id_address_delivery'], $addresses_without_carriers) + && !count(Carrier::getAvailableCarrierList(new Product($product['id_product']), null, $product['id_address_delivery']))) + $addresses_without_carriers[] = $product['id_address_delivery']; + } + if (!$return_collection) + return $addresses_without_carriers; + else + { + $addresses_instance_without_carriers = array(); + foreach ($addresses_without_carriers as $id_address) + $addresses_instance_without_carriers[] = new Address($id_address); + return $addresses_instance_without_carriers; + } + } } diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 6af39466c..2d051fca3 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -146,9 +146,12 @@ abstract class PaymentModuleCore extends Module foreach ($packageByAddress as $id_package => $package) { $product_list = $package['product_list']; - $carrier = new Carrier($package['id_carrier'], $cart->id_lang); $order = new Order(); - $order->id_carrier = (int)$carrier->id; + if (isset($package['id_carrier'])) + { + $carrier = new Carrier($package['id_carrier'], $cart->id_lang); + $order->id_carrier = (int)$carrier->id; + } $order->id_customer = (int)$cart->id_customer; $order->id_address_invoice = (int)$cart->id_address_invoice; $order->id_address_delivery = (int)$id_address; diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index 02901010c..7c33aa810 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -126,6 +126,12 @@ class CartControllerCore extends FrontController $old_id_address_delivery = (int)Tools::getValue('old_id_address_delivery'); $new_id_address_delivery = (int)Tools::getValue('new_id_address_delivery'); + if (!count(Carrier::getAvailableCarrierList(new Product($this->id_product), null, $new_id_address_delivery))) + die(Tools::jsonEncode(array( + 'hasErrors' => true, + 'error' => Tools::displayError('It\'s not possible to deliver this product to the selected address.', false), + ))); + $this->context->cart->setProductAddressDelivery( $this->id_product, $this->id_product_attribute, diff --git a/controllers/front/OrderController.php b/controllers/front/OrderController.php index 02805d6be..1ef10b3f9 100644 --- a/controllers/front/OrderController.php +++ b/controllers/front/OrderController.php @@ -238,9 +238,16 @@ class OrderControllerCore extends ParentOrderController $this->context->cart->setNoMultishipping(); // Add checking for all addresses - - if (!Tools::isSubmit('id_address_delivery') || !Address::isCountryActiveById((int)Tools::getValue('id_address_delivery'))) - $this->errors[] = Tools::displayError('This address is not in a valid area.'); + $address_without_carriers = $this->context->cart->getDeliveryAddressesWithoutCarriers(); + if (count($address_without_carriers)) + { + if (count($address_without_carriers) > 1) + $this->errors[] = sprintf(Tools::displayError('There are no carriers that deliver to some addresses you selected.')); + elseif ($this->context->cart->isMultiAddressDelivery()) + $this->errors[] = sprintf(Tools::displayError('There are no carriers that deliver to one of the address you selected.')); + else + $this->errors[] = sprintf(Tools::displayError('There are no carriers that deliver to the address you selected.')); + } else { $this->context->cart->id_address_delivery = (int)Tools::getValue('id_address_delivery'); diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index a498c7895..817552752 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -197,7 +197,6 @@ class OrderOpcControllerCore extends ParentOrderController if (!count($this->errors)) { - $result = $this->_getCarrierList(); // Wrapping fees $wrapping_fees = (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')); $wrapping_fees_tax = new Tax((int)(Configuration::get('PS_GIFT_WRAPPING_TAX'))); @@ -213,7 +212,10 @@ class OrderOpcControllerCore extends ParentOrderController } } if (count($this->errors)) - die('{"hasError" : true, "errors" : ["'.implode('\',\'', $this->errors).'"]}'); + die(Tools::jsonEncode(array( + 'hasError' => true, + 'errors' => $this->errors + ))); } die(Tools::displayError()); break; @@ -504,7 +506,8 @@ class OrderOpcControllerCore extends ParentOrderController if (count($this->errors)) return array( 'hasError' => true, - 'errors' => $this->errors + 'errors' => $this->errors, + 'carrier_block' => $this->context->smarty->fetch(_PS_THEME_DIR_.'order-carrier.tpl') ); } diff --git a/themes/default/js/cart-summary.js b/themes/default/js/cart-summary.js index 4d77e745d..3fe4a8255 100644 --- a/themes/default/js/cart-summary.js +++ b/themes/default/js/cart-summary.js @@ -99,28 +99,37 @@ function changeAddressDelivery(obj) +'&allow_refresh=1', success: function(jsonData) { - // The product exist - if ($('#product_'+id_product+'_'+id_product_attribute+'_0_'+new_id_address_delivery).length) + if (typeof(jsonData.hasErrors) != 'undefined' && jsonData.hasErrors) { - updateCustomizedDatas(jsonData.customizedDatas); - updateCartSummary(jsonData.summary); - updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); - updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); - if (typeof(getCarrierListAndUpdate) != 'undefined') - getCarrierListAndUpdate(); - - // @todo reverse the remove order - // This effect remove the current line, but it's better to remove the other one, and refresshing this one - $('#product_'+id_product+'_'+id_product_attribute+'_0_'+old_id_address_delivery).remove(); - - // @todo improve customization upgrading - $('.product_'+id_product+'_'+id_product_attribute+'_0_'+old_id_address_delivery).remove(); + alert(jsonData.error); + // Reset the old address + $('#select_address_delivery_'+id_product+'_'+id_product_attribute+'_'+old_id_address_delivery).val(old_id_address_delivery); + } + else + { + // The product exist + if ($('#product_'+id_product+'_'+id_product_attribute+'_0_'+new_id_address_delivery).length) + { + updateCustomizedDatas(jsonData.customizedDatas); + updateCartSummary(jsonData.summary); + updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); + updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); + if (typeof(getCarrierListAndUpdate) != 'undefined') + getCarrierListAndUpdate(); + + // @todo reverse the remove order + // This effect remove the current line, but it's better to remove the other one, and refresshing this one + $('#product_'+id_product+'_'+id_product_attribute+'_0_'+old_id_address_delivery).remove(); + + // @todo improve customization upgrading + $('.product_'+id_product+'_'+id_product_attribute+'_0_'+old_id_address_delivery).remove(); + } + + if (window.ajaxCart !== undefined) + ajaxCart.refresh(); + updateAddressId(id_product, id_product_attribute, old_id_address_delivery, new_id_address_delivery); + cleanSelectAddressDelivery(); } - - if (window.ajaxCart !== undefined) - ajaxCart.refresh(); - updateAddressId(id_product, id_product_attribute, old_id_address_delivery, new_id_address_delivery); - cleanSelectAddressDelivery(); } }); } @@ -192,6 +201,7 @@ function changeAddressDelivery(obj) } }); } + return true; } function updateAddressId(id_product, id_product_attribute, old_id_address_delivery, id_address_delivery, line) diff --git a/themes/default/order-carrier.tpl b/themes/default/order-carrier.tpl index 97c059d66..ecc512827 100644 --- a/themes/default/order-carrier.tpl +++ b/themes/default/order-carrier.tpl @@ -201,11 +201,12 @@
- {if $cart->isMultiAddressDelivery()}
- {l s='There are no carriers available that deliver to some of your addresses.'}
- {else}
- {l s='There are no carriers available that deliver to this address.'}
- {/if}
+ {foreach $cart->getDeliveryAddressesWithoutCarriers(true) as $address}
+ {l s='No carriers available for the address "%s".' sprintf=$address->alias}
+ {if !$address@last}
+
+ {/if}
+ {/foreach}