Why the change in the number of items in the cart PrestaShop does not always work?

Hello!

Prompt, please, who had an affair with PrestaShop in the basket when you change the quantity of any item should change the number in the table and the total number in the header. Now when you add or decrease the number changes every time, it is noticeable if you manually refresh the page. While in console there are no errors.

$('.cart_quantity_up').off('click').on('click', function(e){
e.preventDefault();
 upQuantity($(this).attr('id').replace('cart_quantity_up_', "));
});

upQuantity function(id, qty)
{
 if (typeof(qty) == 'undefined' || !qty)
 qty = 1;
 var customizationId = 0;
 var productId = 0;
 var productAttributeId = 0;
 var id_address_delivery = 0;
 var ids = 0;
 ids = id.split('_');
 productId = parseInt(ids[0]);
 if (typeof(ids[1]) !== 'undefined')
 productAttributeId = parseInt(ids[1]);
 if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom')
 customizationId = parseInt(ids[2]);
 if (typeof(ids[3]) !== 'undefined')
 id_address_delivery = parseInt(ids[3]);

$.ajax({
 type: 'POST',
 headers: { "cache-control": "no-cache" },
 url: baseUri + '?rand=' + new Date().getTime(),
 async: true,
 cache: false,
 dataType: 'json',
 data: 'controller=cart'
 + '&ajax=true'
 + '&add=true'
 + '&getproductprice=true'
 + '&summary=true'
 + '&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)
{
 var errors = ";
 for(var error in jsonData.errors)
 //IE6 bug fix
 if(error !== 'indexOf')
 errors += $('
').html(jsonData.errors[error]).text() + "\n"; if (!!$.prototype.fancybox) $.fancybox.open([ { type: 'inline', autoScale: true, minHeight: 30, content: '<p class="fancybox-error">' + errors + '</p>' }], { padding: 0 }); else alert(errors); $('input[name=quantity_'+ id +']').val($('input[name=quantity_'+ id +'_hidden]').val()); } else { if (jsonData.refresh) location.reload(); updateCartSummary(jsonData.summary); if (window.ajaxCart != undefined) ajaxCart.updateCart(jsonData); if (customizationId !== 0) updateCustomizedDatas(jsonData.customizedDatas); updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); if (typeof(getCarrierListAndUpdate) !== 'undefined') getCarrierListAndUpdate(); if (typeof(updatePaymentMethodsDisplay) !== 'undefined') updatePaymentMethodsDisplay(); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { if (textStatus !== 'abort') { error = "TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown:" + XMLHttpRequest + "\n" + 'Text status:' + textStatus; if (!!$.prototype.fancybox) $.fancybox.open([ { type: 'inline', autoScale: true, minHeight: 30, content: '<p class="fancybox-error">' + error + '</p>' }], { padding: 0 }); else alert(error); } } }); }


 {if isset($cannotModify) AND $cannotModify == 1}
 <span>{if $quantityDisplayed == 0 AND isset($customizedDatas.$productId.$productAttributeId)}{$customizedDatas.$productId.$productAttributeId|@count}{else}{$product.cart_quantity-$quantityDisplayed}{/if}</span>
{else}
 <input type="hidden" value="{$customization.quantity}" name="quantity_{$product.id_product}_{$product.id_product_attribute}_{$id_customization}_{$product.id_address_delivery|intval}_hidden">
 <input type="text" value="{$customization.quantity}" class="cart_quantity_input form-control grey" name="quantity_{$product.id_product}_{$product.id_product_attribute}_{$id_customization}_{$product.id_address_delivery|intval}">
 <div class="cart_quantity_button clearfix">
 {if $product.minimal_quantity < ($customization.quantity -$quantityDisplayed) OR $product.minimal_quantity <= 1}
 <a id="cart_quantity_down_{$product.id_product}_{$product.id_product_attribute}_{$id_customization}_{$product.id_address_delivery|intval}" class="cart_quantity_down btn btn-default button-minus" href="{$link->getPageLink('cart', true, NULL, " add="1&id_product={$product.id_product|intval}&ipa={$product.id_product_attribute|intval}&id_address_delivery={$product.id_address_delivery}&id_customization={$id_customization}&op=down&token={$token_cart}")|escape:'html':'UTF-8'}"" rel="nofollow" title="{l s='Subtract'}">
 <span><i class="icon-minus"></i></span>
</a>
{else}
 <a id="cart_quantity_down_{$product.id_product}_{$product.id_product_attribute}_{$id_customization}" class="cart_quantity_down btn btn-default button-minus disabled" href="#" title="{l s='Subtract'}">
 <span><i class="icon-minus"></i></span>
</a>
{/if}
 <a id="cart_quantity_up_{$product.id_product}_{$product.id_product_attribute}_{$id_customization}_{$product.id_address_delivery|intval}" class="cart_quantity_up btn btn-default button-plus" href="{$link->getPageLink('cart', true, NULL, " add="1&id_product={$product.id_product|intval}&ipa={$product.id_product_attribute|intval}&id_address_delivery={$product.id_address_delivery}&id_customization={$id_customization}&token={$token_cart}")|escape:'html':'UTF-8'}"" rel="nofollow" title="{l s='Add'}">
 <span><i class="icon-plus"></i></span>
</a>
</div>
{/if}
 
June 8th 19 at 16:49
0 answer

Find more questions by tags PrestashopJavaScriptPHPWeb Development