diff --git a/themes/default/css/global.css b/themes/default/css/global.css index 2e18686f3..c5501473b 100644 --- a/themes/default/css/global.css +++ b/themes/default/css/global.css @@ -613,6 +613,8 @@ ul.idTabs li { /* step 1 - cart ******************************************************************************* */ .cart_last_product {display:none} +p.cart_navigation .multishipping-button { margin-right: 10px } + #order-detail-content {margin-bottom:20px} table#cart_summary th { @@ -850,6 +852,54 @@ table#cart_summary .cart_total_price td.cart_voucher { border:1px solid #ccc } +/* step 3 - address ************************************************************************** */ + +.address-form-multishipping { padding: 10px 0px; } +#multishipping_mode_box { + border: 1px solid #D0D3D8; + background: url("../img/form_bg.jpg") repeat-x scroll left top #D0D1D5; + margin-bottom: 10px; + padding: 5px; +} +#multishipping_mode_checkbox { + vertical-align: middle; + margin-right: 5px; +} +#multishipping_mode_box.on { + border: 1px solid #ddd; +} +#multishipping_mode_box .title { + padding: 5px; + font-weight: bold; +} +#multishipping_mode_box .description, #multishipping_mode_box .description_off { + padding: 5px; +} +#multishipping_mode_box .description_off { + display: none; + padding: 5px; +} +#multishipping_mode_box .description_off div { + margin-bottom: 10px; +} +#multishipping_mode_box .description_off a, #multishipping_mode_box .description a { + display: block; + text-align: center; + text-decoration: none; + padding: 5px 10px; + margin: 0 160px; + border: 1px solid #ccc; + background: #ddd; +} +#multishipping_mode_box .description_off a:hover, #multishipping_mode_box .description a:hover { + background: #f3f3f3; + border: 1px solid #ccc; +} +#multishipping_mode_box.on .description_off { + display: block; +} + + /* step 4 - paiement ************************************************************************** */ .order_carrier_content { padding:15px; diff --git a/themes/default/js/cart-summary.js b/themes/default/js/cart-summary.js index a695cea95..28283b886 100644 --- a/themes/default/js/cart-summary.js +++ b/themes/default/js/cart-summary.js @@ -19,19 +19,197 @@ * * @author PrestaShop SA * @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 6594 $ +* @version Release: $Revision: 7040 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ $(document).ready(function() { - $('.cart_quantity_up').unbind('click').click(function(){ upQuantity($(this).attr('id').replace('cart_quantity_up_', '')); return false; }); - $('.cart_quantity_down').unbind('click').click(function(){ downQuantity($(this).attr('id').replace('cart_quantity_down_', '')); return false; }); - $('.cart_quantity_delete' ).unbind('click').click(function(){ deletProductFromSummary($(this).attr('id')); return false; }); - $('.cart_quantity_input').typeWatch({ highlight: true, wait: 600, captureLength: 0, callback: updateQty }); + // If block cart isn't used, we don't bind the handle actions + if (window.ajaxCart !== undefined) + { + $('.cart_quantity_up').unbind('click').live('click', function(){ upQuantity($(this).attr('id').replace('cart_quantity_up_', '')); return false; }); + $('.cart_quantity_down').unbind('click').live('click', function(){ downQuantity($(this).attr('id').replace('cart_quantity_down_', '')); return false; }); + $('.cart_quantity_delete' ).unbind('click').live('click', function(){ deleteProductFromSummary($(this).attr('id')); return false; }); + $('.cart_quantity_input').typeWatch({ highlight: true, wait: 600, captureLength: 0, callback: updateQty }); + + $('.cart_address_delivery').live('change', function(){ changeAddressDelivery($(this)); }); + } + else + { + $('.cart_address_delivery').change(function(){ submit(); }); + } + cleanSelectAddressDelivery(); }); +function cleanSelectAddressDelivery() +{ + if (window.ajaxCart !== undefined) + { + //Removing "Ship to an other address" from the address delivery select option if there is not enought address + $.each($('.cart_address_delivery'), function(it, item) + { + var options = $(item).find('option'); + var address_count = 0; + + var ids = $(item).attr('id').split('_'); + var id_product = ids[3]; + var id_product_attribute = ids[4]; + var id_address_delivery = ids[5]; + + $.each(options, function(i) { + if ($(options[i]).val() > 0 + && ($('#product_' + id_product + '_' + id_product_attribute + '_0_' + $(options[i]).val()).length == 0 // Check the address is not already used for a similare products + || id_address_delivery == $(options[i]).val() + ) + ) + address_count++; + }); + + if (address_count < 2) // Need at least two address to allow skipping products to multiple address + $($(item).find('option[value=-2]')).remove(); + else if($($(item).find('option[value=-2]')).length == 0) + $(item).append($('')); // @todo add translation + }); + } +} + +function changeAddressDelivery(obj) +{ + var ids = obj.attr('id').split('_'); + var id_product = ids[3]; + var id_product_attribute = ids[4]; + var old_id_address_delivery = ids[5]; + var new_id_address_delivery = obj.val(); + + if (new_id_address_delivery == old_id_address_delivery) + return; + + if (new_id_address_delivery > 0) // Change the delivery address + { + $.ajax({ + type: 'GET', + url: baseDir, + async: true, + cache: false, + dataType: 'json', + data: 'controller=cart&ajax=true&changeAddressDelivery&summary&id_product='+id_product + +'&id_product_attribute='+id_product_attribute + +'&old_id_address_delivery='+old_id_address_delivery + +'&new_id_address_delivery='+new_id_address_delivery + +'&token='+static_token, + success: function(jsonData) + { + // 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 (jsonData.carriers != null) + 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(); + } + }); + } + else if (new_id_address_delivery == -1) // Adding a new address + window.location = $($('.address_add a')[0]).attr('href'); + else if (new_id_address_delivery == -2) // Add a new line for this product + { + // This test is will not usefull in the future + if (old_id_address_delivery == 0) + { + alert('Please select first an address'); // @todo translate + return false; + } + + // Get new address to deliver + var id_address_delivery = 0; + var options = $('#select_address_delivery_'+id_product+'_'+id_product_attribute+'_'+old_id_address_delivery+' option'); + $.each(options, function(i) { + if ($(options[i]).val() > 0 && $(options[i]).val() != old_id_address_delivery + && $('#product_' + id_product + '_' + id_product_attribute + '_0_' + $(options[i]).val()).length == 0 // Check the address is not already used for a similare products + ) + { + id_address_delivery = $(options[i]).val(); + return false; + } + }); + + $.ajax({ + type: 'GET', + url: baseDir, + async: true, + cache: false, + dataType: 'json', + context: obj, + data: 'controller=cart&ajax=true&duplicate&summary&id_product='+id_product+'&id_product_attribute='+id_product_attribute+'&id_address_delivery='+old_id_address_delivery+'&new_id_address_delivery='+id_address_delivery+'&token='+static_token , + success: function(jsonData) + { + if (jsonData.error) + { + alert(jsonData.reason); + return; + } + + var line = $('#product_' + id_product+'_' + id_product_attribute + '_0_' + old_id_address_delivery); + var new_line = line.clone(); + updateAddressId(id_product, id_product_attribute, old_id_address_delivery, id_address_delivery, new_line); + line.after(new_line); + new_line.find('input[name=quantity_' + id_product+'_' + id_product_attribute + '_0_' + old_id_address_delivery + '_hidden]') + .val(1); + new_line.find('.cart_quantity_input') + .val(1); + $('#select_address_delivery_' + id_product+'_' + id_product_attribute + '_' + old_id_address_delivery).val(old_id_address_delivery); + $('#select_address_delivery_' + id_product+'_' + id_product_attribute + '_' + id_address_delivery).val(id_address_delivery); + + + cleanSelectAddressDelivery(); + + updateCartSummary(jsonData.summary); + + if (window.ajaxCart !== undefined) + ajaxCart.refresh(); + } + }); + } +} + +function updateAddressId(id_product, id_product_attribute, old_id_address_delivery, id_address_delivery, line) +{ + if (typeof(line) == 'undefined') + var line = $('#product_' + id_product+'_' + id_product_attribute + '_0_' + old_id_address_delivery); + + line.attr('id', 'product_' + id_product+'_' + id_product_attribute + '_0_' + id_address_delivery); + line.find('.cart_quantity_input') + .attr('name', 'quantity_' + id_product+'_' + id_product_attribute + '_0_' + id_address_delivery); + line.find('input[name=quantity_' + id_product+'_' + id_product_attribute + '_0_' + old_id_address_delivery + '_hidden]') + .attr('name', 'quantity_' + id_product+'_' + id_product_attribute + '_0_' + id_address_delivery + '_hidden'); + line.find('#cart_quantity_down_' + id_product+'_' + id_product_attribute + '_0_' + old_id_address_delivery) + .attr('id', 'cart_quantity_down_' + id_product+'_' + id_product_attribute + '_0_' + id_address_delivery); + line.find('#cart_quantity_up_' + id_product+'_' + id_product_attribute + '_0_' + old_id_address_delivery) + .attr('id', 'cart_quantity_up_' + id_product+'_' + id_product_attribute + '_0_' + id_address_delivery); + line.find('#' + id_product+'_' + id_product_attribute + '_0_' + old_id_address_delivery) + .attr('id', id_product+'_' + id_product_attribute + '_0_' + id_address_delivery); + line.find('#select_address_delivery_' + id_product+'_' + id_product_attribute + '_' + old_id_address_delivery) + .attr('id', 'select_address_delivery_' + id_product+'_' + id_product_attribute + '_' + id_address_delivery); +} + function updateQty(val) { var id = $(this.el).attr('name'); @@ -44,19 +222,20 @@ function updateQty(val) var QtyToUp = parseInt(input) - parseInt(hidden); if (parseInt(QtyToUp) > 0) - upQuantity(id.replace('quantity_', ''),QtyToUp); + upQuantity(id.replace('quantity_', ''), QtyToUp); else if(parseInt(QtyToUp) < 0) - downQuantity(id.replace('quantity_', ''),QtyToUp); + downQuantity(id.replace('quantity_', ''), QtyToUp); } else $('input[name='+ id +']').val($('input[name='+ id +'_hidden]').val()); } -function deletProductFromSummary(id) +function deleteProductFromSummary(id) { var customizationId = 0; var productId = 0; var productAttributeId = 0; + var id_address_delivery = 0; var ids = 0; ids = id.split('_'); productId = parseInt(ids[0]); @@ -64,34 +243,36 @@ function deletProductFromSummary(id) productAttributeId = parseInt(ids[1]); if (typeof(ids[2]) != 'undefined') customizationId = parseInt(ids[2]); + if (typeof(ids[3]) != 'undefined') + id_address_delivery = parseInt(ids[3]); $.ajax({ - type: 'GET', - url: baseDir + 'cart.php', - async: true, - cache: false, - dataType: 'json', - data: 'ajax=true&delete&summary&id_product='+productId+'&ipa='+productAttributeId+ ( (customizationId != 0) ? '&id_customization='+customizationId : '') + '&token=' + static_token , - success: function(jsonData) - { - if (jsonData.hasError) - { - var errors = ''; - for(error in jsonData.errors) - //IE6 bug fix - if(error != 'indexOf') - errors += jsonData.errors[error] + "\n"; - } - else - { - if (parseInt(jsonData.summary.products.length) == 0) - { - $('#center_column').children().each(function() { - if ($(this).attr('id') != 'emptyCartWarning' && $(this).attr('class') != 'breadcrumb' && $(this).attr('id') != 'cart_title') - { - $(this).fadeOut('slow', function () { - $(this).remove(); - }); - } + type: 'GET', + url: baseDir, + async: true, + cache: false, + dataType: 'json', + data: 'controller=cart&ajax=true&delete&summary&id_product='+productId+'&ipa='+productAttributeId+'&id_address_delivery='+id_address_delivery+ ( (customizationId != 0) ? '&id_customization='+customizationId : '') + '&token=' + static_token , + success: function(jsonData) + { + if (jsonData.hasError) + { + var errors = ''; + for(error in jsonData.errors) + //IE6 bug fix + if(error != 'indexOf') + errors += jsonData.errors[error] + "\n"; + } + else + { + if (parseInt(jsonData.summary.products.length) == 0) + { + $('#center_column').children().each(function() { + if ($(this).attr('id') != 'emptyCartWarning' && $(this).attr('class') != 'breadcrumb' && $(this).attr('id') != 'cart_title') + { + $(this).fadeOut('slow', function () { + $(this).remove(); + }); + } }); $('#summary_products_label').remove(); $('#emptyCartWarning').fadeIn('slow'); @@ -100,6 +281,7 @@ function deletProductFromSummary(id) { $('#product_'+ id).fadeOut('slow', function() { $(this).remove(); + cleanSelectAddressDelivery(); }); var exist = false; @@ -118,12 +300,12 @@ function deletProductFromSummary(id) updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); updateCustomizedDatas(jsonData.customizedDatas); if (jsonData.carriers != null) - updateCarrierList(jsonData); - - } - }, - error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} - }); + if (typeof(getCarrierListAndUpdate) != 'undefined') + getCarrierListAndUpdate(); + } + }, + error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} + }); } function upQuantity(id, qty) @@ -133,6 +315,7 @@ function upQuantity(id, qty) var customizationId = 0; var productId = 0; var productAttributeId = 0; + var id_address_delivery = 0; var ids = 0; ids = id.split('_'); productId = parseInt(ids[0]); @@ -140,37 +323,40 @@ function upQuantity(id, qty) productAttributeId = parseInt(ids[1]); if (typeof(ids[2]) != 'undefined') customizationId = parseInt(ids[2]); + if (typeof(ids[3]) != 'undefined') + id_address_delivery = parseInt(ids[3]); $.ajax({ - type: 'GET', - url: baseDir + 'cart.php', - async: true, - cache: false, - dataType: 'json', - data: 'ajax=true&add&summary&id_product='+productId+'&ipa='+productAttributeId + ( (customizationId != 0) ? '&id_customization='+customizationId : '') + '&qty='+qty+'&token=' + static_token , - success: function(jsonData) - { - if (jsonData.hasError) - { - var errors = ''; - for(error in jsonData.errors) - //IE6 bug fix - if(error != 'indexOf') - errors += jsonData.errors[error] + "\n"; - alert(errors); - $('input[name=quantity_'+ id +']').val($('input[name=quantity_'+ id +'_hidden]').val()); - } - else - { - updateCustomizedDatas(jsonData.customizedDatas); - updateCartSummary(jsonData.summary); - updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); + type: 'GET', + url: baseDir, + async: true, + cache: false, + dataType: 'json', + data: 'controller=cart&ajax=true&add&getproductprice&summary&id_product='+productId+'&ipa='+productAttributeId+'&id_address_delivery='+id_address_delivery + ( (customizationId != 0) ? '&id_customization='+customizationId : '') + '&qty='+qty+'&token=' + static_token , + success: function(jsonData) + { + if (jsonData.hasError) + { + var errors = ''; + for(error in jsonData.errors) + //IE6 bug fix + if(error != 'indexOf') + errors += jsonData.errors[error] + "\n"; + alert(errors); + $('input[name=quantity_'+ id +']').val($('input[name=quantity_'+ id +'_hidden]').val()); + } + else + { + updateCustomizedDatas(jsonData.customizedDatas); + updateCartSummary(jsonData.summary); + updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); - if (jsonData.carriers != null) - updateCarrierList(jsonData); - } - }, - error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} - }); + if (jsonData.carriers != null) + if (typeof(getCarrierListAndUpdate) != 'undefined') + getCarrierListAndUpdate(); + } + }, + error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} + }); } function downQuantity(id, qty) @@ -183,10 +369,11 @@ function downQuantity(id, qty) newVal = val - 1; } else if (qty < 0) - qty = -qty; + qty = -qty; var customizationId = 0; var productId = 0; var productAttributeId = 0; + var id_address_delivery = 0; var ids = 0; if (newVal > 0) { @@ -196,42 +383,45 @@ function downQuantity(id, qty) productAttributeId = parseInt(ids[1]); if (typeof(ids[2]) != 'undefined') customizationId = parseInt(ids[2]); + if (typeof(ids[3]) != 'undefined') + id_address_delivery = parseInt(ids[3]); $.ajax({ - type: 'GET', - url: baseDir + 'cart.php', - async: true, - cache: false, - dataType: 'json', - data: 'ajax=true&add&summary&id_product='+productId+'&ipa='+productAttributeId+'&op=down' + ( (customizationId != 0) ? '&id_customization='+customizationId : '') + '&qty='+qty+'&token=' + static_token , - success: function(jsonData) - { - if (jsonData.hasError) - { - var errors = ''; - for(error in jsonData.errors) - //IE6 bug fix - if(error != 'indexOf') - errors += jsonData.errors[error] + "\n"; - alert(errors); - $('input[name=quantity_'+ id +']').val($('input[name=quantity_'+ id +'_hidden]').val()); - } - else - { - updateCustomizedDatas(jsonData.customizedDatas); - updateCartSummary(jsonData.summary); - updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); + type: 'GET', + url: baseDir, + async: true, + cache: false, + dataType: 'json', + data: 'controller=cart&ajax=true&add&getproductprice&summary&id_product='+productId+'&ipa='+productAttributeId+'&id_address_delivery='+id_address_delivery+'&op=down' + ( (customizationId != 0) ? '&id_customization='+customizationId : '') + '&qty='+qty+'&token=' + static_token , + success: function(jsonData) + { + if (jsonData.hasError) + { + var errors = ''; + for(error in jsonData.errors) + //IE6 bug fix + if(error != 'indexOf') + errors += jsonData.errors[error] + "\n"; + alert(errors); + $('input[name=quantity_'+ id +']').val($('input[name=quantity_'+ id +'_hidden]').val()); + } + else + { + updateCustomizedDatas(jsonData.customizedDatas); + updateCartSummary(jsonData.summary); + updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); - if (jsonData.carriers != null) - updateCarrierList(jsonData); - } - }, - error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} - }); + if (jsonData.carriers != null) + if (typeof(getCarrierListAndUpdate) != 'undefined') + getCarrierListAndUpdate(); + } + }, + error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} + }); } else { - deletProductFromSummary(id); + deleteProductFromSummary(id); } } @@ -240,8 +430,29 @@ function updateCartSummary(json) // Update products prices + discount var i; var nbrProducts = 0; + + if (typeof json == 'undefined') + return; + for (i=0;i current_price) + initial_price_text = ''+initial_price+'
'; + } + key_for_blockcart = json.products[i].id_product+'_'+json.products[i].id_product_attribute; if (json.products[i].id_product_attribute == 0) key_for_blockcart = json.products[i].id_product; @@ -250,34 +461,38 @@ function updateCartSummary(json) if (priceDisplayMethod != 0) { - $('#cart_block_product_'+key_for_blockcart+' span.price').html(formatCurrency(json.products[i].total, currencyFormat, currencySign, currencyBlank)); - $('#product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute).html(formatCurrency(json.products[i].price, currencyFormat, currencySign, currencyBlank)); - $('#total_product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute).html(formatCurrency(json.products[i].total, currencyFormat, currencySign, currencyBlank)); + $('#cart_block_product_'+key_for_blockcart+' span.price').html(formatCurrency(json.products[i].total, currencyFormat, currencySign, currencyBlank)); + $('#product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+'_'+json.products[i].id_address_delivery).html(initial_price_text+current_price); + $('#total_product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+'_'+json.products[i].id_address_delivery).html(formatCurrency(json.products[i].total, currencyFormat, currencySign, currencyBlank)); } else { - $('#cart_block_product_'+key_for_blockcart+' span.price').html(formatCurrency(json.products[i].total_wt, currencyFormat, currencySign, currencyBlank)); - $('#product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute).html(formatCurrency(json.products[i].price_wt, currencyFormat, currencySign, currencyBlank)); - $('#total_product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute).html(formatCurrency(json.products[i].total_wt, currencyFormat, currencySign, currencyBlank)); + $('#cart_block_product_'+key_for_blockcart+' span.price').html(formatCurrency(json.products[i].total_wt, currencyFormat, currencySign, currencyBlank)); + $('#product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+'_'+json.products[i].id_address_delivery).html(initial_price_text+current_price); + $('#total_product_price_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+'_'+json.products[i].id_address_delivery).html(formatCurrency(json.products[i].total_wt, currencyFormat, currencySign, currencyBlank)); } nbrProducts += parseInt(json.products[i].cart_quantity); if(json.products[i].id_customization == null) { - $('input[name=quantity_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+(json.products[i].id_customization != null ? '_'+json.products[i].id_customization : '')+']').val(json.products[i].cart_quantity); - $('input[name=quantity_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+(json.products[i].id_customization != null ? '_'+json.products[i].id_customization : '')+'_hidden]').val(json.products[i].cart_quantity); + $('input[name=quantity_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+'_0_'+json.products[i].id_address_delivery+']').val(json.products[i].cart_quantity); + $('input[name=quantity_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+'_0_'+json.products[i].id_address_delivery+'_hidden]').val(json.products[i].cart_quantity); } else { - $('#cart_quantity_custom_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute).html(json.products[i].cart_quantity); + //$('input[name=quantity_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+'_'+json.products[i].id_customization+'_'+json.products[i].id_address_delivery+']') + // .val(json.products[i].cart_quantity); + $('#cart_quantity_custom_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+'_'+json.products[i].id_address_delivery) + .html(json.products[i].cart_quantity); } // Show / hide quantity button if minimal quantity if (parseInt(json.products[i].minimal_quantity) == parseInt(json.products[i].cart_quantity) && json.products[i].minimal_quantity != 1) - $('#cart_quantity_down_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+(json.products[i].id_customization != null ? '_'+json.products[i].id_customization : '')).fadeTo('slow',0.3); + $('#cart_quantity_down_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+Number(json.products[i].id_customization)+'_'+json.products[i].id_address_delivery).fadeTo('slow',0.3); else - $('#cart_quantity_down_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+(json.products[i].id_customization != null ? '_'+json.products[i].id_customization : '')).fadeTo('slow',1); + $('#cart_quantity_down_'+json.products[i].id_product+'_'+json.products[i].id_product_attribute+Number(json.products[i].id_customization)+'_'+json.products[i].id_address_delivery).fadeTo('slow',1); + } // Update discounts @@ -288,7 +503,11 @@ function updateCartSummary(json) } else { - $('#total_discount').html(formatCurrency(json.total_discounts, currencyFormat, currencySign, currencyBlank)); + if (priceDisplayMethod != 0) + $('#total_discount').html(formatCurrency(json.total_discounts_tax_exc, currencyFormat, currencySign, currencyBlank)); + else + $('#total_discount').html(formatCurrency(json.total_discounts, currencyFormat, currencySign, currencyBlank)); + $('.cart_discount').each(function(){ var idElmt = $(this).attr('id').replace('cart_discount_',''); var toDelete = true; @@ -298,7 +517,13 @@ function updateCartSummary(json) if (json.discounts[i].id_discount == idElmt) { if (json.discounts[i].value_real != '!') - $('#cart_discount_' + idElmt + ' td.cart_discount_price span.price-discount').html(formatCurrency(json.discounts[i].value_real * -1, currencyFormat, currencySign, currencyBlank)); + { + if (priceDisplayMethod != 0) + $('#cart_discount_' + idElmt + ' td.cart_discount_price span.price-discount').html(formatCurrency(json.discounts[i].value_tax_exc * -1, currencyFormat, currencySign, currencyBlank)); + else + $('#cart_discount_' + idElmt + ' td.cart_discount_price span.price-discount').html(formatCurrency(json.discounts[i].value_real * -1, currencyFormat, currencySign, currencyBlank)); + + } toDelete = false; } } @@ -308,16 +533,16 @@ function updateCartSummary(json) } // Block cart - if (priceDisplayMethod != 0) + if (priceDisplayMethod != 0) { - $('#cart_block_shipping_cost').html(formatCurrency(json.total_shipping_tax_exc, currencyFormat, currencySign, currencyBlank)); - $('#cart_block_wrapping_cost').html(formatCurrency(json.total_wrapping_tax_exc, currencyFormat, currencySign, currencyBlank)); - $('#cart_block_total').html(formatCurrency(json.total_price_without_tax, currencyFormat, currencySign, currencyBlank)); - } else { - $('#cart_block_shipping_cost').html(formatCurrency(json.total_shipping, currencyFormat, currencySign, currencyBlank)); - $('#cart_block_wrapping_cost').html(formatCurrency(json.total_wrapping, currencyFormat, currencySign, currencyBlank)); - $('#cart_block_total').html(formatCurrency(json.total_price, currencyFormat, currencySign, currencyBlank)); - } + $('#cart_block_shipping_cost').html(formatCurrency(json.total_shipping_tax_exc, currencyFormat, currencySign, currencyBlank)); + $('#cart_block_wrapping_cost').html(formatCurrency(json.total_wrapping_tax_exc, currencyFormat, currencySign, currencyBlank)); + $('#cart_block_total').html(formatCurrency(json.total_price_without_tax, currencyFormat, currencySign, currencyBlank)); + } else { + $('#cart_block_shipping_cost').html(formatCurrency(json.total_shipping, currencyFormat, currencySign, currencyBlank)); + $('#cart_block_wrapping_cost').html(formatCurrency(json.total_wrapping, currencyFormat, currencySign, currencyBlank)); + $('#cart_block_total').html(formatCurrency(json.total_price, currencyFormat, currencySign, currencyBlank)); + } $('#cart_block_tax_cost').html(formatCurrency(json.total_tax, currencyFormat, currencySign, currencyBlank)); $('.ajax_cart_quantity').html(nbrProducts); @@ -325,10 +550,10 @@ function updateCartSummary(json) // Cart summary $('#summary_products_quantity').html(nbrProducts+' '+(nbrProducts > 1 ? txtProducts : txtProduct)); if (priceDisplayMethod != 0) - $('#total_product').html(formatCurrency(json.total_products, currencyFormat, currencySign, currencyBlank)); - else - $('#total_product').html(formatCurrency(json.total_products_wt, currencyFormat, currencySign, currencyBlank)); - $('#total_price').children('span').html(formatCurrency(json.total_price, currencyFormat, currencySign, currencyBlank)); + $('#total_product').html(formatCurrency(json.total_products, currencyFormat, currencySign, currencyBlank)); + else + $('#total_product').html(formatCurrency(json.total_products_wt, currencyFormat, currencySign, currencyBlank)); + $('#total_price').html(formatCurrency(json.total_price, currencyFormat, currencySign, currencyBlank)); $('#total_price_without_tax').html(formatCurrency(json.total_price_without_tax, currencyFormat, currencySign, currencyBlank)); $('#total_tax').html(formatCurrency(json.total_tax, currencyFormat, currencySign, currencyBlank)); @@ -338,12 +563,12 @@ function updateCartSummary(json) { $('.cart_total_delivery').fadeIn(); if (priceDisplayMethod != 0) - { - $('#total_shipping').html(formatCurrency(json.total_shipping_tax_exc, currencyFormat, currencySign, currencyBlank)); + { + $('#total_shipping').html(formatCurrency(json.total_shipping_tax_exc, currencyFormat, currencySign, currencyBlank)); } else { - $('#total_shipping').html(formatCurrency(json.total_shipping, currencyFormat, currencySign, currencyBlank)); + $('#total_shipping').html(formatCurrency(json.total_shipping, currencyFormat, currencySign, currencyBlank)); } } @@ -374,10 +599,11 @@ function updateCustomizedDatas(json) for(i in json) for(j in json[i]) for(k in json[i][j]) - { - $('input[name=quantity_'+i+'_'+j+'_'+k+'_hidden]').val(json[i][j][k]['quantity']); - $('input[name=quantity_'+i+'_'+j+'_'+k+']').val(json[i][j][k]['quantity']); - } + for(l in json[i][j][k]) + { + $('input[name=quantity_'+i+'_'+j+'_'+l+'_'+k+'_hidden]').val(json[i][j][k][l]['quantity']); + $('input[name=quantity_'+i+'_'+j+'_'+l+'_'+k+']').val(json[i][j][k][l]['quantity']); + } } function updateHookShoppingCart(html) @@ -389,4 +615,35 @@ function updateHookShoppingCartExtra(html) { $('#HOOK_SHOPPING_CART_EXTRA').html(html); } - +$(document).ready(function() { + $.each($('.delivery_option_radio'), function() { + if ($(this).attr('checked')) + $(this).parent().find('.delivery_option_carrier').show(); + else + $(this).parent().find('.delivery_option_carrier').hide(); + + }); + $('.delivery_option_radio').change(function() { + $(this).parent().parent().find('.delivery_option_carrier').hide(); + $(this).parent().find('.delivery_option_carrier').show(); + }); + + $('#allow_seperated_package').live('click', function() { + $.ajax({ + type: 'GET', + url: baseDir, + async: true, + cache: false, + data: 'controller=cart&ajax=true&allowSeperatedPackage&value=' + +($(this).attr('checked') ? '1' : '0') + +'&token='+static_token, + success: function(jsonData) + { + if (typeof(getCarrierListAndUpdate) != 'undefined') + getCarrierListAndUpdate(); + } + }); + }); + + $('#gift').checkboxChange(function() { $('#gift_div').show('slow'); }, function() { $('#gift_div').hide('slow'); }); +}); diff --git a/themes/default/js/order-opc.js b/themes/default/js/order-opc.js index c201e3beb..fa54cc913 100644 --- a/themes/default/js/order-opc.js +++ b/themes/default/js/order-opc.js @@ -19,71 +19,19 @@ * * @author PrestaShop SA * @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 6772 $ +* @version Release: $Revision: 7040 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ function updateCarrierList(json) { - var carriers = json.carriers; + var html = json.carrier_block; - /* contains all carrier available for this address */ - if (carriers.length == 0) - { - checkedCarrier = 0; - $('input[name=id_carrier]:checked').attr('checked', false); - $('#noCarrierWarning').show(); - $('#extra_carrier').hide(); - $('#recyclable_block').hide(); - $('table#carrierTable:visible').hide(); - } - else - { - checkedCarrier = json.checked; - var html = ''; - for (i=0;i'; - - if (!(carriers[i].is_module && !isLogged)) - var extraHtml = 'disabled="disabled"'; - else if (checkedCarrier == carriers[i].id_carrier || carriers.length == 1) - var extraHtml = 'checked="checked"'; - - html = html + - ''+ - ''+ - ''+ - ''+carriers[i].delay+''+ - ''+formatCurrency(carriers[i].price, currencyFormat, currencySign, currencyBlank)+''; - if (taxEnabled && displayPrice == 0) - html = html + ' ' + txtWithTax; - else - html = html + ' ' + txtWithoutTax; - html = html + ''+ - ''; - } - if (json.HOOK_EXTRACARRIER !== null && json.HOOK_EXTRACARRIER != undefined) html += json.HOOK_EXTRACARRIER; - $('#noCarrierWarning').hide(); - $('#extra_carrier:hidden').show(); - $('table#carrierTable tbody').html(html); - $('table#carrierTable:hidden').show(); - $('#recyclable_block:hidden').show(); - } + if (json.HOOK_EXTRACARRIER !== null && json.HOOK_EXTRACARRIER != undefined) + html += json.HOOK_EXTRACARRIER; + + $('#carrier_area').replaceWith(html); /* update hooks for carrier module */ $('#HOOK_BEFORECARRIER').html(json.HOOK_BEFORECARRIER); @@ -97,46 +45,51 @@ function updatePaymentMethods(json) function updateAddressSelection() { - var idAddress_delivery = ($('input#opc_id_address_delivery').length == 1 ? $('input#opc_id_address_delivery').val() : $('select#id_address_delivery').val()); - var idAddress_invoice = ($('input#opc_id_address_invoice').length == 1 ? $('input#opc_id_address_invoice').val() : ($('input[type=checkbox]#addressesAreEquals:checked').length == 1 ? idAddress_delivery : ($('select#id_address_invoice').length == 1 ? $('select#id_address_invoice').val() : idAddress_delivery))); + var idAddress_delivery = ($('input#opc_id_address_delivery').length == 1 ? $('input#opc_id_address_delivery').val() : $('#id_address_delivery').val()); + var idAddress_invoice = ($('input#opc_id_address_invoice').length == 1 ? $('input#opc_id_address_invoice').val() : ($('input[type=checkbox]#addressesAreEquals:checked').length == 1 ? idAddress_delivery : ($('#id_address_invoice').length == 1 ? $('select#id_address_invoice').val() : idAddress_delivery))); $('#opc_account-overlay').fadeIn('slow'); $('#opc_delivery_methods-overlay').fadeIn('slow'); $('#opc_payment_methods-overlay').fadeIn('slow'); $.ajax({ - type: 'POST', - url: orderOpcUrl, - async: true, - cache: false, - dataType : "json", - data: 'ajax=true&method=updateAddressesSelected&id_address_delivery=' + idAddress_delivery + '&id_address_invoice=' + idAddress_invoice + '&token=' + static_token, - success: function(jsonData) - { - if (jsonData.hasError) - { - var errors = ''; - for(error in jsonData.errors) - //IE6 bug fix - if(error != 'indexOf') - errors += jsonData.errors[error] + "\n"; - alert(errors); - } - else - { - updateCarrierList(jsonData); - updatePaymentMethods(jsonData); - updateCartSummary(jsonData.summary); - updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); - updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); - if ($('#gift-price').length == 1) - $('#gift-price').html(jsonData.gift_price); - $('#opc_account-overlay').fadeOut('slow'); - $('#opc_delivery_methods-overlay').fadeOut('slow'); - $('#opc_payment_methods-overlay').fadeOut('slow'); - } - }, - error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save adresses \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} + type: 'POST', + url: orderOpcUrl, + async: true, + cache: false, + dataType : "json", + data: 'ajax=true&method=updateAddressesSelected&id_address_delivery=' + idAddress_delivery + '&id_address_invoice=' + idAddress_invoice + '&token=' + static_token, + success: function(jsonData) + { + if (jsonData.hasError) + { + var errors = ''; + for(error in jsonData.errors) + //IE6 bug fix + if(error != 'indexOf') + errors += jsonData.errors[error] + "\n"; + alert(errors); + } + else + { + updateCarrierList(jsonData.carrier_data); + updatePaymentMethods(jsonData); + updateCartSummary(jsonData.summary); + updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); + updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); + if ($('#gift-price').length == 1) + $('#gift-price').html(jsonData.gift_price); + $('#opc_account-overlay').fadeOut('slow'); + $('#opc_delivery_methods-overlay').fadeOut('slow'); + $('#opc_payment_methods-overlay').fadeOut('slow'); + } + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + alert("TECHNICAL ERROR: unable to save adresses \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); + $('#opc_account-overlay').fadeOut('slow'); + $('#opc_delivery_methods-overlay').fadeOut('slow'); + $('#opc_payment_methods-overlay').fadeOut('slow'); + } }); } @@ -144,14 +97,14 @@ function getCarrierListAndUpdate() { $('#opc_delivery_methods-overlay').fadeIn('slow'); $.ajax({ - type: 'POST', - url: orderOpcUrl, - async: true, - cache: false, - dataType : "json", - data: 'ajax=true&method=getCarrierList&token=' + static_token, - success: function(jsonData) - { + type: 'POST', + url: orderOpcUrl, + async: true, + cache: false, + dataType : "json", + data: 'ajax=true&method=getCarrierList&token=' + static_token, + success: function(jsonData) + { if (jsonData.hasError) { var errors = ''; @@ -173,7 +126,14 @@ function updateCarrierSelectionAndGift() var recyclablePackage = 0; var gift = 0; var giftMessage = ''; - var idCarrier = 0; + + var delivery_option_radio = $('.delivery_option_radio'); + var delivery_option_params = '&'; + $.each(delivery_option_radio, function(i) { + delivery_option_params += $(delivery_option_radio[i]).attr('name') + '=' + $(delivery_option_radio[i]).val() + '&'; + }); + if (delivery_option_params == '&') + delivery_option_params = '&delivery_option=&' if ($('input#recyclable:checked').length) recyclablePackage = 1; @@ -183,43 +143,42 @@ function updateCarrierSelectionAndGift() giftMessage = encodeURIComponent($('textarea#gift_message').val()); } - if ($('input[name=id_carrier]:checked').length) - { - idCarrier = $('input[name=id_carrier]:checked').val(); - checkedCarrier = idCarrier; - } - $('#opc_payment_methods-overlay').fadeIn('slow'); $('#opc_delivery_methods-overlay').fadeIn('slow'); $.ajax({ - type: 'POST', - url: orderOpcUrl, - async: false, - cache: false, - dataType : "json", - data: 'ajax=true&method=updateCarrierAndGetPayments&id_carrier=' + idCarrier + '&recyclable=' + recyclablePackage + '&gift=' + gift + '&gift_message=' + giftMessage + '&token=' + static_token , - success: function(jsonData) - { - if (jsonData.hasError) - { - var errors = ''; - for(error in jsonData.errors) - //IE6 bug fix - if(error != 'indexOf') - errors += jsonData.errors[error] + "\n"; - alert(errors); - } - else - { - updateCartSummary(jsonData.summary); - updatePaymentMethods(jsonData); - updateHookShoppingCart(jsonData.summary.HOOK_SHOPPING_CART); + type: 'POST', + url: orderOpcUrl, + async: true, + cache: false, + dataType : "json", + data: 'ajax=true&method=updateCarrierAndGetPayments' + delivery_option_params + 'recyclable=' + recyclablePackage + '&gift=' + gift + '&gift_message=' + giftMessage + '&token=' + static_token , + success: function(jsonData) + { + if (jsonData.hasError) + { + var errors = ''; + for(error in jsonData.errors) + //IE6 bug fix + if(error != 'indexOf') + errors += jsonData.errors[error] + "\n"; + alert(errors); + } + else + { + updateCartSummary(jsonData.summary); + updatePaymentMethods(jsonData); + updateHookShoppingCart(jsonData.summary.HOOK_SHOPPING_CART); updateHookShoppingCartExtra(jsonData.summary.HOOK_SHOPPING_CART_EXTRA); + updateCarrierList(jsonData.carrier_data); $('#opc_payment_methods-overlay').fadeOut('slow'); $('#opc_delivery_methods-overlay').fadeOut('slow'); - } - }, - error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save carrier \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} + } + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + alert("TECHNICAL ERROR: unable to save carrier \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); + $('#opc_payment_methods-overlay').fadeOut('slow'); + $('#opc_delivery_methods-overlay').fadeOut('slow'); + } }); } @@ -242,12 +201,12 @@ function confirmFreeOrder() { var array_split = html.split(':'); if (array_split[0] === 'freeorder') - { - if (isGuest) - document.location.href = guestTrackingUrl+'?id_order='+encodeURIComponent(array_split[1])+'&email='+encodeURIComponent(array_split[2]); - else - document.location.href = historyUrl; - } + { + if (isGuest) + document.location.href = guestTrackingUrl+'?id_order='+encodeURIComponent(array_split[1])+'&email='+encodeURIComponent(array_split[2]); + else + document.location.href = historyUrl; + } }, error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to confirm the order \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} }); @@ -266,8 +225,11 @@ function saveAddress(type) params += 'address2='+encodeURIComponent($('#address2'+(type == 'invoice' ? '_invoice' : '')).val())+'&'; params += 'postcode='+encodeURIComponent($('#postcode'+(type == 'invoice' ? '_invoice' : '')).val())+'&'; params += 'city='+encodeURIComponent($('#city'+(type == 'invoice' ? '_invoice' : '')).val())+'&'; - params += 'id_country='+encodeURIComponent($('#id_country'+(type == 'invoice' ? '_invoice' : '')).val())+'&'; + params += 'id_country='+encodeURIComponent($('#id_country').val())+'&'; + if ($('#id_state'+(type == 'invoice' ? '_invoice' : '')).val()) + { params += 'id_state='+encodeURIComponent($('#id_state'+(type == 'invoice' ? '_invoice' : '')).val())+'&'; + } params += 'other='+encodeURIComponent($('#other'+(type == 'invoice' ? '_invoice' : '')).val())+'&'; params += 'phone='+encodeURIComponent($('#phone'+(type == 'invoice' ? '_invoice' : '')).val())+'&'; params += 'phone_mobile='+encodeURIComponent($('#phone_mobile'+(type == 'invoice' ? '_invoice' : '')).val())+'&'; @@ -278,18 +240,18 @@ function saveAddress(type) var result = false; $.ajax({ - type: 'POST', - url: addressUrl, - async: false, - cache: false, - dataType : "json", - data: 'ajax=true&submitAddress=true&type='+type+'&'+params+'&token=' + static_token, - success: function(jsonData) - { + type: 'POST', + url: addressUrl, + async: false, + cache: false, + dataType : "json", + data: 'ajax=true&submitAddress=true&type='+type+'&'+params+'&token=' + static_token, + success: function(jsonData) + { if (jsonData.hasError) { - var tmp = ''; - var i = 0; + var tmp = ''; + var i = 0; for(error in jsonData.errors) //IE6 bug fix if(error != 'indexOf') @@ -315,8 +277,13 @@ function saveAddress(type) result = true; } }, - error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save adresses \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} - }); + error: function(XMLHttpRequest, textStatus, errorThrown) { + alert("TECHNICAL ERROR: unable to save adresses \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); + $('#opc_new_account-overlay').fadeOut('slow'); + $('#opc_delivery_methods-overlay').fadeOut('slow'); + $('#opc_payment_methods-overlay').fadeOut('slow'); + } + }); return result; } @@ -335,6 +302,10 @@ function updateNewAccountToAddressBlock() data: 'ajax=true&method=getAddressBlockAndCarriersAndPayments&token=' + static_token , success: function(json) { + isLogged = 1; + if (json.no_address == 1) + document.location.href = addressUrl; + $('#opc_new_account').fadeOut('fast', function() { $('#opc_new_account').html(json.order_opc_adress); // update block user info @@ -348,7 +319,7 @@ function updateNewAccountToAddressBlock() $('#opc_new_account').fadeIn('fast', function() { updateCartSummary(json.summary); updateAddressesDisplay(true); - updateCarrierList(json.carrier_list); + updateCarrierList(json.carrier_data); updatePaymentMethods(json); if ($('#gift-price').length == 1) $('#gift-price').html(json.gift_price); @@ -357,7 +328,11 @@ function updateNewAccountToAddressBlock() }); }); }, - error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to send login informations \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} + error: function(XMLHttpRequest, textStatus, errorThrown) { + alert("TECHNICAL ERROR: unable to send login informations \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); + $('#opc_delivery_methods-overlay').fadeOut('slow'); + $('#opc_payment_methods-overlay').fadeOut('slow'); + } }); } @@ -433,7 +408,7 @@ $(function() { async: false, cache: false, dataType : "json", - data: 'SubmitLogin=true&ajax=true&email='+encodeURIComponent($('#login_email').val())+'&passwd='+encodeURIComponent($('#passwd').val())+'&token=' + static_token , + data: 'SubmitLogin=true&ajax=true&email='+encodeURIComponent($('#login_email').val())+'&passwd='+encodeURIComponent($('#login_passwd').val())+'&token=' + static_token , success: function(jsonData) { if (jsonData.hasError) @@ -577,6 +552,7 @@ $(function() { // force to refresh carrier list if (isGuest) { + isLogged = 1; $('#opc_account_saved').fadeIn('slow'); $('#submitAccount').hide(); updateAddressSelection(); @@ -588,7 +564,12 @@ $(function() { $('#opc_delivery_methods-overlay').fadeOut('slow'); $('#opc_payment_methods-overlay').fadeOut('slow'); }, - error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save account \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} + error: function(XMLHttpRequest, textStatus, errorThrown) { + alert("TECHNICAL ERROR: unable to save account \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); + $('#opc_new_account-overlay').fadeOut('slow'); + $('#opc_delivery_methods-overlay').fadeOut('slow'); + $('#opc_payment_methods-overlay').fadeOut('slow'); + } }); return false; }); @@ -598,15 +579,15 @@ $(function() { $('#message').blur(function() { $('#opc_delivery_methods-overlay').fadeIn('slow'); $.ajax({ - type: 'POST', - url: orderOpcUrl, - async: false, - cache: false, - dataType : "json", - data: 'ajax=true&method=updateMessage&message=' + encodeURIComponent($('#message').val()) + '&token=' + static_token , - success: function(jsonData) - { - if (jsonData.hasError) + type: 'POST', + url: orderOpcUrl, + async: false, + cache: false, + dataType : "json", + data: 'ajax=true&method=updateMessage&message=' + encodeURIComponent($('#message').val()) + '&token=' + static_token , + success: function(jsonData) + { + if (jsonData.hasError) { var errors = ''; for(error in jsonData.errors) @@ -615,11 +596,14 @@ $(function() { errors += jsonData.errors[error] + "\n"; alert(errors); } - else - $('#opc_delivery_methods-overlay').fadeOut('slow'); + else + $('#opc_delivery_methods-overlay').fadeOut('slow'); }, - error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save message \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} - }); + error: function(XMLHttpRequest, textStatus, errorThrown) { + alert("TECHNICAL ERROR: unable to save message \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); + $('#opc_delivery_methods-overlay').fadeOut('slow'); + } + }); }); // Recyclable checkbox @@ -646,8 +630,8 @@ $(function() { updateCarrierSelectionAndGift(); }); - // TOS - $('#cgv').click(function() { + // Term Of Service (TOS) + $('#cgv').live('click', function() { if ($('#cgv:checked').length != 0) var checked = 1; else @@ -655,19 +639,19 @@ $(function() { $('#opc_payment_methods-overlay').fadeIn('slow'); $.ajax({ - type: 'POST', - url: orderOpcUrl, - async: true, - cache: false, - dataType : "json", - data: 'ajax=true&method=updateTOSStatusAndGetPayments&checked=' + checked + '&token=' + static_token, - success: function(json) - { + type: 'POST', + url: orderOpcUrl, + async: true, + cache: false, + dataType : "json", + data: 'ajax=true&method=updateTOSStatusAndGetPayments&checked=' + checked + '&token=' + static_token, + success: function(json) + { $('div#HOOK_TOP_PAYMENT').html(json.HOOK_TOP_PAYMENT); $('#opc_payment_methods-content div#HOOK_PAYMENT').html(json.HOOK_PAYMENT); $('#opc_payment_methods-overlay').fadeOut('slow'); - } - }); + } + }); }); $('#opc_account_form input,select,textarea').change(function() { @@ -679,3 +663,81 @@ $(function() { }); }); + +function multishippingMode(it) +{ + if ($(it).attr('checked')) + { + $('#address_delivery').hide(); + $('#address_invoice').removeClass('alternate_item').addClass('item'); + $('#multishipping_mode_box').addClass('on'); + + $('#link_multishipping_form').click(function() {return false;}); + + $('#link_multishipping_form').fancybox({ + 'transitionIn': 'elastic', + 'transitionOut': 'elastic', + 'type': 'ajax', + 'onClosed': function() + { + // Reload the cart + $.ajax({ + url: orderOpcUrl, + data: 'ajax=true&method=cartReload', + dataType : 'html', + cache: false, + success: function(data) { + $('#cart_summary').replaceWith($(data).find('#cart_summary')); + } + }); + updateCarrierSelectionAndGift(); + }, + 'onStart': function() + { + // Removing all ids on the cart to avoid conflic with the new one on the fancybox + // This action could "break" the cart design, if css rules use ids of the cart + $.each($('#cart_summary *'), function(it, el) { + $(el).attr('id', ''); + }); + }, + 'onComplete': function() + { + cleanSelectAddressDelivery(); + } + }); + } + else + { + $('#address_delivery').show(); + $('#address_invoice').removeClass('item').addClass('alternate_item'); + $('#multishipping_mode_box').removeClass('on'); + + // Disable multi address shipping + $.ajax({ + url: orderOpcUrl, + async: true, + cache: false, + data: 'ajax=true&method=noMultiAddressDelivery', + }); + + // Reload the cart + $.ajax({ + url: orderOpcUrl, + async: true, + cache: false, + data: 'ajax=true&method=cartReload', + dataType : 'html', + success: function(data) { + $('#cart_summary').replaceWith($(data).find('#cart_summary')); + } + }); + } +} + +$(document).ready(function() { + // If the multishipping mode is off assure us the checkbox "I want to specify a delivery address for each products I order." is unchecked. + $('#multishipping_mode_checkbox').attr('checked', false); + // If the multishipping mode is on, check the box "I want to specify a delivery address for each products I order.". + if (typeof(multishipping_mode) != 'undefined' && multishipping_mode) + $('#multishipping_mode_checkbox').click() +}); diff --git a/themes/default/order-address.tpl b/themes/default/order-address.tpl index 6874c6b20..773489acb 100644 --- a/themes/default/order-address.tpl +++ b/themes/default/order-address.tpl @@ -19,7 +19,7 @@ * * @author PrestaShop SA * @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 6594 $ +* @version Release: $Revision: 7471 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} @@ -67,7 +67,6 @@ - + {if {Configuration::get('PS_ALLOW_MULTISHIPPING')}} +
+
+
{l s='Multi-shipping'}
+
+ +
+ +
+ +
+ {/if}
{/if} diff --git a/themes/prestashop/css/global.css b/themes/prestashop/css/global.css index a698180c6..f204bb0f5 100644 --- a/themes/prestashop/css/global.css +++ b/themes/prestashop/css/global.css @@ -1026,13 +1026,12 @@ p.cart_navigation .button_large { float: left } p.cart_navigation .exclusive, p.cart_navigation .exclusive_large, p.cart_navigation .exclusive_large_disabled { float: right } -p.cart_navigation .multishipping-button { margin-right: 10px } p.cart_navigation_extra { text-align: center; width: auto } - +p.cart_navigation .multishipping-button { margin-right: 10px } .address-form-multishipping { padding: 10px 0px; } #multishipping_mode_box { border: 1px solid #D0D3D8;