Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. define(
  2. [
  3. 'jquery',
  4. 'uiComponent',
  5. 'Magento_Customer/js/customer-data'
  6. ],
  7. function (jQuery, Component, customerData) {
  8. 'use strict';
  9.  
  10. jQuery(document).on('click', '.tocart', function (e, config) {
  11.  
  12. let idForm = "#form-"+jQuery(this).attr('rel');
  13. let form = idForm;
  14. var sections = ['cart'];
  15. let formData = jQuery(idForm).serialize();
  16. let button = idForm+" button";
  17. jQuery(button).html("<span>Adicionando...</span>");
  18.  
  19.  
  20. jQuery.ajax({
  21. url: jQuery(form).attr('action'),
  22. data: formData,
  23. type: 'GET',
  24. //url: "tableticket/category/addproducts",
  25. //type: 'POST',
  26. beforeSend: function() {
  27. // show some loading icon
  28. console.log('beforeSend');
  29. jQuery('body').trigger('processStart');
  30.  
  31. },
  32. success: function(data, status, xhr) {
  33. // data contains your controller response
  34. customerData.invalidate(sections);
  35. customerData.reload(sections, true);
  36. console.log('success');
  37. jQuery(button).removeClass("bg_azul_light");
  38. jQuery(button).addClass('bg_salmao');
  39. jQuery(button).html("<span><i class=\"fa fa-pencil-square-o size18\"></i>Alterar Quantdade</span>");
  40. jQuery('body').trigger('processStop');
  41. },
  42. error: function (xhr, status, errorThrown) {
  43. console.log('Error happens. Try again.');
  44. console.log(errorThrown);
  45. jQuery('div.products-grid').trigger('processStop');
  46. }
  47.  
  48. });
  49.  
  50.  
  51. });
  52. }
  53. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement