NikolayBezay

Nizat GTM teg to trigger free shipping campaign.

May 19th, 2021
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.20 KB | None | 0 0
  1. <script>
  2. (function() {
  3.     var MINIMUM_TOTAL_CART_PRICE = 450;
  4.     var MAXIMUM_TOTAL_CART_PRICE = 600;
  5.  
  6.     function getTotalCartPrice() {
  7.         var userCart = window.sessionStorage.getItem('Cart');
  8.         var cartTotalPrice = 0;
  9.         if (userCart) {
  10.             userCart = JSON.parse(userCart);
  11.             userCart.forEach(function (item)  {
  12.                 cartTotalPrice += parseFloat(item.price) * parseInt(item.quantity);
  13.             });
  14.         }
  15.         window.localStorage.setItem('adoric_user_total_price', cartTotalPrice.toFixed(2));
  16.         return cartTotalPrice.toFixed(2);
  17.     }
  18.  
  19.     function checkTotalPriceConditions() {
  20.         var currentUserTotalPrice = getTotalCartPrice();
  21.         if (currentUserTotalPrice < MAXIMUM_TOTAL_CART_PRICE && currentUserTotalPrice > MINIMUM_TOTAL_CART_PRICE && adoric) {
  22.            adoric.trigger('show_free_shipping_campaign');
  23.         }
  24.     }
  25.  
  26.     checkTotalPriceConditions();
  27.  
  28.     document.querySelector('body').addEventListener('click', function(event) {
  29.         var  addToCartProductOption1 = event.target.getAttribute('rel');
  30.         var  addToCartProductOption2 = event.target.getAttribute('name');
  31.         if (addToCartProductOption1 && (addToCartProductOption1.indexOf('addproduct') != -1 || addToCartProductOption1.indexOf('addprodtobasket') != -1) ) {
  32.            setTimeout(checkTotalPriceConditions, 1000);
  33.         }
  34.         if (addToCartProductOption2 && addToCartProductOption2.indexOf('addtobasket') != -1) {
  35.            setTimeout(checkTotalPriceConditions, 1000);
  36.         }
  37.     });
  38.     document.querySelector('body').addEventListener('touchend', function(event) {
  39.         var  addToCartProductOption1 = event.target.getAttribute('rel');
  40.         var  addToCartProductOption2 = event.target.getAttribute('name');
  41.         if (addToCartProductOption1 && (addToCartProductOption1.indexOf('addproduct') != -1 || addToCartProductOption1.indexOf('addprodtobasket') != -1) ) {
  42.            setTimeout(checkTotalPriceConditions, 1000);
  43.         }
  44.         if (addToCartProductOption2 && addToCartProductOption2.indexOf('addtobasket') != -1) {
  45.            setTimeout(checkTotalPriceConditions, 1000);
  46.         }
  47.     });
  48. })();      
  49. </script>
  50.  
Advertisement
Add Comment
Please, Sign In to add comment