var appstleInit = function () { var head = document.getElementsByTagName('head')[0]; var startingTime = new Date().getTime(); if (typeof jQuery == 'undefined' && !RS?.Config?.disableLoadingJquery) { var jQueryScript = document.createElement('script'); jQueryScript.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'; jQueryScript.type = 'text/javascript'; head.appendChild(jQueryScript); } if (typeof Mustache == 'undefined') { var mustacheScript = document.createElement('script'); mustacheScript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mustache.js/3.1.0/mustache.js'; mustacheScript.type = 'text/javascript'; head.appendChild(mustacheScript); } // Poll for jQuery to come into existance var checkReady = function (callback) { if (window.jQuery && window.Mustache && window.Shopify) { callback(jQuery); } else { window.setTimeout(function () { checkReady(callback); }, 20); } }; const urlParams = new URLSearchParams(window.location.search); var globalUrlParameter = urlParams.get('variant'); // Start polling... checkReady(function ($) { (function () { var endingTime = new Date().getTime(); var tookTime = endingTime - startingTime; console.log("jQuery is loaded, after " + tookTime + " milliseconds!"); function renderWidget(standAloneProduct, standAloneElement, widgetId) { if(!window["Shopify"]) { return; } RS.Config = Object.assign(RS.Config, "undefined" != typeof _RSConfig && null !== _RSConfig ? _RSConfig : {}) window.RSConfig = RS.Config; var product = RSConfig.product; if (standAloneProduct) { product = standAloneProduct; } processProductVariants(product); var localVariantsByTitle = RSConfig.variantsByTitle; var localVariantsById = RSConfig.variantsById; var localWindowVariant; function processProductVariants(product) { if (!product) { return; } var variants = product.variants; var _variantsByTitle = {}; var _variantsById = {}; for (var index = 0; index < variants.length; index++) { var variant = variants[index]; _variantsByTitle[variant.title] = Object.assign({}, variant); _variantsById[variant.id] = Object.assign({}, variant); } RSConfig.variantsByTitle = _variantsByTitle; RSConfig.variantsById = _variantsById; } function urlParamsToObject() { var queryStringTokens = location.search.substr(1).split("&"); var result = {}; for (var index = 0; index < queryStringTokens.length; index++) { var keyValues = queryStringTokens[index].split("=") result[keyValues[0]] = keyValues[1]; } return result } function urlParam(key) { return urlParamsToObject()[key] || null } function detectVariant(previousVariantId, selector, product) { var variantId = urlParam("variant"); if (selector.closest('form[action$="/cart/add"]').find('[name=id]').length > 0 && selector.closest('form[action$="/cart/add"]').find('[name=id]')[0].value) { variantId = selector.closest('form[action$="/cart/add"]').find('[name=id]')[0].value; return localVariantsById[variantId]; } else if (variantId) { return localVariantsById[variantId]; } else if (Object.values(localVariantsById).some(data => data?.title == $("form select[name='options[Bundle]']")?.val())) { return Object.values(localVariantsById).find(data => data?.title == $("select[name='options[Bundle]']").val()) } else { var titleTokens; titleTokens = function () { var variantTokens = []; var singleOptionSelector = selector.closest('form[action$="/cart/add"]').find("select.single-option-selector"); if (singleOptionSelector != null && singleOptionSelector.selectedIndex != null && singleOptionSelector.selectedIndex !== -1) { variantTokens.push(singleOptionSelector[singleOptionSelector.selectedIndex].value) } else { variantTokens.push(void 0); } return variantTokens }(); var variant = localVariantsByTitle[titleTokens.join(" / ")] if (variant) { return variant; } else { var variant = product.variants[0]; return variant; } } } function getSellingPlanAllocation(variantId, sellingPlanId) { var variant = localVariantsById[variantId]; return variant.selling_plan_allocations.find(function (plan) { return plan.selling_plan_id === sellingPlanId; }); } function compareCustomerTags(array1, array2) { return array1.filter(function (n) { return array2.indexOf(n) != -1; }); } function isSellingPlanVisible(sellingPlanId) { var customerId = __st.cid; var userTags = RSConfig.customer_tags || []; var isVisible = true; if (!customerId && RSConfig.memberOnlySellingPlansJson && RSConfig.memberOnlySellingPlansJson[sellingPlanId]) { isVisible = false; } if (customerId && RSConfig.nonMemberOnlySellingPlansJson && RSConfig.nonMemberOnlySellingPlansJson[sellingPlanId]) { isVisible = false; } if (isVisible && customerId && RSConfig.memberOnlySellingPlansJson && RSConfig.memberOnlySellingPlansJson[sellingPlanId]) { if (RSConfig.memberOnlySellingPlansJson[sellingPlanId].memberInclusiveTags && RSConfig.memberOnlySellingPlansJson[sellingPlanId].memberInclusiveTags.trim()) { var sellingPlanTags = RSConfig.memberOnlySellingPlansJson[sellingPlanId].memberInclusiveTags.split(","); var tagFound = compareCustomerTags(userTags, sellingPlanTags); isVisible = (tagFound.length > 0); } } return isVisible; } function buildSellingPlantText(sellingPlan) { var sellingPlanModel = sellingPlan.totalPrice == sellingPlan.formattedPrice ? { sellingPlanName: sellingPlan.name, sellingPlanPrice: `${sellingPlan.formattedPrice}`, secondSellingPlanPrice: `${sellingPlan.secondFormattedPrice}`, discountText: sellingPlan?.discountText, totalPrice: `${sellingPlan?.totalPrice}`, } : { sellingPlanName: sellingPlan.name, totalPrice: `${sellingPlan?.totalPrice}`, sellingPlanPrice: `${sellingPlan.formattedPrice}`, secondSellingPlanPrice: `${sellingPlan.secondFormattedPrice}`, discountText: sellingPlan.discountText }; var sellingPlanDisplayText = Mustache.render(RS.Config.sellingPlanTitleText, sellingPlanModel); return wrapPriceWithSpanTag(sellingPlanDisplayText); } function buildAtcButtonSelector() { var atcButtonSelector = RSConfig.atcButtonSelector || "form[action$='/cart/add'] [type='submit']" var atcButtonSelectorModel = { productId: product.id, }; atcButtonSelector = Mustache.render(atcButtonSelector, atcButtonSelectorModel); return atcButtonSelector; } function buildOneTimePriceText(price) { var priceModel = { price: price, }; var priceText = Mustache.render(RS.Config.oneTimePriceText, priceModel); return wrapPriceWithSpanTag(priceText); } function buildSubscriptionOptionText(isPrepaidPlan, discountValue) { let subscriptionOptionModel = { discountValue: discountValue }; let subscriptionOptionText = Mustache.render(RS.Config.subscriptionOptionText, subscriptionOptionModel); return wrapPriceWithSpanTag(subscriptionOptionText); } function buildSelectedPriceText(price, isPrePaid, totalPrice) { var priceModel = isPrePaid ? { pricePerDelivery: price, totalPrice: totalPrice } : { price: price, }; var text = isPrePaid ? RS.Config.selectedPrepaidSellingPlanPriceText : RS.Config.selectedPayAsYouGoSellingPlanPriceText; var priceText = Mustache.render(text, priceModel); return wrapPriceWithSpanTag(priceText); } function buildPrepaidPerDeliveryPriceText(price) { var priceModel = { prepaidPerDeliveryPrice: price, } return wrapPriceWithSpanTag(Mustache.render(RS.Config.totalPricePerDeliveryText, priceModel)); } function buildSelectedTooltipPrePaidText(price, totalPrice) { var prepaidPricetooltipModel = { pricePerDelivery: price, totalPrice: totalPrice } var text = RS.Config.tooltipDescriptionOnPrepaidPlan; var prepaidPricetooltipText = Mustache.render(text, prepaidPricetooltipModel); return wrapPriceWithSpanTag(prepaidPricetooltipText); } function buildSelectedTooltipDiscountText(selectedSellingPlanAllocationObj, multipleDiscount) { if (selectedSellingPlanAllocationObj?.price_adjustments?.length == 2) { var discountModel = { firstPrice: formatPriceWithQuantity(selectedSellingPlanAllocationObj?.price_adjustments[0]?.price), secondPrice: formatPriceWithQuantity(selectedSellingPlanAllocationObj?.price_adjustments[1]?.price), discountOne: multipleDiscount.length > 0 ? multipleDiscount[0] : "", discountTwo: multipleDiscount.length == 2 ? multipleDiscount[1] : "" }; return wrapPriceWithSpanTag(Mustache.render(RS.Config.tooltipDescriptionOnMultipleDiscount, discountModel)); } } function buildTooltipDetailsText(prepaidText, isPrePaid, discountText) { var tooltipDetailModel = isPrePaid ? { prepaidDetails: prepaidText, discountDetails: discountText, defaultTooltipDescription: RS.Config.tooltipDesctiption } : { defaultTooltipDescription: RS.Config.tooltipDesctiption, discountDetails: discountText }; // let text = RS.Config.tooltipDesctiption + (isPrePaid ? "
{{prepaidDetails}}" : "") + (discountText!= undefined ? "
{{discountDetails}}": ""); let text = RS.Config.tooltipDescriptionCustomization; var tooltipText = Mustache.render(text, tooltipDetailModel); return wrapPriceWithSpanTag(tooltipText); } function populateDropdown(purchaseOptions, variant) { var sellingPlanVariants = []; jQuery.each(product.selling_plan_groups, function (index, sellingPlanGroup) { if (sellingPlanGroup.app_id === 'appstle') { jQuery.each(sellingPlanGroup.selling_plans, function (subIndex, sellingPlan) { var visible = isSellingPlanVisible(sellingPlan.id); if (visible) { var sellingPlanAllocation = getSellingPlanAllocation(variant.id, sellingPlan.id); if (!sellingPlanAllocation) { return } var price = sellingPlanAllocation.per_delivery_price; var totalPrice = formatPriceWithQuantity(sellingPlanAllocation?.price); var formattedPrice = formatPriceWithQuantity(price); var secondPrice = null; var secondFormattedPrice = null; if (sellingPlanAllocation && sellingPlanAllocation.price_adjustments && sellingPlanAllocation.price_adjustments.length === 2) { secondPrice = sellingPlanAllocation.price_adjustments[1].price; secondFormattedPrice = formatPriceWithQuantity(secondPrice); } else { secondPrice = price; secondFormattedPrice = formattedPrice; } let discountText; var priceAdjustment = sellingPlan?.price_adjustments[0]; if (priceAdjustment?.value_type !== 'percentage') { discountText = formatPriceWithQuantity(priceAdjustment?.value); } else { discountText = priceAdjustment?.value + '%'; } sellingPlanVariants.push({ "name": sellingPlan.name, "description": sellingPlan.description, "id": sellingPlan.id, "formattedPrice": formattedPrice, "price": price, "totalPrice": totalPrice, "secondPrice": secondPrice, "secondFormattedPrice": secondFormattedPrice, "discountText": discountText }); } }); } }); if (sellingPlanVariants.length > 0) { if (sellingPlanVariants.length < 2) { jQuery(purchaseOptions).find('.appstle_subscribe_option').children().hide(); var singleSellingPlanDisplayText = buildSellingPlantText(sellingPlanVariants[0]); var planText = jQuery(`
${singleSellingPlanDisplayText}
`); planText.appendTo(purchaseOptions.find('.appstle_subscribe_option')) if (sellingPlanVariants[0]?.description) { jQuery(`
${sellingPlanVariants[0]?.description}
` ).appendTo(purchaseOptions.find('.appstle_subscribe_option')); } } if (!RSConfig?.sortByDefaultSequence) { sellingPlanVariants.sort(function (sellingPlanA, sellingPlanB) { return sellingPlanA.price - sellingPlanB.price; }) } jQuery(sellingPlanVariants).each(function (index, sellingPlan) { var sellingPlanDisplayText = buildSellingPlantText(sellingPlan); if (!RSConfig?.switchRadioButtonWidget) { jQuery('