NikolayBezay

Gadecosmetics add two products to the cart.

Jul 16th, 2021
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. (function() {
  2. function addProductToTheCart(productId, pageRefresh) {
  3. try {
  4. var ACTION_URL = window.location.origin + '/cart/add.js?';
  5. var productData = {
  6. form_type: 'product',
  7. utf8: '%E2%9C%93',
  8. id: productId,
  9. quantity: 1
  10. };
  11.  
  12. for (const key in productData) {
  13. ACTION_URL += key + '=' + productData[key] + '&';
  14. }
  15.  
  16. var data = null;
  17. var xhr = new XMLHttpRequest();
  18. xhr.withCredentials = true;
  19. xhr.addEventListener('readystatechange', function () {
  20. if (this.readyState === 4) {
  21. console.log(this.responseText);
  22. if (pageRefresh) {
  23. window.location.reload();
  24. }
  25. }
  26. });
  27. xhr.open('POST', ACTION_URL);
  28. xhr.setRequestHeader('cache-control', 'no-cache');
  29. xhr.send(data);
  30. } catch(error) {
  31. console.log(error.message);
  32. }
  33. }
  34. var product1 = '39282690064419';
  35. var product2 = '32340515291171';
  36.  
  37. addProductToTheCart(product1, false);
  38. setTimeout(function() {
  39. addProductToTheCart(product2, true);
  40. },300);
  41. })();
Advertisement
Add Comment
Please, Sign In to add comment