Tepster Posted June 8, 2013 Share Posted June 8, 2013 Hi, in the file shopping-cart-product-line.tpl is the table with produkts. There is the + and - for add or delete the produkt. After click on this buttons it is loaded by AJAX. I need a javascript which does functionality of this buttons by AJAX. Please, can you help me? Thank (Sorry for my bad English) Link to comment Share on other sites More sharing options...
vekia Posted June 8, 2013 Share Posted June 8, 2013 themes/default/js/cart-summary.js there is: $('.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;}); in the same file you've got: function upQuantity(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 += jsonData.errors[error] + "\n"; alert(errors); $('input[name=quantity_'+ id +']').val($('input[name=quantity_'+ id +'_hidden]').val()); } else { if (jsonData.refresh) location.reload(); updateCartSummary(jsonData.summary); 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') alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); } }); } function downQuantity(id, qty) { var val = $('input[name=quantity_'+id+']').val(); var newVal = val; if(typeof(qty) == 'undefined' || !qty) { qty = 1; newVal = val - 1; } else if (qty < 0) qty = -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]); 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]); if (newVal > 0 || $('#product_'+id+'_gift').length) { $.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 +'&op=down' + ((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 += jsonData.errors[error] + "\n"; alert(errors); $('input[name=quantity_'+ id +']').val($('input[name=quantity_'+ id +'_hidden]').val()); } else { if (jsonData.refresh) location.reload(); updateCartSummary(jsonData.summary); if (customizationId !== 0) updateCustomizedDatas(jsonData.customizedDatas); updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); if (newVal == 0) $('#product_'+id).hide(); if (typeof(getCarrierListAndUpdate) !== 'undefined') getCarrierListAndUpdate(); if (typeof(updatePaymentMethodsDisplay) !== 'undefined') updatePaymentMethodsDisplay(); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { if (textStatus !== 'abort') alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); } }); } else { deleteProductFromSummary(id); } } Link to comment Share on other sites More sharing options...
Tepster Posted June 8, 2013 Author Share Posted June 8, 2013 Thank you Link to comment Share on other sites More sharing options...
vekia Posted June 8, 2013 Share Posted June 8, 2013 you're welcome i marked this thread as solved if you've got any questions related to this case - feel free to continue discussion regards Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now