Advertisement
Guest User

bcp_eligable

a guest
Nov 15th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var allthesky = [];
  2. var state_name;
  3. var bcp_eligable ;
  4. function myFunction() {
  5.     setTimeout(function(){ checkCookie(); }, 2000);
  6. }
  7.   //call the function
  8.   myFunction();
  9.   //End call
  10. function setCookie(cname,cvalue) {
  11.  
  12.   var now = new Date();
  13.   now.setTime(now.getTime() + 4 * 3600 * 1000);
  14.   var expires = "expires=" + now.toUTCString();
  15.   document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  16. }
  17. function getCookie(cname) {
  18.     var name = cname + "=";
  19.     var decodedCookie = decodeURIComponent(document.cookie);
  20.     var ca = decodedCookie.split(';');
  21.     for(var i = 0; i < ca.length; i++) {
  22.         var c = ca[i];
  23.         while (c.charAt(0) == ' ') {
  24.             c = c.substring(1);
  25.         }
  26.         if (c.indexOf(name) == 0) {
  27.             return c.substring(name.length, c.length);
  28.         }
  29.     }
  30.     return "";
  31. }
  32.  
  33. function checkCookie() {
  34.     {% for tag in product.tags %}
  35.      {% if tag contains 'bcp2day_eligible' %}
  36.         {% assign bcpeligible = tag | split: ":" %}
  37.           bcp_eligable = {{bcpeligible[1]}};
  38.       {% endif %}
  39.     {% if tag contains 'SKY' %}
  40.      {% assign new_tagg = tag %}
  41.         allthesky.push('{{new_tagg}}');
  42.     {% endif %}
  43.     {% endfor %}
  44.     state_name = getCookie("two_day_state");
  45.     if (state_name != "") {
  46.       console.log("state_name",state_name);
  47.       var sky = '{{product.variants.first.sku}}';
  48.         variant(sky);
  49.     } else {
  50.       console.log("ajax api");
  51.      
  52.         function callback (json){
  53.             console.log("ajax api callback")
  54.             state_name = json.state;
  55.             setCookie("two_day_state", state_name);
  56.             var sky = '{{product.variants.first.sku}}';
  57.             variant(sky);
  58.           }
  59.      
  60.          $.ajax({
  61.             url: "https://geoip-db.com/jsonp",
  62.             jsonpCallback: "callback",
  63.             dataType: "jsonp",
  64.             success: function( location ) {
  65.               state_name = location.state;
  66.               setCookie("two_day_state", state_name);
  67.               var sky = '{{product.variants.first.sku}}';
  68.               variant(sky);
  69.             }
  70.         });
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement