diff --git a/classes/Cart.php b/classes/Cart.php index 792c0d490..a4a555450 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -2837,8 +2837,8 @@ class CartCore extends ObjectModel $invoice = new Address((int)$this->id_address_invoice); // New layout system with personalization fields + $formatted_addresses['delivery'] = AddressFormat::getFormattedLayoutData($delivery); $formatted_addresses['invoice'] = AddressFormat::getFormattedLayoutData($invoice); - $formatted_addresses['delivery'] = AddressFormat::getFormattedLayoutData($delivery); $total_tax = $this->getOrderTotal() - $this->getOrderTotal(false); diff --git a/classes/Customer.php b/classes/Customer.php index 4d953a385..f8a01c5ce 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -412,16 +412,17 @@ class CustomerCore extends ObjectModel */ public static function customerHasAddress($id_customer, $id_address) { - if (!array_key_exists($id_customer, self::$_customerHasAddress)) + $key = (int)$id_customer.'-'.(int)$id_address; + if (!array_key_exists($id_address, self::$_customerHasAddress)) { - self::$_customerHasAddress[$id_customer] = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' + self::$_customerHasAddress[$key] = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT `id_address` FROM `'._DB_PREFIX_.'address` WHERE `id_customer` = '.(int)$id_customer.' AND `id_address` = '.(int)$id_address.' AND `deleted` = 0'); } - return self::$_customerHasAddress[$id_customer]; + return self::$_customerHasAddress[$key]; } public static function resetAddressCache($id_customer) diff --git a/themes/default/js/order-address.js b/themes/default/js/order-address.js index 02dc962bd..567bd85e0 100644 --- a/themes/default/js/order-address.js +++ b/themes/default/js/order-address.js @@ -35,18 +35,13 @@ function updateAddressesDisplay(first_view) { // update content of delivery address updateAddressDisplay('delivery'); - var txtInvoiceTitle = ""; - try{ var adrs_titles = getAddressesTitles(); txtInvoiceTitle = adrs_titles.invoice; } catch (e) - { - - } - + {} // update content of invoice address //if addresses have to be equals... if ($('input[type=checkbox]#addressesAreEquals:checked').length === 1 && ($('#multishipping_mode_checkbox:checked').length === 0)) @@ -68,7 +63,6 @@ function updateAddressesDisplay(first_view) $('ul#address_invoice li.address_title').html(txtInvoiceTitle); } } - if(!first_view) { if (orderProcess === 'order') @@ -82,15 +76,15 @@ function updateAddressDisplay(addressType) if (formatedAddressFieldsValuesList.length <= 0) return false; - var idAddress = $('#id_address_' + addressType + '').val(); - buildAddressBlock(idAddress, addressType, $('#address_'+ addressType)); + var idAddress = parseInt($('#id_address_' + addressType + '').val()); + buildAddressBlock(idAddress, addressType, $('#address_' + addressType)); // change update link var link = $('ul#address_' + addressType + ' li.address_update a').attr('href'); var expression = /id_address=\d+/; if (link) { - link = link.replace(expression, 'id_address='+idAddress); + link = link.replace(expression, 'id_address=' + idAddress); $('ul#address_' + addressType + ' li.address_update a').attr('href', link); } resizeAddressesBox(); @@ -98,41 +92,43 @@ function updateAddressDisplay(addressType) function updateAddresses() { - var idAddress_delivery = $('#id_address_delivery').val(); - var idAddress_invoice = $('input[type=checkbox]#addressesAreEquals:checked').length === 1 ? idAddress_delivery : $('#id_address_invoice').val(); - $.ajax({ - type: 'POST', - headers: { "cache-control": "no-cache" }, - url: baseUri + '?rand=' + new Date().getTime(), - async: true, - cache: false, - dataType : "json", - data: { - processAddress: true, - step: 2, - ajax: 'true', - controller: 'order', - 'multi-shipping': $('#id_address_delivery:hidden').length, - id_address_delivery: idAddress_delivery, - id_address_invoice: idAddress_invoice, - token: static_token - }, - success: function(jsonData) - { - if (jsonData.hasError) + var idAddress_delivery = parseInt($('#id_address_delivery').val()); + var idAddress_invoice = $('input[type=checkbox]#addressesAreEquals:checked').length === 1 ? idAddress_delivery : parseInt($('#id_address_invoice').val()); + + if(isNaN(idAddress_delivery) == false && isNaN(idAddress_invoice) == false) + $.ajax({ + type: 'POST', + headers: { "cache-control": "no-cache" }, + url: baseUri + '?rand=' + new Date().getTime(), + async: true, + cache: false, + dataType : "json", + data: { + processAddress: true, + step: 2, + ajax: 'true', + controller: 'order', + 'multi-shipping': $('#id_address_delivery:hidden').length, + id_address_delivery: idAddress_delivery, + id_address_invoice: idAddress_invoice, + token: static_token + }, + success: function(jsonData) { - var errors = ''; - for(var error in jsonData.errors) - //IE6 bug fix - if(error !== 'indexOf') - errors += jsonData.errors[error] + "\n"; - alert(errors); + if (jsonData.hasError) + { + var errors = ''; + for(var error in jsonData.errors) + //IE6 bug fix + if(error !== 'indexOf') + errors += jsonData.errors[error] + "\n"; + alert(errors); + } + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + if (textStatus !== 'abort') + alert("TECHNICAL ERROR: unable to save adresses \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); } - }, - error: function(XMLHttpRequest, textStatus, errorThrown) { - if (textStatus !== 'abort') - alert("TECHNICAL ERROR: unable to save adresses \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); - } - }); + }); resizeAddressesBox(); -} +} \ No newline at end of file