let loadingFrequency=!1,openCartDrawer=!1;const standardProperties={_bundleUid:"123455124566",_bundleHandle:"subscription-bundle-all-meals",_bundleType:"dynamicBaB",_bundleLabel:"at least 4 meals",_bundleProductId:"gid://shopify/Product/7749228396799",_bundleName:"Subscription Bundle",_bundleBoxSize:6,_variantId:"gid://shopify/ProductVariant/43154673172735"},propertiesArray={_bundleUid:"123455124566",_bundleHandle:"subscription-bundle-all-meals",_bundleType:"dynamicBaB",_bundleLabel:"at least 4 meals",_bundleProductId:"gid://shopify/Product/7749228396799",_bundleName:"Subscription Bundle",_bundleBoxSize:6,_variantId:"gid://shopify/ProductVariant/43154673172735"};var selectedSellingPlan="3520921855";function createBundleUID(){return 123455124566}function updateFrequency(linePosition,sellingPlanId){return fetch("/cart/change.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({line:linePosition,properties:propertiesArray,selling_plan:sellingPlanId})})}function getCartItems(reducedCart){var cartSnapshot=ShopifyAPI.cart.items;if(reducedCart){var reduced=cartSnapshot.map(element=>({id:element.id,quantity:element.quantity,properties:element.properties,product_type:element.product_type}));return reduced}else return cartSnapshot}let sellingPlans=[{name:"One Off",id:null,short:"one off"},{name:"Every 1 week",id:3520921855,short:"weekly"},{name:"Every 2 weeks",id:3520889087,short:"every 2 weeks"},{name:"Every 3 weeks",id:3520856319,short:"every 3 weeks"},{name:"Every 4 weeks",id:3520823551,short:"every 4 weeks"},{name:"Every 5 weeks",id:3520790783,short:"every 5 weeks"},{name:"Every 6 weeks",id:3520954623,short:"every 6 weeks"}];var items,dietitianId=43666532106495,feelGoodId=43666751062271,dietitianApt,feelGoodObj;let services=[];function filterCartExtras(cart){return cart.filter(function(currentValue,index,arr){if(console.log(currentValue),currentValue.product_type=="Service"||currentValue.id==44197373149439)services.push(currentValue),console.log("personalised plan");else{if(currentValue.id!=feelGoodId)return currentValue;feelGoodObj=currentValue}})}function updateItemProperties(element,sellingPlanId){let returnSubArray=Object.assign({},standardProperties),returnOneArray={};return element.hasOwnProperty("properties")&&element.properties!=null&&element.properties.hasOwnProperty("from")&&(returnSubArray.from=element.properties.from,returnOneArray.from=element.properties.from),sellingPlanId=="null"||sellingPlanId==null?returnOneArray:returnSubArray}function updateSellingPlanInfo(element,sellingPlanId){return element.product_type=="Extra"?null:sellingPlanId}function createNewCart(sellingPlanId,element,otherElements,notification,planData){console.log("--creating new subscription cart"),loadingFrequency=!0;try{var cart=getCartItems(!0)}catch{console.log(ShopifyAPI)}cart=filterCartExtras(cart);let noti=!1;if(notification&&(noti=!0),cart.length>0){if(showLoadingIcon(),sellingPlanId!=null&&sellingPlanId!="null"){let itemProperties=standardProperties;items=cart.map(element2=>({id:element2.id,quantity:element2.quantity,properties:updateItemProperties(element2,sellingPlanId),selling_plan:updateSellingPlanInfo(element2,sellingPlanId)}))}else items=cart.map(element2=>({id:element2.id,quantity:element2.quantity,properties:updateItemProperties(element2,sellingPlanId)}));services.map(element2=>items.push({id:element2.id,quantity:element2.quantity,properties:element2.properties,selling_plan:null})),services=[];let errors=!1,itemsToAdd;fetch("/cart/clear.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({})}).then(function(response){return response.json()}).then(function(data){itemsToAdd=items.reverse(),console.log(itemsToAdd)}).catch(function(){console.log("error"),errors=!0}).then(function(){errors?(console.log("error"),errors=!0):(console.log("no error"),errors=!1,console.log(itemsToAdd),fetch("/cart/add.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:itemsToAdd})}).then(function(response){return response.json()}).then(function(data){ajaxCart.load(),itemsCookie=btoa(unescape(encodeURIComponent(JSON.stringify(items)))),createCookie("cartitems",itemsCookie,2),createCookie("globalSellingPlan",sellingPlanId,8e3),createCookie("sellingPlanElement","#"+$(element).attr("id"))}).then(function(){planData?(console.log("Adding plan lines, show loading"),showLoadingIcon(),addPlanLines(planData)):(console.log("No plan lines- hide loading"),hideLoadingIcon()),loadingFrequency=!1,updateFrequencyRef(noti)}))})}}function loadFrequency(){var sellingPlan=readCookie("globalSellingPlan");if(sellingPlan==null&&(sellingPlan=3520889087,createCookie("globalSellingPlan",sellingPlan,1e3),console.log(readCookie("globalSellingPlan"))),!loadingFrequency){console.log("--starting load frequency");let checkExtra=checkPlan();checkExtra==!1?getCartItems(!0).length==0?createNewCart(sellingPlan,"","",!1):getCartItems(!0).filter(x=>x.id==44197373149439).length>0&&console.log("personalised plan found"):checkExtra=="Service"&&(jQuery.post("/cart/clear.js",{}).always(function(data){ajaxCart.load()}),notie.alert({type:"error",text:'Appointment timeslot no longer available. Please book again',time:5}))}}function updateFrequencyRef(notification){let sellingPlanId=readCookie("globalSellingPlan"),planName=null;for(var i=0;i'+saving+""),$(".discount-strikethrough").css({"text-decoration":"line-through"})):($(".discounted-price").css({display:"none"}),$(".discount-strikethrough").css({"text-decoration":"none"}),$("#savings")[0]&&($("#savings")[0].innerHTML="")):($(".discounted-price").css({display:"none"}),$(".discount-strikethrough").css({"text-decoration":"none"}),$("#savings")[0]&&($("#savings")[0].innerHTML=""))}function roundTo(n,digits){digits===void 0&&(digits=0);var multiplicator=Math.pow(10,digits);n=parseFloat((n*multiplicator).toFixed(11));var test=Math.round(n)/multiplicator;return+test.toFixed(digits)}function subscriptionSaving(){return formatMoney((ShopifyAPI.cart.total_price/.95-ShopifyAPI.cart.total_price)/100)}function changeCart(){loadFrequency();let newItems=atob(readCookie("cartitems"));console.log(newItems)}jQuery(document).ready(function(){window.location.href.includes("subsmodal=1")&&subscriptionModalOpen()});function getSelectedFrequency(){return jQuery('input[name="subscribeToggle"]:checked').val()=="oneOff"?null:jQuery(".frequencyRadioButtons").val()}jQuery(window).on("load",function(){jQuery('option[value="'+readCookie("globalSellingPlan")+'"]').prop("selected",!0),readCookie("globalSellingPlan")=="null"?(jQuery("#oneOffRadio").prop("checked",!0),jQuery("#frequencySelect").hide()):(jQuery("#subscribeRadio").prop("checked",!0),jQuery("#frequencySelect").show()),jQuery("#oneOffRadio").click(function(){jQuery("#frequencySelect").hide(),jQuery("#updateSubscriptionButton").css("background","#FCD9CB")}),jQuery("#subscribeRadio").click(function(){jQuery("#frequencySelect").show(),jQuery("#updateSubscriptionButton").css("background","#FCD9CB")}),jQuery("#frequencySelectOb").on("change",function(){jQuery("#updateSubscriptionButton").css("background","#FCD9CB")}),jQuery("#updateSubscriptionButton").click(function(){jQuery("#loadingStateIcon").show(),createNewCart(getSelectedFrequency(),"","",!0),jQuery("#subscriptionModalClose").trigger("click"),jQuery("#updateSubscriptionButton").css("background","#F3DB8F")})}); //# sourceMappingURL=/cdn/shop/t/104/assets/subscriptionScripts.js.map

search