Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. function addToCart(product_id, quantity, option_id, option_value) {
  2. quantity = typeof(quantity) != 'undefined' ? quantity : 1;
  3. option_value = typeof(option_value) != 'undefined' ? option_value : 0;
  4. option_id = typeof(option_id) != 'undefined' ? option_id : 0;
  5. jQuery.ajax({
  6. url: 'index.php?route=checkout/cart/add',
  7. type: 'post',
  8. cache: false,
  9. data: 'product_id=' + product_id + '&quantity=' + quantity + '&option_id=' + option_id + '&option_value=' + option_value+'&rnd=' + Math.random(),
  10. dataType: 'json',
  11. success: function(jsonObj) {
  12. $('.success, .warning, .attention, .information, .error').remove();
  13.  
  14. if (jsonObj['redirect']) {
  15. location = jsonObj['redirect'];
  16. }
  17.  
  18. if (jsonObj['success']) {
  19. $('#notification').html('<div class="success" style="display: none;">' + jsonObj['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
  20.  
  21. $('.success').fadeIn('slow');
  22.  
  23. $('#cart-total').html(jsonObj['total']);
  24.  
  25. $('html, body').animate({ scrollTop: 0 }, 'slow');
  26. }
  27. }
  28. });
  29. }
  30.  
  31. {"success":"Added to cart!","total":"1 product(s) - 52,48u043bu0432."}
  32.  
  33. jsonObj: Object
  34. success: "Added to cart!"
  35. total: "1 product(s) - 52.48ะปะฒ."
  36. __proto__: Object
  37.  
  38. $('base').attr('href')
  39.  
  40. option_value = typeof(option_value) != 'undefined' ? option_value : 0;
  41. option_id = typeof(option_id) != 'undefined' ? option_id : 0;
  42. var base = jQuery('base').attr('href');
  43. jQuery.ajax({
  44. url: base + 'index.php?route=checkout/cart/add',
  45. type: 'post',
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement