Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- (function() {
- function adoricAddToCart(productId) {
- console.log('product added - ', productId);
- var formData = new FormData();
- formData.append('quantity[]', 1);
- formData.append('option', 'com_virtuemart');
- formData.append('view', 'cart');
- formData.append('virtuemart_product_id[]', productId);
- var xhr = new XMLHttpRequest();
- xhr.withCredentials = true;
- xhr.addEventListener('readystatechange', function () {
- if (this.readyState === 4) {
- console.log(this.responseText);
- }
- });
- xhr.open('POST', 'https://babyteva.co.il/index.php?option=com_virtuemart&nosef=1&view=cart&task=addJS&format=json&lang=he');
- xhr.setRequestHeader('cache-control', 'no-cache');
- xhr.send(formData);
- }
- if (window.Element && !Element.prototype.closest) {
- Element.prototype.closest = function(s) {
- var matches = (this.document || this.ownerDocument).querySelectorAll(s),
- i,
- el = this;
- do {
- i = matches.length;
- while (--i >= 0 && matches.item(i) !== el) {};
- } while ((i < 0) && (el = el.parentElement));
- return el;
- };
- }
- var currentCampaignRepeater = document.querySelector('.' + self.identifier + ' .repeater-content');
- currentCampaignRepeater.addEventListener('click', function(event) {
- var productItem = event.target.closest('.repeater-item');
- event.preventDefault();
- if (event.target.getAttribute('role') === 'button' && productItem) {
- var productInformation = JSON.parse(productItem.dataset.productInfo);
- var productId = getUrlParameter('variant', productInformation.link);
- adoricAddToCart(productId);
- }
- });
- })();
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement