Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // add a product in the cart via ajax
- add : function(idProduct, idCombination, addedFromProductPage, callerElement, quantity, whishlist){
- $.ajax({
- type: 'POST',
- headers: { "cache-control": "no-cache" },
- url: baseUri + '?rand=' + new Date().getTime(),
- async: true,
- cache: false,
- dataType : "json",
- data: 'controller=cart&add=1&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): '' + '&id_customization=' + ((typeof customizationId !== 'undefined') ? customizationId : 0)),
- success: function(jsonData,textStatus,jqXHR)
- {
- if (!jsonData.hasError)
- {
- var latestAddedProduct = jsonData.products[jsonData.products.length-1].name
- ajaxCart.updateCartInformation(jsonData, addedFromProductPage);
- if (jsonData.crossSelling) {
- $('.vi__similar__slider').html(jsonData.crossSelling);
- } else {
- $('.vi__similar__title').hide();
- $('.vi__similar').hide();
- }
- toastr.success('Prekė sėkmingai pridėta į krepšelį', 'Prekių krepšelis');
- // If product page remove loader class
- $('.vi__product__information').removeClass('vi__loader--visible');
- if (idCombination)
- $(jsonData.products).each(function(){
- if (this.id != undefined && this.id == parseInt(idProduct) && this.idCombination == parseInt(idCombination))
- if (contentOnly)
- window.parent.ajaxCart.updateLayer(this);
- else
- ajaxCart.updateLayer(this);
- });
- else
- $(jsonData.products).each(function(){
- if (this.id != undefined && this.id == parseInt(idProduct))
- if (contentOnly)
- window.parent.ajaxCart.updateLayer(this);
- else
- ajaxCart.updateLayer(this);
- });
- }
- else
- {
- ajaxCart.updateCart(jsonData);
- $('.vi__product__information').removeClass('vi__loader--visible');
- }
- // Remove loader effect after popup call
- $('.ajax_block_product').removeClass('vi__loader--visible');
- },
- error: function(XMLHttpRequest, textStatus, errorThrown)
- {
- // var error = "Impossible to add the product to the cart.<br/>textStatus: '" + textStatus + "'<br/>errorThrown: '" + errorThrown + "'<br/>responseText:<br/>" + XMLHttpRequest.responseText;
- var error = "Nepavyko pridėti prekės į krepšelį"
- // Remove loader effect after error show
- $('.ajax_block_product').removeClass('vi__loader--visible');
- $('.vi__product__information').removeClass('vi__loader--visible');
- toastr.error(error, 'Prekių krepšelis');
- }
- });
- },
- //remove a product from the cart via ajax
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement