NikolayBezay

Gade.co.il "Free delivery" event to Adoric for GTM

Feb 22nd, 2021 (edited)
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.25 KB | None | 0 0
  1. <script>
  2. (function() {
  3.     var minPrice = 100;
  4.     var maxPrice = 149;
  5.     var FREE_SHIPPING = 150;
  6.     function checkTotalCart() {
  7.         var parser = new DOMParser();
  8.         var doc =  '';
  9.         var data = null;
  10.         var xhr = new XMLHttpRequest();
  11.         xhr.withCredentials = true;
  12.         xhr.addEventListener('readystatechange', function () {
  13.             if (this.readyState === 4) {
  14.  
  15.                 doc = parser.parseFromString(this.responseText, 'text/html');      
  16.                 var cartData = JSON.parse(doc.querySelector('body').innerText, 2);
  17.                 var totalPrice = cartData.total_price;
  18.                 totalPrice = parseInt(totalPrice / 100);
  19.                 window.localStorage.setItem('adoricTotalCartPrice', totalPrice);
  20.                 if ((totalPrice >= minPrice) && (totalPrice <= maxPrice)) {
  21.                    window.localStorage.setItem('adoricFreeShipping', FREE_SHIPPING - totalPrice);
  22.                     window.adoric && adoric.trigger('FreeDelivery');
  23.                 }
  24.             }
  25.         });
  26.         xhr.open('GET', window.location.origin + '/cart.js');
  27.         xhr.setRequestHeader('cache-control', 'no-cache');
  28.         xhr.send(data);
  29.     }
  30.     setTimeout(checkTotalCart, 2000);
  31. })();
  32. </script>
Advertisement
Add Comment
Please, Sign In to add comment