From 72917cad5c2997d89dba3b4cc8fea86ab258f9e9 Mon Sep 17 00:00:00 2001 From: mDeflotte Date: Wed, 14 Mar 2012 13:40:39 +0000 Subject: [PATCH] [-] FO : #PSTEST-990 - Fix bug with bad ajax return on adding product to the cart with a new cart reduction applyed git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14150 b9a71923-0436-4b27-9f14-aed3839534dd --- controllers/front/CartController.php | 6 +-- modules/blockcart/ajax-cart.js | 70 ++++++++++++++++------------ modules/blockcart/blockcart-json.tpl | 2 +- modules/blockcart/blockcart.css | 3 ++ modules/blockcart/blockcart.tpl | 27 ++++++----- themes/default/js/cart-summary.js | 55 +++++++++++++++++++--- 6 files changed, 111 insertions(+), 52 deletions(-) diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index bcdf1eb31..8fcaaa22d 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -114,7 +114,7 @@ class CartControllerCore extends FrontController } } $removed = CartRule::autoRemoveFromCart(); - if (count($removed)) + if (count($removed) && (int)Tools::getValue('allow_refresh')) $this->ajax_refresh = true; } @@ -232,14 +232,14 @@ class CartControllerCore extends FrontController else { $cart_rules2 = $this->context->cart->getCartRules(); - if (count($cart_rules2) != count($cart_rules)) + if (count($cart_rules2) != count($cart_rules) && (int)Tools::getValue('allow_refresh')) $this->ajax_refresh = true; } } } $removed = CartRule::autoRemoveFromCart(); - if (count($removed)) + if (count($removed) && (int)Tools::getValue('allow_refresh')) $this->ajax_refresh = true; } diff --git a/modules/blockcart/ajax-cart.js b/modules/blockcart/ajax-cart.js index 1a6b8d864..4b079fe6d 100644 --- a/modules/blockcart/ajax-cart.js +++ b/modules/blockcart/ajax-cart.js @@ -366,30 +366,29 @@ var ajaxCart = { //refresh display of vouchers (needed for vouchers in % of the total) refreshVouchers : function (jsonData) { - if (jsonData.discounts = undefined || jsonData.discounts.length == 0) - $('#vouchers').remove(); + if (typeof(jsonData.discounts) == 'undefined' || jsonData.discounts.length == 0) + $('#vouchers').hide(); else { - $('.bloc_cart_voucher').each(function(){ - var idElmt = $(this).attr('id').replace('bloc_cart_voucher_',''); - var toDelete = true; - for (i=0;i 0) { - if (jsonData.discounts[i].id == idElmt && parseFloat(jsonData.discounts[i].price_float) > 0) - { - $('#bloc_cart_voucher_' + idElmt + ' td.price').text(jsonData.discounts[i].price); - toDelete = false; - } + $('#vouchers tbody').append($( + '' + +' 1x' + +' '+jsonData.discounts[i].name+'' + +' -'+jsonData.discounts[i].price+'' + +' '+delete_txt+'' + +'' + )); } - if (toDelete) - { - $('#bloc_cart_voucher_' + idElmt).fadeTo('fast', 0, function(){ - $(this).remove(); - }); - } - }); - } + } + $('#vouchers').show(); + } }, @@ -629,18 +628,18 @@ var ajaxCart = { }; function HoverWatcher(selector){ - this.hovering = false; - var self = this; + this.hovering = false; + var self = this; - this.isHoveringOver = function() { - return self.hovering; - } + this.isHoveringOver = function() { + return self.hovering; + } - $(selector).hover(function() { - self.hovering = true; - }, function() { - self.hovering = false; - }) + $(selector).hover(function() { + self.hovering = true; + }, function() { + self.hovering = false; + }) } //when document is loaded... @@ -675,5 +674,18 @@ $(document).ready(function(){ $("#cart_block").stop(true, true).slideUp(450); }, 200); }); + + $('.delete_voucher').live('click', function() { + $.ajax({url:$(this).attr('href')}); + $(this).parent().parent().remove(); + if ($('body').attr('id') == 'order' || $('body').attr('id') == 'order-opc') + { + if (typeof(updateAddressSelection) != 'undefined') + updateAddressSelection(); + else + location.reload(); + } + return false; + }); }); diff --git a/modules/blockcart/blockcart-json.tpl b/modules/blockcart/blockcart-json.tpl index b10946535..47ae69884 100644 --- a/modules/blockcart/blockcart-json.tpl +++ b/modules/blockcart/blockcart-json.tpl @@ -88,7 +88,7 @@ "name": "{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|addslashes|replace:'\\\'':'\''}", "description": "{$discount.description|addslashes|replace:'\\\'':'\''}", "nameDescription": "{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|addslashes|replace:'\\\'':'\''}", - "link": "{$link->getPageLink('order', true, NULL, "deleteDiscount={$discount.id_discount}")}", + "link": "{$link->getPageLink("$order_process", true, NULL, "deleteDiscount={$discount.id_discount}")}", "price": "{if $priceDisplay == 1}{convertPrice|html_entity_decode:2:'UTF-8' price=$discount.value_tax_exc}{else}{convertPrice|html_entity_decode:2:'UTF-8' price=$discount.value_real}{/if}", "price_float": "{if $priceDisplay == 1}{$discount.value_tax_exc}{else}{$discount.value_real}{/if}" {rdelim} diff --git a/modules/blockcart/blockcart.css b/modules/blockcart/blockcart.css index 0e0c3b35d..dfdb26b94 100644 --- a/modules/blockcart/blockcart.css +++ b/modules/blockcart/blockcart.css @@ -106,6 +106,9 @@ min-width:18px } #cart_block table#vouchers tr td.delete{ + padding-left: 0; + padding-right: 0; text-align: right; + width: 15px; } diff --git a/modules/blockcart/blockcart.tpl b/modules/blockcart/blockcart.tpl index 6e21dfba8..b8d8d4f3e 100644 --- a/modules/blockcart/blockcart.tpl +++ b/modules/blockcart/blockcart.tpl @@ -34,6 +34,8 @@ var customizationIdMessage = '{l s='Customization #' mod='blockcart' js=1}'; var removingLinkText = '{l s='remove this product from my cart' mod='blockcart' js=1}'; var freeShippingTranslation = '{l s='Free shipping!' mod='blockcart' js=1}'; var freeProductTranslation = '{l s='Free!' mod='blockcart' js=1}'; +var delete_txt = '{l s='Delete' mod='blockcart'}'; +var img_dir = '{$img_dir}'; {/if} @@ -67,7 +69,7 @@ var freeProductTranslation = '{l s='Free!' mod='blockcart' js=1}'; {$product.name|truncate:13:'...'|escape:html:'UTF-8'} {if !isset($customizedDatas.$productId.$productAttributeId)} {/if} - {$product.total} + {if $product.total > 0} {if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice p="`$product.total`"}{else}{displayWtPrice p="`$product.total_wt`"}{/if} {else} @@ -105,21 +107,22 @@ var freeProductTranslation = '{l s='Free!' mod='blockcart' js=1}'; {/if}

{l s='No products' mod='blockcart'}

- {if $discounts|@count > 0} +
- {foreach from=$discounts item=discount} - {if $discount.value_real > 0} - - - - - - + {if $discounts|@count > 0} + {foreach from=$discounts item=discount} + {if $discount.value_real > 0} + + + + + + + {/if} + {/foreach} {/if} - {/foreach}
1x{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|escape:'htmlall':'UTF-8'}-{if $priceDisplay == 1}{convertPrice price=$discount.value_tax_exc}{else}{convertPrice price=$discount.value_real}{/if}{l s='Delete'}
1x{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|escape:'htmlall':'UTF-8'}-{if $priceDisplay == 1}{convertPrice price=$discount.value_tax_exc}{else}{convertPrice price=$discount.value_real}{/if}{l s='Delete' mod='blockcart'}
- {/if}

{$shipping_cost} diff --git a/themes/default/js/cart-summary.js b/themes/default/js/cart-summary.js index 694bc97d8..e857f374c 100644 --- a/themes/default/js/cart-summary.js +++ b/themes/default/js/cart-summary.js @@ -95,7 +95,8 @@ function changeAddressDelivery(obj) +'&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, + +'&token='+static_token + +'&allow_refresh=1', success: function(jsonData) { // The product exist @@ -154,7 +155,14 @@ function changeAddressDelivery(obj) 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 , + 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 + +'&allow_refresh=1', success: function(jsonData) { if (jsonData.error) @@ -250,7 +258,13 @@ function deleteProductFromSummary(id) 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 , + 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 + +'&allow_refresh=1', success: function(jsonData) { if (jsonData.hasError) @@ -331,7 +345,17 @@ function upQuantity(id, qty) 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 , + 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 + +'&allow_refresh=1', success: function(jsonData) { if (jsonData.hasError) @@ -392,7 +416,18 @@ function downQuantity(id, qty) 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 , + 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 + +'&allow_refresh=1', success: function(jsonData) { if (jsonData.hasError) @@ -651,7 +686,8 @@ $(document).ready(function() { cache: false, data: 'controller=cart&ajax=true&allowSeperatedPackage&value=' +($(this).attr('checked') ? '1' : '0') - +'&token='+static_token, + +'&token='+static_token + +'&allow_refresh=1', success: function(jsonData) { if (typeof(getCarrierListAndUpdate) != 'undefined') @@ -687,7 +723,12 @@ function updateExtraCarrier(id_delivery_option, id_address) async: true, cache: false, dataType : "json", - data: 'ajax=true&method=updateExtraCarrier&id_address='+id_address+'&id_delivery_option='+id_delivery_option+'&token=' + static_token, + data: 'ajax=true' + +'&method=updateExtraCarrier' + +'&id_address='+id_address + +'&id_delivery_option='+id_delivery_option + +'&token='+static_token + +'&allow_refresh=1', success: function(jsonData) { $('#HOOK_EXTRACARRIER_'+id_address).html(jsonData['content']);