Advertisement
NikolayBezay

Babyteva add to cart

May 12th, 2021
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.87 KB | None | 0 0
  1. <script>
  2. (function() {
  3.  
  4.     function adoricAddToCart(productId) {
  5.         console.log('product added - ', productId);
  6.         var formData = new FormData();
  7.         formData.append('quantity[]', 1);
  8.         formData.append('option', 'com_virtuemart');
  9.         formData.append('view', 'cart');
  10.         formData.append('virtuemart_product_id[]', productId);
  11.         var xhr = new XMLHttpRequest();
  12.         xhr.withCredentials = true;
  13.         xhr.addEventListener('readystatechange', function () {
  14.             if (this.readyState === 4) {
  15.                 console.log(this.responseText);
  16.             }
  17.         });
  18.         xhr.open('POST', 'https://babyteva.co.il/index.php?option=com_virtuemart&nosef=1&view=cart&task=addJS&format=json&lang=he');
  19.  
  20.         xhr.setRequestHeader('cache-control', 'no-cache');
  21.         xhr.send(formData);
  22.     }
  23.  
  24.     if (window.Element && !Element.prototype.closest) {
  25.        Element.prototype.closest = function(s) {
  26.            var matches = (this.document || this.ownerDocument).querySelectorAll(s),
  27.                i,
  28.                el = this;
  29.             do {
  30.             i = matches.length;
  31.             while (--i >= 0 && matches.item(i) !== el) {};
  32.             } while ((i < 0) && (el = el.parentElement));
  33.            return el;
  34.        };
  35.    }    
  36.    var currentCampaignRepeater = document.querySelector('.' + self.identifier + ' .repeater-content');
  37.    currentCampaignRepeater.addEventListener('click', function(event) {
  38.        var productItem = event.target.closest('.repeater-item');
  39.        event.preventDefault();
  40.        if (event.target.getAttribute('role') === 'button' && productItem) {
  41.            var productInformation = JSON.parse(productItem.dataset.productInfo);
  42.            var  productId = getUrlParameter('variant', productInformation.link);
  43.            adoricAddToCart(productId);
  44.        }
  45.    });
  46. })();
  47. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement