SETTINGS_CACHE_DURATION) {
console.debug('STOQ - settings changed recently, skipping cache');
return null;
}
return settings;
} catch (error) {
console.debug('STOQ - Error checking settings cache:', error);
return null;
}
}
function createRestockRocketContainer() {
const restockRocketContainer = document.createElement('div');
restockRocketContainer.id = 'restock-rocket';
document.body.appendChild(restockRocketContainer);
}
function createRestockRocketScript(scriptUrl) {
const restockRocketScriptElement = document.createElement('script');
restockRocketScriptElement.setAttribute('defer', 'defer');
restockRocketScriptElement.src = scriptUrl;
document.body.appendChild(restockRocketScriptElement);
}
createRestockRocketContainer()
console.debug('STOQ - extension activated')
function applyTranslations(settings) {
try {
// Skip translation logic entirely if multi-language is not enabled
if (!settings ||
!settings.multi_language_enabled) {
return settings;
}
if (!settings.translations) {
console.debug('STOQ - No translations found, skipping translation');
return settings;
}
const normalizedLocale = window._RestockRocketConfig.normalizedLocale;
const translations = settings.translations;
if (!normalizedLocale) {
// No matching locale has translations; drop payload to save memory
console.debug('STOQ - No matching locale for translations. Available:', Object.keys(translations || {}));
delete settings.translations;
return settings;
}
console.debug(`STOQ - Applying translations for normalized locale: ${normalizedLocale} (original: ${window._RestockRocketConfig.locale})`);
const translatedFields = translations[normalizedLocale];
if (translatedFields && typeof translatedFields === 'object') {
Object.keys(translatedFields).forEach(function(key) {
const value = translatedFields[key
];
if (value !== null && value !== undefined && value !== '') {
settings[key] = value;
}
});
} else {
console.debug('STOQ - No translated fields found for locale:', normalizedLocale);
}
delete settings.translations;
return settings;
} catch (e) {
console.debug('STOQ - error applying translations:', e);
return settings;
}
}
// First try to get settings from metafields with expiry check
const cachedSettings = window._RestockRocketConfig.cachedSettings;
const validCachedSettings = cachedSettings ? checkSettingsExpiry(cachedSettings) : null;
if (validCachedSettings) {
console.debug('STOQ - using cached settings');
initializeScripts(validCachedSettings);
} else {
console.debug('STOQ - fetching fresh settings');
const headers = {
'X-Shopify-Shop-Domain': window._RestockRocketConfig.shop || window.Shopify.shop,
'ngrok-skip-browser-warning': 'skip'
};
if (window.Shopify?.them
#FeaturedImage--template--15326745395426__1645734801adfd4c07 { --overlay-opacity: 0.2; }
HANDLEBARe?.role === 'main') {
headers['X-Shopify-Theme-Schema-Name'] = window.Shopify.theme.schema_name;
headers['X-Shopify-Theme-Schema-Version'] = window.Shopify.theme.schema_version;
headers['X-Shopify-Theme-Store-Id'] = window.Shopify.theme.theme_store_id;
}
fetch(
`${window._RestockRocketConfig.host}/api/v1/setting.json?translation_locale=${window._Rest
ockRocketConfig.normalizedLocale}`,
{ headers }
)
.then(function(response) {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(function(settings) {
initializeScripts(settings);
})
.catch(function(error) {
// If request failed and we have cached settings (even if expired), use them as fallback
if (cachedSettings) {
console.debug('STOQ - using expired cached settings as fallback');
initializeScripts(cachedSettings);
} else {
console.error('STOQ - failed to load settings:', error);
}
})
.catch(function(e) {
console.error(e)
})
}
function initializeScripts(settings) {
settings = applyTranslations(settings);
window._RestockRocketConfig.settings = settings;
console.debug(`STOQ - settings configured for ${window._RestockRocketConfig.pageType}`);
if(settings.enable_app) {
const hijackIntegration = window._RestocHire Kryptolok Standard U-Lock & 4 foot Kryptoflex cable
kRocketConfig.integrations.find(function(integration) {
return integration.type === 'hijack' && integration.enabled && integration.page_types.includes(window._RestockRocketConfig.pageType);
})
if(window._RestockRocketConfig.pageType === 'collection' && (settings.show_button_on_collection || settings.preorder_collection_enabled)) {
createRestockRocketScript(window._RestockRocketConfig.scriptUrlCollection);
} else if(window._RestockRocketConfig.pageType === 'index' && (settings.show_button_on_index || settings.preorder_index_enabled)) {
createRestockRocketScript(window._RestockRocketConfig.scriptUrlCollection);
} else if(window._RestockRocketConfig.pageType === 'search' && (settings.show_button_on_search || settings.preorder_search_enabled)) {
createRestockRocketScript(window._RestockRocketConfig.scriptUrlCollection);
} else if(window._RestockRocketConfig.pageType === 'page' && (settings.show_button_on_page || settings.preorder_page_enabled)) {
createRestockRocketScript(window._RestockRocketConfig.scriptUrlCollection);
} else if(window._RestockRocketConfig.pageType === 'product') {
createRestockRocketScript(window._RestockRocketConfig.scriptUrlProduct);
} else if(hijackIntegration) {
createRestockRocketScript(window._RestockRocketConfig.scriptUrlCollection);
} else {
console.debug(`STOQ - no scripts enabled for ${window._RestockRocketConfig.pageType}`);
}
// Check and update cart selling plans after scripts are loaded
if (settings.preorder_enabled) {
updateCartSellingPlans();
}
// Dispatch custom event when app is loaded
const appLoadedEvent = new CustomEvent('stoq:loaded', {
detail: {
pageType: window._RestockRocketConfig.pageType,
enabled: settings.enable_app,
settings: settings
}
});
console.debug('STOQ - dispatching app loaded event');
window.dispatchEvent(appLoadedEvent);
}
}
functi
window.appBlockPlacements ||= [];
if (window.klarnaAppBlocksManager) {
window.klarnaAppBlocksManager.push({
productVariants: [{"id":45760559055074,"title":"Small \/ Medium","option1":"Small \/ Medium","option2":null,"option3":null,"sku":"RB22129MD","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"Ridgeback Advance 2W - Small \/ Medium","public_title":"Small \/ Medium","options":["Small \/ Medium"],"price":220000,"weight":0,"compare_at_price":333900,"inventory_management":"shopify","barcode":"","requires_selling_plan":false,"selling_plan_allocations":[]},{"id":45760559087842,"title":"Medium \/ Large","option1":"Medium \/ Large","option2":null,"option3":null,"sku":"RB22129LG","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Ridgeback Advance 2W - Medium \/ Large","public_title":"Medium \/ Large","options":["Medium \/ Large"],"price":220000,"weight":0,"compare_at_price":333900,"inventory_management":"shopify","barcode":"","requires_selling_plan":false,"selling_plan_allocations":[]}],
templateName: 'product',
dataKey: 'top-strip-promotion-badge',
storefrontCurrency: 'GBP',
storefrontCountry: 'GB',
storefrontLanguage: 'en',
shopLocale: 'en',
shopDomain: 'projektride.co.uk',
variantPrice: '220000',
cartPrice: '0',
selector: 'shopify-osm-Ac2tTRTlRaTI0R3BZb__klarna_on_site_messaging_app_block_8gNReH',
topPadding: '0',
bottomPadding: '0',
});
} else {
window.appBlockPlacements.push({
productVariants: [{"id":45760559055074,"title":"Small \/ Medium","option1":"Small \/ Medium","option2":null,"option3":null,"sku":"RB22129MD","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"Ridgeback Advance 2W - Small \/ Medium","public_title":"Small \/ Medium","options":["Small \/ Medium"],"price":220000,"weight":0,"compare_at_price":333900,"inventory_management":"shopify","barcode":"","requires_selling_plan":false,"selling_plan_allocations":[]},{"id":45760559087842,"title":"Medium \/ Large","option1":"Medium \/ Large","option2":null,"option3":null,"sku":"RB22129LG","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Ridgeback Advance 2W - Medium \/ Large","public_title":"Medium \/ Large","options":["Medium \/ Large"],"price":220000,"weight":0,"compare_at_price":333900,"inventory_management":"shopify","barcode":"","requires_selling_plan":false,"selling_plan_allocations":[]}],
templateName: 'product',
shopLocale: 'en',
dataKey: 'top-strip-promotion-badge',
storefrontCurrency: 'GBP',
storefrontCountry: 'GB',
storefrontLanguage: 'en',
shopDomain: 'projektride.co.uk',
variantPrice: '220000',
cartPrice: '0',
selector: 'shopify-osm-Ac2tTRTlRaTI0R3BZb__klarna_on_site_messaging_app_block_8gNReH',
topPadding: '0',
bottomPadding: '0',
});
}
img src="//projektride.co.uk/cdn/shop/files/logo_header_2048x2048.png?v=1634060673" alt="" class="logo--footer">
Kona Aluminum Riseron updateCartSellingPlans() {
// Wait for the API to be available with retries
const maxRetries = 10;
const retryDelay = 500;
function attemptCartCheck(attempt = 1) {
if (window._RestockRocket && window._RestockRocket.updateCartSellingPlans) {
window._RestockRocket.updateCartSellingPlans()
.then(hasUpdates => {
if (hasUpdates) {
console.debug('STOQ - cart selling plans updated successfully');
} else {
console.debug('STOQ - no cart selling plan updates needed');
}
})
.catch(error => {
console.error('STOQ - error updating cart selling plans:', error);
});
} else if (attempt
<£0.00
maxRetries) {
console.debug(`STOQ - API not ready, retry ${attempt}/${maxRetries}`);
setTimeout(() => attemptCartCheck(attempt + 1), retryDelay);
} else {
console.debug('STOQ - API not loaded after max retries, skipping cart selling plan check');
}
}