[-] 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
This commit is contained in:
mDeflotte
2012-03-14 13:40:39 +00:00
parent fa77f2cddc
commit 72917cad5c
6 changed files with 111 additions and 52 deletions
+3 -3
View File
@@ -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;
}
+41 -29
View File
@@ -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<jsonData.discounts.length;i++)
$('#vouchers tbody').html('');
for (i=0;i<jsonData.discounts.length;i++)
{
if (parseFloat(jsonData.discounts[i].price_float) > 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($(
'<tr class="bloc_cart_voucher" id="bloc_cart_voucher_'+jsonData.discounts[i].id+'">'
+' <td class="quantity">1x</td>'
+' <td class="name" title="'+jsonData.discounts[i].description+'">'+jsonData.discounts[i].name+'</td>'
+' <td class="price">-'+jsonData.discounts[i].price+'</td>'
+' <td class="delete"><a class="delete_voucher" href="'+jsonData.discounts[i].link+'" title="'+delete_txt+'"><img src="'+img_dir+'icon/delete.gif" alt="'+delete_txt+'" class="icon" /></a></td>'
+'</tr>'
));
}
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;
});
});
+1 -1
View File
@@ -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}
+3
View File
@@ -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;
}
+15 -12
View File
@@ -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 = '<b>{l s='Free shipping!' mod='blockcart' js=1}</b>';
var freeProductTranslation = '<b>{l s='Free!' mod='blockcart' js=1}</b>';
var delete_txt = '{l s='Delete' mod='blockcart'}';
var img_dir = '{$img_dir}';
</script>
{/if}
@@ -67,7 +69,7 @@ var freeProductTranslation = '<b>{l s='Free!' mod='blockcart' js=1}</b>';
<a class="cart_block_product_name" href="{$link->getProductLink($product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)}" title="{$product.name|escape:html:'UTF-8'}">
{$product.name|truncate:13:'...'|escape:html:'UTF-8'}</a>
<span class="remove_link">{if !isset($customizedDatas.$productId.$productAttributeId)}<a rel="nofollow" class="ajax_cart_block_remove_link" href="{$link->getPageLink('cart', true, NULL, "delete&amp;id_product={$product.id_product}&amp;ipa={$product.id_product_attribute}&amp;id_address_delivery={$product.id_address_delivery}&amp;token={$static_token}")}" title="{l s='remove this product from my cart' mod='blockcart'}">&nbsp;</a>{/if}</span>
<span class="price">{$product.total}
<span class="price">
{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 = '<b>{l s='Free!' mod='blockcart' js=1}</b>';
{/if}
<p {if $products}class="hidden"{/if} id="cart_block_no_products">{l s='No products' mod='blockcart'}</p>
{if $discounts|@count > 0}<table id="vouchers">
<table id="vouchers">
<tbody>
{foreach from=$discounts item=discount}
{if $discount.value_real > 0}
<tr class="bloc_cart_voucher" id="bloc_cart_voucher_{$discount.id_discount}">
<td class="quantity">1x</td>
<td class="name" title="{$discount.description}">{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|escape:'htmlall':'UTF-8'}</td>
<td class="price">-{if $priceDisplay == 1}{convertPrice price=$discount.value_tax_exc}{else}{convertPrice price=$discount.value_real}{/if}</td>
<td class="delete"><a href="{$link->getPageLink('$order_process.php', true)}?deleteDiscount={$discount.id_discount}" title="{l s='Delete'}"><img src="{$img_dir}icon/delete.gif" alt="{l s='Delete'}" class="icon" /></a></td>
</tr>
{if $discounts|@count > 0}
{foreach from=$discounts item=discount}
{if $discount.value_real > 0}
<tr class="bloc_cart_voucher" id="bloc_cart_voucher_{$discount.id_discount}">
<td class="quantity">1x</td>
<td class="name" title="{$discount.description}">{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|escape:'htmlall':'UTF-8'}</td>
<td class="price">-{if $priceDisplay == 1}{convertPrice price=$discount.value_tax_exc}{else}{convertPrice price=$discount.value_real}{/if}</td>
<td class="delete"><a class="delete_voucher" href="{$link->getPageLink('$order_process.php', true)}?deleteDiscount={$discount.id_discount}" title="{l s='Delete' mod='blockcart'}"><img src="{$img_dir}icon/delete.gif" alt="{l s='Delete' mod='blockcart'}" class="icon" /></a></td>
</tr>
{/if}
{/foreach}
{/if}
{/foreach}
</tbody>
</table>
{/if}
<p id="cart-prices">
<span id="cart_block_shipping_cost" class="price ajax_cart_shipping_cost">{$shipping_cost}</span>
+48 -7
View File
@@ -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']);