Subscriptions


') checkSelect2Initialised() } function addIconCssInHead() { jQuery('head').append('') } function checkSelect2Initialised() { try { initiateSelect2() } catch(err) { setTimeout(checkSelect2Initialised,2000) } } function initiateSelect2() { jQuery(".appstle_product-search-select").each(function(index, selectEl) { jQuery(selectEl).on('select2:select', function (e) { var data = e.params.data; var selecTargetEl = jQuery(e.target) selecTargetEl.attr('data-variant-price', data.price); selecTargetEl.attr('data-variant-id', data.id); }); var lastSearchTerm = ""; var next = false; var cursor = null; jQuery(selectEl).select2({ ajax: { url: "https://subscription-admin.appstle.com/api/data/v2/product-variants", dataType: 'json', delay: 250, data: function (params) { if (params.term !== lastSearchTerm) { next = false; cursor = null; } lastSearchTerm = params.term; return { search: params.term, // search term cursor: cursor, next: next, shop: shopName }; }, "async": true, "crossDomain": true, "headers": { "cache-control": "no-cache", "postman-token": "06eaf057-9152-2ff9-616b-c8f3f319e47f" }, processResults: function (data, params) { next = data.products.pageInfo.hasNextPage; cursor = data.products.edges[data.products.edges.length - 1].cursor; // Remove draft products var listData = data.products.edges.filter(function(line) { return line?.node?.status === 'ACTIVE' }) // Append variants to list var resultsData = [] listData = listData.forEach(function(line) { if (line?.node?.totalVariants === 1) { var item = {} item.title = line?.node?.title; item.price = line?.node?.variants?.edges[0]?.node?.price; item.id = line?.node?.variants?.edges[0]?.node?.id; item.imgSrc = line?.node?.featuredImage?.transformedSrc; item.currencyCode = line?.node?.priceRangeV2?.maxVariantPrice?.currencyCode; resultsData = [...resultsData, item]; } else { line?.node?.variants?.edges.forEach(function(variantLine) { var item = {} item.title = variantLine?.node?.displayName; item.price = variantLine?.node?.price; item.id = variantLine?.node?.id; item.imgSrc = line?.node?.featuredImage?.transformedSrc; item.currencyCode = line?.node?.priceRangeV2?.maxVariantPrice?.currencyCode; resultsData = [...resultsData, item]; }) } }) // listData = listData.map(function(line) { // }) // listData = listData.map(function(line) { // return { // id: line?.node?.id, // title: line?.node?.title, // imgSrc: line?.node?.featuredImage?.transformedSrc // } // }) return { results: resultsData, pagination: { more: data.products.pageInfo.hasNextPage } }; }, cache: true }, minimumInputLength: 0, templateResult: formatRepo, templateSelection: formatRepoSelection }); }) } function contractDetailsFromContractId(contractId) { jQuery.ajax({ type: "GET", url: 'https://subscription-admin.appstle.com/api/subscription-contracts/contract-external/' + contractId + '?shop=' +shopName, dataType: "json", headers: { 'Access-Control-Allow-Origin': '*', }, success: function (result, status, xhr) { return result console.log("My Contrcat Data" + result); }, error: function (xhr, status, error) { console.log("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText) } }); } function formatRepo (product) { var container = jQuery( "

" + "
" + "
" + "
" + product?.title + "
" + "
" + product?.price + " " + product?.currencyCode + "
" + "
" + "
" ); return container; } function formatRepoSelection (product) { return product.title; } function addStyle() { var css = _RSConfig?.css; jQuery(' ').appendTo(jQuery('head')); } function shopifyLoaded() { if (window.hasOwnProperty('Shopify')) { window.shopName = Shopify.shop; window.customerId = __st.cid; if (customerId == null) { customerId = urlParams.get('customerId'); } subscriptionInit(); addStyle(); } else { setTimeout(shopifyLoaded, 2000) } } function toggleChangeAddressForm(contractId) { jQuery('.appstle_ShippingAcc_' + contractId).find('.editBtnAddress_' + contractId).toggle(); jQuery('.appstle_ShippingAcc_' + contractId).find('.appstle_address_viewOnly').slideToggle(); jQuery('.appstle_ShippingAcc_' + contractId).find('.appstle_address_editForm').slideToggle(); } function updateShippingAddress(contractId) { jQuery('.appstle_ShippingAcc_' + contractId).find('.appstle_edit_shipping_update-button span').hide(); jQuery('.appstle_ShippingAcc_' + contractId).find('.appstle_edit_shipping_update-button .appstle_loaderTiny').show(); var formdata = jQuery('.appstle_ShippingAcc_' + contractId).find('form').serializeArray(); var data = {}; jQuery(formdata).each(function(index, obj){ data[obj.name] = obj.value; }); data['name'] = data['firstName'] + ' ' + data['lastName']; var settings = { "url": "https://subscription-admin.appstle.com/api/subscription-contracts-update-shipping-address?contractId=" + contractId + "&shop=" + shopName, "method": "PUT", "timeout": 0, "headers": { "Content-Type": "application/json" }, "data": JSON.stringify(data), }; jQuery.ajax(settings).done(function (response) { jQuery(".appstle_myProduct").fadeOut(500, function () { jQuery(".appstle_preloader").fadeIn(250); subscriptionInit(); }); }); } function pauseSubscription(contractId) { jQuery('.appstle_subscription_contract_content_wrapper_' + contractId).find('.appstle_pause_subscription_button .appstle_icon_wrapper').hide(); jQuery('.appstle_subscription_contract_content_wrapper_' + contractId).find('.appstle_pause_subscription_button .appstle_loaderTiny').show(); var settings = { "url": "https://subscription-admin.appstle.com/api/subscription-contracts-update-status?contractId=" + contractId + "&status=PAUSED&shop=" + shopName, "method": "PUT", "timeout": 0, }; jQuery.ajax(settings).done(function (response) { jQuery(".appstle_myProduct").fadeOut(500, function () { jQuery(".appstle_preloader").fadeIn(250); subscriptionInit(); }); }); } function resumeSubscription(contractId) { jQuery('.appstle_subscription_contract_content_wrapper_' + contractId).find('.appstle_resume_subscription_button .appstle_icon_wrapper').hide(); jQuery('.appstle_subscription_contract_content_wrapper_' + contractId).find('.appstle_resume_subscription_button .appstle_loaderTiny').show(); var settings = { "url": "https://subscription-admin.appstle.com/api/subscription-contracts-update-status?contractId=" + contractId + "&status=ACTIVE&shop=" + shopName, "method": "PUT", "timeout": 0, }; jQuery.ajax(settings).done(function (response) { jQuery(".appstle_myProduct").fadeOut(500, function () { jQuery(".appstle_preloader").fadeIn(250); subscriptionInit(); }); }); } jQuery(document).ready(function () { shopifyLoaded(); }); // ]]>