The Genesis CDA blends rugged gravel pedigree with urban practicality. Designed as our entry-level drop-bar bike, it is built to handle everything from mixed-surface trails to early morning commutes — lightweight, comfortable, and dependable.Frog
Our ALX8 6061 aluminium tubeset makes the CDA a lightweight, dependable allrounder. Combined with a chromoly fork and increased tyre clearance the ride is sublime!Custom Build Inspiration
":true,"shipping_text":"Estimated to ship within 2 months","payment_type":"full","billing_checkout_charge_type":"percentage","billing_checkout_charge_amount":null,"billing_checkout_charge_percentage":"100.0","pricing_type":"no_discount","pricing_amount":null,"pricing_percentage":null,"discount_text":"Save {{ discount }}","billing_title":"Full payment","billing_description":null,"enable_billing_widget":false,"inventory_provider":"stoq","preorder_badge_enabled":false,"preorder_badge_text":"Preorder","preorder_badge_text_color":"#FFFFFF","preorder_badge_background_color":"#000000","preorder_discounted_price_enabled":null,"payment_line_item_property_enabled":false,"shipping_line_item_property_enabled":true,"custom_line_item_property_text":null,"preorder_button_text_color":"#ffffff","preorder_button_background_color":"#565557","preorder_button_colors_enabled":true,"markets_enabled":false,"market_id":13779632354,"shopify_market_ids":[],"use_shopify_selling_plan":true,"use_simplified_shipping_text":false,"translatio
ns":{},"payment_options":[{"billing_type":"no_remaining_balance","billing_checkout_charge_type":"percentage","billing_checkout_charge_amount":null,"billing_checkout_charge_percentage":"100.0","billing_at":"2025-07-26T09:20:38.472Z","billing_after_n_intervals":7,"billing_after_interval_type":"day","pricing_type":"no_discount","pricing_amount":null,"pricing_percentage":null,"billing_title":"Full payment","billing_description":null,"discount_text":"Save {{ discount }}","shopify_selling_plan_id":713071886719,"is_default":true,"type":"full","translations":{}}],"require_preorder_acknowledgement":false,"preorder_acknowledgement_text":"I acknowledge and agree to the preorder terms and conditions for this product.","disable_button_until_acknowledged":false,"preorder_min_quantity":null,"preorder_max_quantity":null,"countdown_timer_enabled":false,"countdown_timer_style":"text","countdown_timer_text_color":"#000000","countdown_timer_background_color":"#f5f5f5","countdown_timer_border_radius":8,"countdown_timer_format":"Date }}","shipping_applies_to_all_products":true,"shipping_text":"Estimated to ship within 2 months","payment_type":"full","billing_checkout_charge_type":"percentage","billing_checkout_charge_amount":null,"billing_checkout_charge_percentage":"100.0","pricing_type":"no_discount","pricing_amount":null,"pricing_percentage":null,"discount_text":"Save {{ discount }}","billing_title":"Full payment","billing_description":null,"enable_billing_widget":false,"inventory_provider":"stoq","preorder_badge_enabled":false,"preorder_badge_text":"Preorder","preorder_badge_text_color":"#FFFFFF","preorder_badge_background_color":"#000000","preorder_discounted_price_enabled":null,"payment_line_item_property_enabled":false,"shipping_line_item_property_enabled":true,"custom_line_item_property_text":null,"preorder_button_text_color":"#ffffff","preorder_button_background_color":"#565557","preorder_button_colors_enabled":true,"markets_enabled":false,"market_id":13779632354,"shopify_market_ids":[],"use_shopify_selling_plan":true,"use_si
mplified_shipping_text":false,"translations":{},"payment_options":[{"billing_type":"no_remaining_balance","billing_checkout_charge_type":"percentage","billing_checkout_charge_amount":null,"billing_checkout_charge_percentage":"100.0","billing_at":"2025-07-26T09:20:38.472Z","billing_after_n_intervals":7,"billing_after_interval_type":"day","pricing_type":"no_discount","pricing_amount":null,"pricing_percentage":null,"billing_title":"Full payment","billing_description":null,"discount_text":"Save {{ discount }}","shopify_selling_plan_id":713071886719,"is_default":true,"type":"full","translations":{}}],"require_preorder_acknowledgement":false,"preorder_acknowledgement_text":"I acknowledge and agree to the preorder terms and conditions for this product.","disable_button_until_acknowledged":false,"preorder_min_quantity":null,"preorder_max_quantity":null,"countdown_timer_enabled":false,"countdown_timer_style":"text","countdown_timer_text_color":"#000000","countdown_timer_background_color":"#f5f5f5","countdown_timer_bor
der_radius":8,"countdown_timer_format":"DHMS","countdown_timer_use_schedule_dates":true,"countdown_timer_custom_start_date":null,"countdown_timer_custom_end_date":null,"countdown_timer_starts_text":null,"countdown_timer_ends_text":null,"schedule_offer":false,"schedule_start_date":null,"schedule_end_date":null,"updated_at":"2025-08-19T10:05:43.042Z","allow_mixed_cart":true,"mixed_cart_error_message":"Preorders must be purchased separately from regular items. Please complete your current order first, or clear your cart to continue.","b2b_enabled":true,"preorder_progress_bar_enabled":false,"preorder_progress_bar_text":"{{ sold }} of {{ total }} claimed","preorder_progress_bar_fill_color":"#000000","preorder_progress_bar_background_color":"#e5e5e5","preorder_progress_bar_text_color":"#FFFFFF","preorder_progress_bar_border_radius":4,"preorder_progress_bar_show_percentage":false}],"disabled_plan_ids":[713813721471,713176482175,714631872895],"cached_at":"2026-04-09T09:16:46Z"};
if (cachedData && typeof cached
Data === 'object' && cachedData.cached_at) {
// Find the maximum updated_at from all items in old array
const oldPlans = window._RestockRocketConfig.sellingPlans;
const maxUpdatedAt = Array.isArray(oldPlans) && oldPlans.length > 0
? oldPlans.reduce(function(max, plan) {
// Parse dates for proper comparison (handles mixed ISO formats)
if (plan.updated_at) {
const planDate = new Date(plan.updated_at);
const maxDate = max ? new Date(max) : null;
return (!maxDate || (planDate && !isNaN(planDate) && planDate > maxDate)) ? plan.updated_at : max;
}
return max;
}, '')
: null;
// Use cached if old array is empty/has no timestamps, or cached is newer
// Parse dates for comparison to handle format differences (+00:00 vs .000Z)
const cachedDate = new Date(cachedData.cached_at);
const maxDate = maxUpdatedAt ? new Date(maxUpdatedAt)
: null;
const useCached = !maxUpdatedAt || (cachedDate && !isNaN(cachedDate) && (!maxDate || cachedDate > maxDate));
if (useCached) {
if (Array.isArray(cachedData.plans)) {
window._RestockRocketConfig.sellingPlans = cachedData.plans;
// Only use disabled_plan_ids when using cached plans
window._RestockRocketConfig.disabledSellingPlanIds = cachedData.disabled_plan_ids || [];
console.debug('[RR] Using selling plans from cachedSellingPlans (cached_at: ' + cachedData.cached_at + ')');
}
} else {
// When using old format (stale cache), don't trust disabled_plan_ids
window._RestockRocketConfig.disabledSellingPlanIds = [];
console.debug('[RR] Using selling plans from old format (max updated_at: ' + maxUpdatedAt + ')');
}
}
})();window._RestockRocketConfig.enabledNotifyMeVariantIds = [];window._RestockRocketConfig.disabledNotifyMeVariantIds = [];window._RestockRocketConfig.backI
nStockTemplates = [];window._RestockRocketConfig.restockNotes = {};window._RestockRocketConfig.integrations = [{"id":"15c94526-b6b8-4de1-9bc1-23b1ca52ddb0","shop_id":38436,"enabled":true,"page_types":["product","collection","index","search","page","cart","list-collections","article","blog"],"configuration":{"toastDuration":10000,"toastPosition":"bottom-right","enableXHRHijack":true,"enableFetchHijack":true,"quantityLimitDisabled":false},"type":"hijack","css_config":null,"js_config":null,"created_at":"2025-07-26T09:16:04.076Z","updated_at":"2025-07-26T09:16:04.076Z"}];window._RestockRocketConfig.obfuscateInventoryQuantity = false;window._RestockRocketConfig.product = {"id":15350152069503,"title":"Genesis CDA 10","handle":"genesis-cda-11","description":"\u003cdiv class=\"pagebuilder-column-group\" data-background-images=\"{}\" data-content-type=\"column-group\" data-appearance=\"default\" data-grid-size=\"12\" data-element=\"main\" data-pb-style=\"QYBMYF0\"\u003e\n\u003cdiv class=\"pagebuilder-column-line\" dat
a-content-type=\"column-line\" data-element=\"main\" data-pb-style=\"GYDE5U3\"\u003e\n\u003cdiv class=\"pagebuilder-column\" data-content-type=\"column\" data-appearance=\"full-height\" data-background-images=\"{}\" data-element=\"main\" data-pb-style=\"NRNOA7A\"\u003e\n\u003ch2 data-content-type=\"heading\" data-appearance=\"default\" data-element=\"main\"\u003eOne Bike Many Hats\u003c\/h2\u003e\n\u003cdiv data-content-type=\"text\" data-appearance=\"default\" data-element=\"main\"\u003e\n\u003cp\u003e\u003cspan\u003eThe Genesis CDA blends rugged gravel pedigree with urban practicality. Designed as our entry-level drop-bar bike, it is built to handle everything from mixed-surface trails to early morning commutes — lightweight, comfortable, and dependable.\u003c\/span\u003e\u003c\/p\u003e\n\u003c\/div\u003e\n\u003c\/div\u003e\n\u003c\/div\u003e\n\u003c\/div\u003e\n\u003cdiv\u003e\n\u003csection class=\"carousel is-hover\" dir=\"ltr\" aria-label=\"Gallery\" tabindex=\"0\"\u003e\n\u003cdiv class=\"carousel__v
iewport\"\u003e\n\u003col class=\"carousel__track\"\u003e\n\u003cli class=\"carousel__slide carousel__slide--clone\" aria-hidden=\"true\"\u003e\n\u003cdiv class=\"carousel__item pagebuilder-column\" data-content-type=\"slide\"\u003e\n\u003cfigure class=\"pagebuilder-image\" data-content-type=\"image\" data-appearance=\"full-width\" data-element=\"main\" data-pb-style=\"OV4G6EA\"\u003e\u003cpicture\u003e\u003csource media=\"(max-width: 768px)\" srcset=\"https:\/\/www.freewheel.co.uk\/media\/headless_websites\/genesis\/cda\/cda_10\/800x1000-cdf10-keyfeature-d.jpg\" data-element=\"lazy_mobile_image\"\u003e\u003cimg alt=\"\" title=\"\" src=\"https:\/\/www.freewheel.co.uk\/media\/headless_websites\/genesis\/cda\/cda_10\/800x1000-cdf10-keyfeature-d.jpg\" data-element=\"lazy_image\"\u003e\u003c\/picture\u003e\u003c\/figure\u003e\n\u003ch3 class=\"text-xl font-medium\" data-content-type=\"heading\" data-appearance=\"default\" data-element=\"main\" data-pb-style=\"MTMQ57X\"\u003eShimano ESSA\u003c\/h3\u003e\n\u003cdiv class=\"h-40\" data-content-type=\"text\" data-appearance=\"default\" data-element=\"main\" data-pb-style=\"OOR6DAP\"\u003e\n\u003cp id=\"NM8TUA9\"\u003eA Shimano ESSA drivetrain brings effortless shifting and wide ratios to cover any terrain.\u003c\/p\u003e\n\u003c\/div\u003e\n\u003c\/div\u003e\n\u003c\/li\u003e\n\u003cli class=\"carousel__slide carousel__slide--clone\" aria-hidden=\"true\"\u003e\n\u003cdiv class=\"carousel__item pagebuilder-column\" data-content-type=\"slide\"\u003e\n\u003cfigure class=\"pagebuilder-image\" data-content-type=\"image\" data-appearance=\"full-width\" data-element=\"main\" data-pb-style=\"GWTH39J\"\u003e\u003cpicture\u003e\u003csource media=\"(max-width: 768px)\" srcset=\"https:\/\/www.freewheel.co.uk\/media\/headless_websites\/genesis\/cda\/cda_10\/800x1000-cdf10-keyfeature-c.jpg\" data-element=\"lazy_mobile_image\"\u003e\u003cimg alt=\"\" title=\"\" src=\"https:\/\/www.freewheel.co.uk\/media\/headless_websites\/genesis\/cda\/cda_10\/800x1000-cdf10-keyfeature-c.jpg\" data-el
ement=\"lazy_image\"\u003e\u003c\/picture\u003e\u003c\/figure\u003e\n\u003ch3 class=\"text-xl font-medium\" data-content-type=\"heading\" data-appearance=\"default\" data-element=\"main\" data-pb-style=\"JLDTG68\"\u003eBig Tyres\u003c\/h3\u003e\n\u003cdiv class=\"h-40\" data-content-type=\"text\" data-appearance=\"default\" data-element=\"main\" data-pb-style=\"C7BLEDD\"\u003e\n\u003cp id=\"NM8TUA9\"\u003eThe CDA now features volumous 45mm Maxxis Rambler tyres for added comfort on all surfaces and increased confidence offroad.\u003c\/p\u003e\n\u003c\/div\u003e\n\u003c\/div\u003e\n\u003c\/li\u003e\n\u003cli class=\"carousel__slide carousel__slide--clone\" aria-hidden=\"true\"\u003e\n\u003cdiv class=\"carousel__item pagebuilder-column\" data-content-type=\"slide\"\u003e\n\u003cfigure class=\"pagebuilder-image\" data-content-type=\"image\" data-appearance=\"full-width\" data-element=\"main\" data-pb-style=\"NC8CTF7\"\u003e\u003cpicture\u003e\u003csource media=\"(max-width: 768px)\" srcset=\"https:\/\/www.freewhecp id=\"NM8TUA9\"\u003eThe CDA 10 uses the latest Shimano ESSA drivetrain with a single front chainring. This adds further durability and serviceability to an already dependable drivetrain.\u003c\/p\u003e\n\u003c\/div\u003e\n\u003c\/div\u003e\n\u003c\/li\u003e\n\u003c\/ol\u003e\n\u003c\/div\u003e\n\u003c\/section\u003e\n\u003c\/div\u003e","published_at":"2025-10-22T16:34:01+01:00","created_at":"2025-10-22T16:33:59+01:00","vendor":"Genesis","type":"Bicycles","tags":["CDA","spo-cs-disabled","spo-default","spo-disabled","spo-notify-me-disabled"],"price":79900,"price_min":79900,"price_max":79900,"available":true,"price_varies":false,"compare_at_price":null,"compare_at_price_min":0,"compare_at_price_max":0,"compare_at_price_varies":false,"variants":[{"id":56266468786559,"title":"X-Small","option1":"X-Small","option2":null,"option3":null,"sku":"GN10010XS","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"Genesis CDA 10 - X-Small","public_title":"X-Small","options":["X-Small"],"price":79900,"weight":0,"compare_at_price":null,"inventory_management":"shopify","barcode":"","requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":56266468819327,"title":"Small","option1":"Small","option2":null,"option3":null,"sku":"GN10010SM","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Genesis CDA 10 - Small","public_title":"Small","options":["Small"],"price":79900,"weight":0,"compare_at_price":null,"inventory_management":"shopify","barcode":"","requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":56266468852095,"title":"Medium","option1":"Medium","option2":null,"option3":null,"sku":"GN10010MD","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Genesis CDA 10 - Medium","public_title":"Medium","options":["Medium"],"price":79900,"weight":0,"compare_at_price":null,"inventory_management":"shopify","barcode":"","requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":56266468884863,"title":"Large","option1":"Large","option2":null,"option3":null,"sku":"GN10010LG","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Genesis CDA 10 - Large","public_title":"Large","options":["Large"],"price":79900,"weight":0,"compare_at_price":null,"inventory_management":"shopify","barcode":"","requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":1,"max":null,"increment":1}},{"id":56266468917631,"title":"X-Large","option1":"X-Large","option2":null,"option3":null,"sku":"GN10010XL","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"Genesis CDA 10 - X-Large","public_title":"X-Large","options":["X-Large"],"price":79900,"weight":0,"compare_at_price":null,"inventory_management":"shopify","barcode":"","requires_selling_plan":false,"selling_plan_allocations":[],"quantity_rule":{"min":
1,"max":null,"increment":1}}],"images":["\/\/projektride.co.uk\/cdn\/shop\/files\/gn10010_cda_10_detail_01.jpg?v=1761147063","\/\/projektride.co.uk\/cdn\/shop\/files\/gn10010_cda_10_detail_02.jpg?v=1761147063","\/\/projektride.co.uk\/cdn\/shop\/files\/gn10010_cda_10_detail_03.jpg?v=1761147063","\/\/projektride.co.uk\/cdn\/shop\/files\/gn10010_cda_10_detail_04.jpg?v=1761147063","\/\/projektride.co.uk\/cdn\/shop\/files\/gn10010_cda_10_detail_05.jpg?v=1761147063","\/\/projektride.co.uk\/cdn\/shop\/files\/gn10010_cda_10_detail_06.jpg?v=1761147063","\/\/projektride.co.uk\/cdn\/shop\/files\/gn10010_cda_10_detail_07.jpg?v=1761147063","\/\/projektride.co.uk\/cdn\/shop\/files\/gn10010_cda_10_detail_08.jpg?v=1761147063","\/\/projektride.co.uk\/cdn\/shop\/files\/gn10010_cda_10_detail_09.jpg?v=1761147063","\/\/projektride.co.uk\/cdn\/shop\/files\/gn10010_cda_10_detail_10.jpg?v=1761147063","\/\/projektride.co.uk\/cdn\/shop\/files\/gn10010_cda_10_detail_11.jpg?v=1761147064","\/\/projektride.co.uk\/cdn\/shop\/files\/gn10010
=\"default\" data-element=\"main\" data-pb-style=\"C7BLEDD\"\u003e\n\u003cp id=\"NM8TUA9\"\u003eThe CDA now features volumous 45mm Maxxis Rambler tyres for added comfort on all surfaces and increased confidence offroad.\u003c\/p\u003e\n\u003c\/div\u003e\n\u003c\/div\u003e\n\u003c\/li\u003e\n\u003cli class=\"carousel__slide carousel__slide--clone\" aria-hidden=\"true\"\u003e\n\u003cdiv class=\"carousel__item pagebuilder-column\" data-content-type=\"slide\"\u003e\n\u003cfigure class=\"pagebuilder-image\" data-content-type=\"image\" data-appearance=\"full-width\" data-element=\"main\" data-pb-style=\"NC8CTF7\"\u003e\u003cpicture\u003e\u003csource media=\"(max-width: 768px)\" srcset=\"https:\/\/www.freewheel.co.uk\/media\/headless_websites\/genesis\/cda\/cda_10\/800x1000-cdf10-keyfeature-a.jpg\" data-element=\"lazy_mobile_image\"\u003e\u003cimg alt=\"\" title=\"\" src=\"https:\/\/www.freewheel.co.uk\/media\/headless_websites\/genesis\/cda\/cda_10\/800x1000-cdf10-keyfeature-a.jpg\" data-element=\"lazy_image\"\u003
e\u003c\/picture\u003e\u003c\/figure\u003e\n\u003ch3 class=\"text-xl font-medium\" data-content-type=\"heading\" data-appearance=\"default\" data-element=\"main\" data-pb-style=\"JGQ2LKQ\"\u003eSix Zero Six One\u003c\/h3\u003e\n\u003cdiv class=\"h-40\" data-content-type=\"text\" data-appearance=\"default\" data-element=\"main\" data-pb-style=\"FNHCFU7\"\u003e\n\u003cp id=\"NM8TUA9\"\u003eOur ALX8 6061 aluminium tubeset makes the CDA a lightweight, dependable allrounder. Combined with a chromoly fork and increased tyre clearance the ride is sublime!\u003c\/p\u003e\n\u003c\/div\u003e\n\u003c\/div\u003e\n\u003c\/li\u003e\n\u003cli class=\"carousel__slide carousel__slide--clone carousel__slide--prev\" aria-hidden=\"true\"\u003e\n\u003cdiv class=\"carousel__item pagebuilder-column\" data-content-type=\"slide\"\u003e\n\u003cfigure class=\"pagebuilder-image\" data-content-type=\"image\" data-appearance=\"full-width\" data-element=\"main\" data-pb-style=\"XYP271N\"\u003e\u003cpicture\u003e\u003csource media=\"(max-width: 768px)\" srcset=\"https:\/\/www.freewheel.co.uk\/media\/headless_websites\/genesis\/cda\/cda_10\/800x1000-cdf10-keyfeature-b.jpg\" data-element=\"lazy_mobile_image\"\u003e\u003cimg alt=\"\" title=\"\" src=\"https:\/\/www.freewheel.co.uk\/media\/headless_websites\/genesis\/cda\/cda_10\/800x1000-cdf10-keyfeature-b.jpg\" data-element=\"lazy_image\"\u003e\u003c\/picture\u003e\u003c\/figure\u003e\n\u003ch3 class=\"text-xl font-medium\" data-content-type=\"heading\" data-appearance=\"default\" data-element=\"main\" data-pb-style=\"REMDX5H\"\u003e1X\u003c\/h3\u003e\n\u003cdiv class=\"h-40\" data-content-type=\"text\" data-appearance=\"default\" data-element=\"main\" data-pb-style=\"FKW8FI2\"\u003e\n\u003cp id=\"NM8TUA9\"\u003eThe CDA 10 uses the latest Shimano ESSA drivetrain with a single front chainring. This adds further durability and serviceability to an already dependable drivetrain.\u003c\/p\u003e\n\u003c\/div\u003e\n\u003c\/div\u003e\n\u003c\/li\u003e\n\u003c\/ol\u003e\n\u003c\/div\u003e\n\u003c\/sectio
n\u003e\n\u003c\/div\u003e"};
window._RestockRocketConfig.variantsInventoryPolicy = {56266468786559 : "deny",56266468819327 : "deny",56266468852095 : "deny",56266468884863 : "deny",56266468917631 : "deny",};
window._RestockRocketConfig.variantsInventoryQuantity = {56266468786559 : parseInt("0"),56266468819327 : parseInt("1"),56266468852095 : parseInt("1"),56266468884863 : parseInt("1"),56266468917631 : parseInt("1"),};
window._RestockRocketConfig.variantsPreorderCount = {56266468786559 : parseInt(""),56266468819327 : parseInt(""),56266468852095 : parseInt(""),56266468884863 : parseInt(""),56266468917631 : parseInt(""),};
window._RestockRocketConfig.variantsPreorderCountForMarket = {56266468786559 : null,56266468819327 : null,56266468852095 : null,56266468884863 : null,56266468917631 : null,};
window._RestockRocketConfig.variantsPreorderMaxCount = {56266468786559 : parseInt(""),56266468819327 : parseInt(""),56266468852095 : parseInt(""),56266468884863 : parseInt(""),56266468917631 : parseIn<
uuid>/
<
handle>-<
version>/assets/...
// Trailing digits (e.g. ".../restockrocket-1-521/assets/" -> "521"). Kept numeric to
// match ParseStoqData, so funnel app_version lines up with the order-attribution
// app_version. Reflects the ACTUAL deployed build. This is the SINGLE source of the
// parsed version — preorder.js getAppVersion() reads it back off config rather than
// re-parsing, so the regex lives in exactly one place.
try {
const _stoqVersionMatch = window._RestockRocketConfig.scriptHost.match(/(\d+)\/?(?:assets\/?)?$/);
window._RestockRocketConfig.appVersion = (_stoqVersionMatch && _stoqVersionMatch[1]) || '';
} catch (e) {
window._RestockRocketConfig.appVersion = '';
}
const SETTINGS_CACHE_DURATION = 15 * 60 * 1000; // 15 minutes in milliseconds
const LIQUID_CACHE_MAX_AGE = 15 * 60; // 15 minutes in seconds
// Calculate Liquid cache freshness once at initialization
const liquidRenderedAt = window._RestockRocketConfig.liquidRenderedAt;
// Validate timestamp and calculate ca 0) {
console.debug(`STOQ - Client clock appears ahead of server by ${Math.abs(Math.round(liquidCacheAge / 60))} minutes, assuming cache fresh`);
window._RestockRocketConfig.isLiquidCacheFresh = true;
} else if (liquidCacheAge
<
= LIQUID_CACHE_MAX_AGE) {
console.debug(`STOQ - Liquid cache is fresh (${Math.round(liquidCacheAge / 60)} minutes old)`);
window._RestockRocketConfig.isLiquidCacheFresh = true;
} else {
console.debug(`STOQ - Liquid cache is stale (${Math.round(liquidCacheAge / 60)} minutes old, max ${Math.round(LIQUID_CACHE_MAX_AGE / 60)} minutes)`);
window._RestockRocketConfig.isLiquidCacheFresh = false;
}
}
function checkSettingsExpiry(settings) {
try {
if (!settings || !settings.updated_at) {
console.debug('STOQ - Invalid settings data structure');
return null;
}
if (!settings.cache) {
console.debug('STOQ - settings caching disabled');
return null;
}
// Check if translations are enabled but missing from cache
// This handles the backfill period where DB has translations but metafield doesn't
if (settings.multi_language_enabled) {
if (!settings.translations) {
// Translations enabled but no
translation data in metafield
// Metafield hasn't been backfilled yet - force refresh
console.debug('STOQ - multi-language enabled but no translation data in cache, fetching fresh');
return null;
}
// Translations object exists in metafield - cache is valid
// If current locale isn't translated, applyTranslations will gracefully use default locale from base fields
if (window._RestockRocketConfig.normalizedLocale &&
!Object.prototype.hasOwnProperty.call(settings.translations, window._RestockRocketConfig.normalizedLocale)) {
console.debug('STOQ - locale not explicitly translated, will use default language from cache');
}
// Don't return null - continue using cache even for untranslated locales
}
const updatedAt = new Date(settings.updated_at);
if (isNaN(updatedAt.getTime())) {
console.debug('STOQ - Invalid updated_at date format in settings');
return null;
}
const age = Date.now() - updatedAt.getTime();
if (age
<ctedVariantId || '',
liquid_rendered_at: _stoqInitConfig.liquidRenderedAt || 0,
app_version: _stoqInitConfig.appVersion || '',
liquid_cache_age: _stoqInitConfig.liquidCacheAge,
// Selected variant's stock posture as our app saw it at render — explains
// whether we *should* have treated it as a preorder candidate.
inventory_policy: (_stoqInitConfig.variantsInventoryPolicy || {})[_stoqSelectedVariantId] || '',
inventory_quantity: (_stoqInitConfig.variantsInventoryQuantity || {})[_stoqSelectedVariantId],
});
} catch (e) {
console.debug('STOQ - stoq_initialized publish failed:', e);
}
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 n
ormalizedLocale = 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:', normalizedL
ocale);
}
delete settings.translations;
return settings;
} catch (e) {
console.debug('STOQ - error applying translations:', e);
return settings;
}
}
// Setup event listener for cart selling plan updates
// This must be called before any scripts are loaded to avoid race conditions
function setupCartSellingPlanUpdater(settings) {
// Setup listener regardless - updateCartSellingPlans has its own guards
// This ensures cleanup happens even when preorders are disabled globally
// Listen for stoq:inventory-data-loaded event dispatched by api.js
window.addEventListener('stoq:inventory-data-loaded', function(event) {
console.debug('STOQ - Inventory data loaded, updating cart selling plans');
if (window._RestockRocket && window._RestockRocket.updateCartSellingPlans) {
window._RestockRocket.updateCartSellingPlans()
.then(hasUpdates => {
if (hasUpdates) {
console.debug('STOQ - cart selling plans update
d successfully');
} else {
console.debug('STOQ - no cart selling plan updates needed');
}
})
.catch(error => {
console.error('STOQ - error updating cart selling plans:', error);
});
}
});
}
// ---- Live settings via the Storefront API (additive, does not gate init) ----
// The inlined `cachedSettings` comes from the app-embed Liquid render, which
// Shopify edge-caches and can serve stale. Reading the same `settings` metafield
// back over the Storefront API is a POST to /api/<
version>/graphql.json — never
// CDN-cached — so it returns the live value on every page load. We fetch it
// best-effort and stash it on `window._RestockRocketConfig.storefrontSettings`
// so individual behaviours can migrate onto the fresh value over time. This is
// PURELY ADDITIVE: it does NOT change the resolution flow below, never blocks
// init, and silently no-ops on any failure / missing token.
(function loadStorefrontSettings() {
const cfg = window._RestockRocketConfig;
if (!cfg.storefrontAccessToken || cfg.disableStorefrontApi === true) return;
// Deferred to browser idle so this best-effort read runs strictly AFTER the
// critical init flow and never competes with it for a connection — the call
// is a live, uncached Storefront round-trip and can be slow (multi-second
// TTFB observed). Nothing on the critical path waits for it.
function run() {
const query = 'query StoqSettings($namespace: String!) { shop { metafield(namespace: $namespace, key:p'
};
if (window.Shopify?.theme?.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._RestockRocketConfig.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('S
TOQ - failed to load settings:', error);
}
})
.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) {
// Apply failures are programming bugs (e.g. response shape changed
// server-side and the assignment threw). Surface them as console.error
// so they're visible in browser logs, then re-throw to fall through
// to the same Liquid-cached fallback as a fetch failure.
console.error('STOQ - apply failed for ' +
endpoint + ':', applyError);
throw applyError;
}
})
.catch(function(error) {
console.debug(`STOQ - using cached ${endpoint}:`, error.message);
});
}
function initializeScripts(settings) {
settings = applyTranslations(settings);
window._RestockRocketConfig.settings = settings;
console.debug(`STOQ - settings configured for ${window._RestockRocketConfig.pageType}`);
// Stale-Liquid resilience (default-on, per-shop opt-out via the
// `disable_refresh_on_stale_liquid` Toggle, surfaced as the negative
// `disable_refresh_on_stale_liquid` flag in settings.json so that
// `undefined` -- in CDN-cached metafield payloads that predate this
// key -- reads as `!undefined === true` and gets default-on behavior
// immediately, no metafield rewrite required).
// When the Liquid CDN cache is older than LIQUID_CACHE_MAX_AGE the in-page
// selling_plans / integrations metafields can be wrong; refresh both from
// the API before launching scr
ipts. Race against a 1000ms timeout so a slow
// API can't block init indefinitely. If the timeout wins, the in-flight
// fetches still complete and update window._RestockRocketConfig — the
// bundle re-reads sellingPlans/integrations on every interaction, so the
// late-arriving values benefit subsequent renders even though the first
// paint may use the Liquid-cached values. On any failure the existing
// Liquid-loaded values stay in place via fetchEmbedConfig's catch.
if (!window._RestockRocketConfig.isLiquidCacheFresh && !settings.disable_refresh_on_stale_liquid) {
console.debug('STOQ - Liquid cache stale, refreshing selling_plans + integrations');
Promise.race([
Promise.all([
fetchEmbedConfig('selling_plans', function(data) {
if (data && Array.isArray(data.plans)) {
window._RestockRocketConfig.sellingPlans = data.plans;
window._RestockRocketConfig.disabledSellingPlanIds = data.disabled_plan_ids || [];
}
}),
fetchEmbedConfig('integrations', function(data) {
if (Array.isArray(data)) {
window._RestockRocketConfig.integrations = data;
}
})
]),
new Promise(function(resolve) { setTimeout(resolve, 1000); })
]).then(function() { loadScripts(settings); });
return;
}
loadScripts(settings);
}
function loadScripts(settings) {
// Setup cart selling plan updater BEFORE loading any scripts to avoid race conditions
setupCartSellingPlanUpdater(settings);
if(settings.enable_app) {
const hijackIntegration = window._RestockRocketConfig.integrations.find(function(integration) {
return integration.type === 'hijack' && integration.enabled && integration.page_types.includes(window._RestockRocketConfig.pageType);
})
// STOQ-1520: serve the lean back-in-stock-only build (no preorder/hijack code)
// only to shops with NO preorder plans. Use the full build if preorder is o
n,
// an enabled offer exists, or a disabled-but-kept plan id remains (cart sweep
// must still strip those). Rationale in the PR.
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 collectionScriptUrl = usePreorderBuild
? window._RestockRocketConfig.scriptUrlCollection
: window._RestockRocketConfig.scriptUrlCollectionBis;
const productScriptUrl = usePreorderBuild
? window._RestockRocketConfig.scriptUrlProduct
: window._RestockRocketConfig.scriptUrlProductBis;
const pageType = window._RestockRocketConfig.pageType;
const collecti