Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.74 KB | None | 0 0
  1. // add a product in the cart via ajax
  2.     add : function(idProduct, idCombination, addedFromProductPage, callerElement, quantity, whishlist){
  3.        
  4.         $.ajax({
  5.             type: 'POST',
  6.             headers: { "cache-control": "no-cache" },
  7.             url: baseUri + '?rand=' + new Date().getTime(),
  8.             async: true,
  9.             cache: false,
  10.             dataType : "json",
  11.             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)),
  12.             success: function(jsonData,textStatus,jqXHR)
  13.             {
  14.                 if (!jsonData.hasError)
  15.                 {
  16.                     var latestAddedProduct = jsonData.products[jsonData.products.length-1].name
  17.                     ajaxCart.updateCartInformation(jsonData, addedFromProductPage);
  18.  
  19.                     if (jsonData.crossSelling) {
  20.                         $('.vi__similar__slider').html(jsonData.crossSelling);
  21.                     } else {
  22.                         $('.vi__similar__title').hide();
  23.                         $('.vi__similar').hide();
  24.                     }
  25.  
  26.                     toastr.success('Prekė sėkmingai pridėta į krepšelį', 'Prekių krepšelis');
  27.  
  28.                     // If product page remove loader class
  29.                     $('.vi__product__information').removeClass('vi__loader--visible');
  30.  
  31.                     if (idCombination)
  32.                         $(jsonData.products).each(function(){
  33.                             if (this.id != undefined && this.id == parseInt(idProduct) && this.idCombination == parseInt(idCombination))
  34.                                 if (contentOnly)
  35.                                     window.parent.ajaxCart.updateLayer(this);
  36.                                 else
  37.                                     ajaxCart.updateLayer(this);
  38.                         });
  39.                     else
  40.                         $(jsonData.products).each(function(){
  41.                             if (this.id != undefined && this.id == parseInt(idProduct))
  42.                                 if (contentOnly)
  43.                                     window.parent.ajaxCart.updateLayer(this);
  44.                                 else
  45.                                     ajaxCart.updateLayer(this);
  46.                         });
  47.                 }
  48.                 else
  49.                 {
  50.                     ajaxCart.updateCart(jsonData);
  51.                     $('.vi__product__information').removeClass('vi__loader--visible');
  52.  
  53.                 }
  54.                
  55.                 // Remove loader effect after popup call
  56.                 $('.ajax_block_product').removeClass('vi__loader--visible');
  57.             },
  58.             error: function(XMLHttpRequest, textStatus, errorThrown)
  59.             {
  60.                 // var error = "Impossible to add the product to the cart.<br/>textStatus: '" + textStatus + "'<br/>errorThrown: '" + errorThrown + "'<br/>responseText:<br/>" + XMLHttpRequest.responseText;
  61.                 var error = "Nepavyko pridėti prekės į krepšelį"
  62.  
  63.                 // Remove loader effect after error show
  64.                 $('.ajax_block_product').removeClass('vi__loader--visible');
  65.                 $('.vi__product__information').removeClass('vi__loader--visible');
  66.                 toastr.error(error, 'Prekių krepšelis');
  67.             }
  68.         });
  69.     },
  70.     //remove a product from the cart via ajax
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement