}
})
.catch(function(e) {
console.error(e)
})
}
function fetchEmbedConfig(endpoint, apply) {
return fetch(
`${window._RestockRocketConfig.host}/api/v1/embed/${endpoint}.json`,
{
headers: {
'X-Shopify-Shop-Domain': window._RestockRocketConfig.shop || window.Shopify.shop,
'ngrok-skip-browser-warning': 'skip'
}
}
)
.then(function(response) {
if (!response.ok) throw new Error(`Failed to fetch ${endpoint}`);
return response.json();
})
.then(function(data) {
try {
apply(data);
} catch (applyError) {
console.error('STOQ - apply failed for ' + endpoint + ':', applyError);
throw applyError;
}
})
.catch(function(error) {
console.debug(`STOQ - using cached ${endpoint}:`, error.message);
});
}
function refreshShopConfig(source) {
const cfg = window._RestockRocketConfig;
const viaEmbed = function() { return fetchEmbedConfig(source.endpoint,
a) {
cfg.integrations = data;
}
});
}
function refreshSellingPlans(embedOnly) {
const cfg = window._RestockRocketConfig;
return refreshShopConfig({
embedOnly: embedOnly === true,
endpoint: 'selling_plans',
metafieldKey: 'cachedSellingPlans',
flag: 'enable_storefront_selling_plans_read',
isValid: function(value) { return !!value && Array.isArray(value.plans); },
apply: function(data) {
cfg.sellingPlans = data.plans;
cfg.disabledSellingPlanIds = data.disabled_plan_ids || [];
if (data && data.read_flags && typeof data.read_flags === 'object' && !Array.isArray(data.read_flags)) {
cfg.readFlags = data.read_flags;
}
}
});
}
function initializeScripts(settings) {
settings = applyTranslations(settings);
window._RestockRocketConfig.settings = settings;
console.debug(`STOQ - settings configured for ${window._RestockRocketConfig.pageType}`);
const forceEmbedSellingPlans = settings.foSouth Africa (GBP£)
ncludes(window._RestockRocketConfig.pageType);
})
const hasEnabledOffer = Array.isArray(window._RestockRocketConfig.sellingPlans)
&& window._RestockRocketConfig.sellingPlans.some(function(plan) { return plan && plan.enabled; });
const hasDisabledPlanIds = Array.isArray(window._RestockRocketConfig.disabledSellingPlanIds)
&& window._RestockRocketConfig.disabledSellingPlanIds.length > 0;
const usePreorderBuild = settings.preorder_enabled || hasEnabledOffer || hasDisabledPlanIds;
const pageType = window._RestockRocketConfig.pageType;
const preorderUiOnPage = (settings.preorder_enabled && settings[`preorder_${pageType}_enabled`])
|| window._RestockRocketConfig.integrations.some(function(integration) {
return (integration.type === 'quick_buy' || integration.type === 'featured_product')
&& integration.enabled && integration.page_types.includes(pageType);
})
|| /\b(renderPreorderButton|updateAddToCartButton|updateAddToC
tion) {
createRestockRocketScript(preorderCollectionScriptUrl);
} else if(usePreorderBuild) {
createRestockRocketScript(preorderCollectionScriptUrl);
} else {
console.debug(`STOQ - no scripts enabled for ${pageType}`);
}
const wishlistIntegration = window._RestockRocketConfig.integrations.find(function(integration) { return integration.type === 'wishlist' && integration.enabled; });
if (wishlistIntegration) {
createRestockRocketScript(window._RestockRocketConfig.scriptHost + 'restockrocket-wishlist.js');
if ((wishlistIntegration.page_types || []).indexOf(pageType) !== -1) {
let wishlistHeartsRequested = false;
const wishlistHeartTarget = pageType === 'product' ? '[data-stoq-wishlist-heart]' : '[data-stoq-wishlist-heart], a[href*="/products/"]';
const loadWishlistHearts = function() {
if (wishlistHeartsRequested || !document.querySelector(wishlistHeartTarget)) return;
wishlistHeartsReques
}
} catch (e) {}
}
const appLoadedEvent = new CustomEvent('stoq:loaded', {
detail: {
pageType: window._RestockRocketConfig.pageType,
enabled: settings.enable_app,
settings: settings,
preorderEnabled: settings.preorder_enabled
}
});
console.debug('STOQ - dispatching app loaded event');
window.dispatchEvent(appLoadedEvent);
}
}
html.stoq-buy-now-pending .shopify-payment-button{pointer-events:none!important}South Sudan (GBP£)