@swell/apps-sdk 1.0.129 → 1.0.132

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -7179,108 +7179,144 @@ var ThemeCache = class extends Cache {
7179
7179
  };
7180
7180
 
7181
7181
  // src/resources/product_helpers.ts
7182
- function calculateAddOptionsPrice(product, queryParams) {
7183
- const { option_values = "" } = queryParams;
7184
- const queryOptionValues = option_values;
7185
- const optionValues = queryOptionValues.split(",");
7186
- const addPrice = product.options?.reduce((acc, option) => {
7187
- if (!option.active || !option.values || option.values.length <= 0) {
7188
- return acc;
7189
- }
7190
- if (option.input_type !== "select") {
7191
- return acc;
7192
- }
7193
- for (const value of option.values) {
7194
- if (optionValues.includes(value.id)) {
7195
- return acc + (value.price || 0);
7196
- }
7197
- }
7198
- return acc + (option.values[0].price || 0);
7199
- }, 0);
7200
- return product.price + (addPrice || 0);
7201
- }
7202
- function calculateAddOptionsVariantPrice(product, variant, queryParams) {
7203
- const { option_values = "" } = queryParams;
7204
- const queryOptionValues = option_values;
7205
- const optionValues = queryOptionValues.split(",");
7206
- const addPrice = product.options?.reduce((acc, option) => {
7207
- if (option.variant || // skip variant options
7208
- !option.active || !option.values || option.values.length <= 0) {
7209
- return acc;
7210
- }
7211
- if (option.input_type !== "select") {
7212
- return acc;
7213
- }
7214
- for (const value of option.values) {
7215
- if (optionValues.includes(value.id)) {
7216
- return acc + (value.price || 0);
7217
- }
7218
- }
7219
- return acc + (option.values[0].price || 0);
7220
- }, 0);
7221
- let price = product.price;
7222
- if (variant.price !== null && variant.price !== void 0) {
7223
- price = variant.price;
7224
- }
7225
- return price + (addPrice || 0);
7226
- }
7227
7182
  function getAvailableVariants(product) {
7228
7183
  return (product.variants?.results?.slice()?.reverse() || []).filter(
7229
7184
  (variant) => variant.stock_status === "in_stock" || !variant.stock_status
7230
7185
  );
7231
7186
  }
7232
- function getSelectedSwellVariant(product, queryParams) {
7233
- const { variant: queryVariant, option_values } = queryParams;
7234
- const queryOptionValues = option_values;
7187
+ function isOptionValueAvailable(option, value, product, availableVariants) {
7188
+ if (!option.variant) {
7189
+ return true;
7190
+ }
7191
+ const hasVariants = product.variants?.results.length > 0;
7192
+ if (!hasVariants) {
7193
+ return true;
7194
+ }
7195
+ const variants = availableVariants || getAvailableVariants(product);
7196
+ return variants.some(
7197
+ (variant) => variant.option_value_ids.includes(value.id)
7198
+ );
7199
+ }
7200
+ function isOptionValueSelected(option, value, product, queryParams, selectedVariant) {
7201
+ let variant;
7202
+ if (option.variant) {
7203
+ variant = selectedVariant || getSelectedVariant(product, queryParams);
7204
+ }
7205
+ const selectedOptionValues = getSelectedVariantOptionValues(
7206
+ product,
7207
+ queryParams,
7208
+ variant
7209
+ );
7210
+ return selectedOptionValues.includes(value.id);
7211
+ }
7212
+ function getSelectedVariant(product, queryParams) {
7213
+ const {
7214
+ variant: queryVariant,
7215
+ option_values: queryOptionValues,
7216
+ selected_option_value: selectedOptionValue
7217
+ } = queryParams;
7235
7218
  const variants = getAvailableVariants(product);
7236
7219
  let selectedVariant = void 0;
7237
7220
  if (queryVariant) {
7238
7221
  selectedVariant = variants.find((variant) => variant.id === queryVariant);
7239
7222
  } else if (queryOptionValues) {
7240
7223
  const optionValues = queryOptionValues.split(",");
7241
- selectedVariant = variants.find(
7242
- (variant) => variant.option_value_ids.every(
7224
+ selectedVariant = variants.find((variant) => {
7225
+ if (variant.option_value_ids.length !== optionValues.length) {
7226
+ return false;
7227
+ }
7228
+ return variant.option_value_ids.every(
7243
7229
  (optionValueId) => optionValues.includes(optionValueId)
7244
- )
7245
- );
7230
+ );
7231
+ });
7232
+ if (!selectedVariant && selectedOptionValue) {
7233
+ selectedVariant = variants.filter(
7234
+ (variant) => variant.option_value_ids.includes(selectedOptionValue)
7235
+ )[0];
7236
+ }
7246
7237
  }
7247
7238
  return selectedVariant || variants?.[0] || void 0;
7248
7239
  }
7249
- function getSelectedVariant(product, queryParams) {
7250
- return getSelectedSwellVariant(
7240
+ function getSelectedVariantOptionValues(product, queryParams, variant) {
7241
+ if (variant) {
7242
+ return variant.option_value_ids;
7243
+ }
7244
+ const { option_values: queryOptionValues = "" } = queryParams;
7245
+ const optionValues = queryOptionValues.split(",");
7246
+ return (product.options || []).reduce((acc, option) => {
7247
+ if (!option.values) {
7248
+ return acc;
7249
+ }
7250
+ const hasOptionValues = option.values.length > 0;
7251
+ if (!option.active || !hasOptionValues) {
7252
+ return acc;
7253
+ }
7254
+ const value = option.values.find(
7255
+ (value2) => optionValues.includes(value2.id)
7256
+ );
7257
+ if (value) {
7258
+ acc.push(value.id);
7259
+ }
7260
+ return acc;
7261
+ }, []);
7262
+ }
7263
+ function getPurchaseOptions(product, queryParams) {
7264
+ if (!product?.purchase_options) {
7265
+ return null;
7266
+ }
7267
+ const { standard, subscription } = product.purchase_options;
7268
+ const selectedPurchaseOptionType = getSelectedPurchaseOptionType(
7251
7269
  product,
7252
7270
  queryParams
7253
7271
  );
7272
+ const purchaseOptions = {};
7273
+ if (standard) {
7274
+ purchaseOptions.standard = {
7275
+ ...standard,
7276
+ selected: selectedPurchaseOptionType === "standard"
7277
+ };
7278
+ }
7279
+ if (subscription) {
7280
+ const selectedPlan = getSelectedSubscriptionPurchaseOptionPlan(
7281
+ selectedPurchaseOptionType,
7282
+ subscription,
7283
+ queryParams
7284
+ );
7285
+ purchaseOptions.subscription = {
7286
+ ...subscription,
7287
+ selected: selectedPurchaseOptionType === "subscription",
7288
+ plans: subscription.plans.map((plan) => ({
7289
+ ...plan,
7290
+ selected: selectedPlan ? plan.id === selectedPlan.id : false
7291
+ }))
7292
+ };
7293
+ }
7294
+ return Object.keys(purchaseOptions).length > 0 ? purchaseOptions : null;
7254
7295
  }
7255
- function getSelectedOptionValues(product, queryParams) {
7256
- const variant = getSelectedSwellVariant(product, queryParams);
7257
- return getSelectedVariantOptionValues(product, variant, queryParams);
7296
+ function getSelectedPurchaseOptionType(product, queryParams) {
7297
+ const { purchase_options: purchaseOptions } = product;
7298
+ if (!purchaseOptions) {
7299
+ return null;
7300
+ }
7301
+ const { purchase_option: purchaseOption } = queryParams;
7302
+ const purchaseOptionType = purchaseOption?.type;
7303
+ if (purchaseOptionType && purchaseOptionType in purchaseOptions) {
7304
+ return purchaseOptionType;
7305
+ }
7306
+ return purchaseOptions.standard ? "standard" : "subscription";
7258
7307
  }
7259
- function getSelectedVariantOptionValues(product, variant, queryParams) {
7260
- const { option_values = "" } = queryParams;
7261
- const queryOptionValues = option_values;
7262
- const optionValues = queryOptionValues.split(",");
7263
- const selectedValues = variant ? [...variant.option_value_ids || []] : [];
7264
- const values = [];
7265
- for (const option of product.options || []) {
7266
- if (option.active && option.values && option.values.length > 0 && option.input_type === "select") {
7267
- let selectedByVariantId = "";
7268
- let selectedByOptionId = "";
7269
- for (const value of option.values) {
7270
- if (selectedValues.includes(value.id)) {
7271
- selectedByVariantId = value.id;
7272
- break;
7273
- }
7274
- if (optionValues.includes(value.id)) {
7275
- selectedByOptionId = value.id;
7276
- }
7277
- }
7278
- values.push(
7279
- selectedByVariantId || selectedByOptionId || option.values[0].id
7280
- );
7281
- }
7308
+ function getSelectedSubscriptionPurchaseOptionPlan(selectedPurchaseOptionType, subscriptionPurchaseOption, queryParams) {
7309
+ if (selectedPurchaseOptionType !== "subscription") {
7310
+ return null;
7282
7311
  }
7283
- return values;
7312
+ const { purchase_option: purchaseOption } = queryParams;
7313
+ let selectedPlan = null;
7314
+ if (purchaseOption?.plan_id) {
7315
+ selectedPlan = subscriptionPurchaseOption.plans.find(
7316
+ (plan) => plan.id === purchaseOption.plan_id
7317
+ );
7318
+ }
7319
+ return selectedPlan || subscriptionPurchaseOption.plans[0];
7284
7320
  }
7285
7321
 
7286
7322
  // src/resources/variant.ts
@@ -7294,11 +7330,10 @@ function transformSwellVariant(params, product, variant) {
7294
7330
  return {
7295
7331
  ...variant,
7296
7332
  // add swell properties there
7297
- price: calculateAddOptionsVariantPrice(product, variant, params),
7298
7333
  selected_option_values: getSelectedVariantOptionValues(
7299
7334
  product,
7300
- variant,
7301
- params
7335
+ params,
7336
+ variant
7302
7337
  )
7303
7338
  };
7304
7339
  }
@@ -7311,8 +7346,8 @@ function transformSwellProduct(params, product) {
7311
7346
  const newProduct = {
7312
7347
  ...product,
7313
7348
  // add swell properties there
7314
- price: calculateAddOptionsPrice(product, params),
7315
- selected_option_values: getSelectedOptionValues(product, params)
7349
+ selected_option_values: getSelectedVariantOptionValues(product, params),
7350
+ purchase_options: getPurchaseOptions(product, params)
7316
7351
  };
7317
7352
  if (Array.isArray(newProduct.variants?.results)) {
7318
7353
  newProduct.variants = {
@@ -7669,14 +7704,10 @@ var Swell = class _Swell {
7669
7704
  }
7670
7705
  };
7671
7706
  function getCacheKey(key, args) {
7672
- let cacheKey = key;
7673
7707
  if (Array.isArray(args) && args.length > 0) {
7674
- cacheKey += `_${JSON.stringify(args)}`;
7708
+ return `${key}_${md5(JSON.stringify(args))}`;
7675
7709
  }
7676
- if (cacheKey.length > 512) {
7677
- cacheKey = `${cacheKey.slice(0, 480)}${md5(cacheKey)}`;
7678
- }
7679
- return cacheKey;
7710
+ return key;
7680
7711
  }
7681
7712
  var SwellBackendAPI = class {
7682
7713
  apiHost = DEFAULT_API_HOST;
@@ -7808,11 +7839,12 @@ async function getBlog(swell, id, query) {
7808
7839
  var import_json53 = __toESM(require("json5"), 1);
7809
7840
  var import_lodash_es4 = require("lodash-es");
7810
7841
  var NO_INLINE = true;
7811
- async function getEasyblocksPageTemplate(theme, pageId) {
7842
+ async function getEasyblocksPageTemplate(theme, pageId, altTemplate) {
7812
7843
  let templateConfig = null;
7813
7844
  templateConfig = await theme.getThemeTemplateConfigByType(
7814
7845
  "templates",
7815
- pageId
7846
+ pageId,
7847
+ altTemplate
7816
7848
  );
7817
7849
  if (templateConfig) {
7818
7850
  if (templateConfig.file_path.endsWith(".liquid")) {
@@ -8183,11 +8215,7 @@ function getAllSectionComponentTemplates(allSections) {
8183
8215
  );
8184
8216
  }
8185
8217
  }
8186
- return list.filter((template) => {
8187
- return Object.keys(template.entry).some(
8188
- (key) => key !== "_id" && key !== "_component"
8189
- );
8190
- });
8218
+ return list;
8191
8219
  }
8192
8220
  function getEasyblocksPagePropsWithConfigs(themeGlobals, allSections, pageSections, layoutSectionGroups, pageId) {
8193
8221
  const rootComponent = {
@@ -13866,8 +13894,7 @@ function ShopifyArticle(instance, blog, blogCategory) {
13866
13894
  (blog2) => blog2.date_published || blog2.date_created
13867
13895
  ),
13868
13896
  tags: defer(() => blog.tags),
13869
- template_suffix: void 0,
13870
- // TODO
13897
+ template_suffix: defer(() => blog.theme_template),
13871
13898
  title: defer(() => blog.title),
13872
13899
  updated_at: deferWith(
13873
13900
  blog,
@@ -13936,8 +13963,7 @@ function ShopifyBlog(instance, blogCategory) {
13936
13963
  // TODO
13937
13964
  tags: allTags,
13938
13965
  // TODO: this should only apply to articles in the current view
13939
- template_suffix: void 0,
13940
- // TODO
13966
+ template_suffix: defer(() => blogCategory.theme_template),
13941
13967
  title: defer(() => blogCategory.title),
13942
13968
  url: deferWith(
13943
13969
  blogCategory,
@@ -14200,29 +14226,23 @@ function ShopifyProduct(instance, product, depth = 0) {
14200
14226
  if (!Array.isArray(product2.options)) {
14201
14227
  return {};
14202
14228
  }
14203
- let index = 0;
14229
+ const { queryParams } = instance.swell;
14230
+ const variants = getAvailableVariants(product2);
14231
+ const variant = getSelectedVariant(product2, queryParams);
14204
14232
  return product2.options.reduce(
14205
- (acc, option) => {
14206
- if (option.active && option.name) {
14207
- acc[option.name.toLowerCase()] = {
14208
- name: option.name,
14209
- position: ++index,
14210
- selected_value: void 0,
14211
- // variant_option: option.variant,
14212
- values: option.values?.map(
14213
- (value) => ShopifyProductOptionValue({
14214
- available: true,
14215
- id: value.id,
14216
- name: value.name,
14217
- product_url: void 0,
14218
- selected: false,
14219
- swatch: void 0,
14220
- variant: void 0
14221
- // addPrice: value.price,
14222
- })
14223
- ) ?? []
14224
- };
14233
+ (acc, option, index) => {
14234
+ if (!option.active || !option.name) {
14235
+ return acc;
14225
14236
  }
14237
+ acc[option.name.toLowerCase()] = getOption(
14238
+ option,
14239
+ index,
14240
+ product2,
14241
+ instance,
14242
+ depth,
14243
+ variants,
14244
+ variant
14245
+ );
14226
14246
  return acc;
14227
14247
  },
14228
14248
  {}
@@ -14234,33 +14254,20 @@ function ShopifyProduct(instance, product, depth = 0) {
14234
14254
  if (!Array.isArray(product2.options)) {
14235
14255
  return [];
14236
14256
  }
14237
- const variant = getSelectedVariant(product2, instance.swell.queryParams);
14238
- const optionValues = variant?.option_value_ids || [];
14239
- return product2.options.filter((option) => option.active && option.name).map((option, index) => {
14240
- return {
14241
- name: option.name,
14242
- position: index + 1,
14243
- selected_value: void 0,
14244
- // variant_option: option.variant,
14245
- values: option.values?.map(
14246
- (value) => ShopifyProductOptionValue({
14247
- available: true,
14248
- id: value.id,
14249
- name: value.name,
14250
- product_url: void 0,
14251
- selected: optionValues.includes(value.id),
14252
- swatch: void 0,
14253
- variant: ShopifyVariant(
14254
- instance,
14255
- variant || product2,
14256
- product2,
14257
- depth + 1
14258
- )
14259
- // addPrice: value.price,
14260
- })
14261
- )
14262
- };
14263
- });
14257
+ const { queryParams } = instance.swell;
14258
+ const variants = getAvailableVariants(product2);
14259
+ const variant = getSelectedVariant(product2, queryParams);
14260
+ return product2.options.filter((option) => option.active && option.name).map(
14261
+ (option, index) => getOption(
14262
+ option,
14263
+ index,
14264
+ product2,
14265
+ instance,
14266
+ depth,
14267
+ variants,
14268
+ variant
14269
+ )
14270
+ );
14264
14271
  }
14265
14272
  ),
14266
14273
  price: deferWith(product, (product2) => product2.price),
@@ -14335,7 +14342,7 @@ function ShopifyProduct(instance, product, depth = 0) {
14335
14342
  selected_variant: void 0,
14336
14343
  selling_plan_groups: [],
14337
14344
  tags: defer(() => product.tags),
14338
- template_suffix: void 0,
14345
+ template_suffix: defer(() => product.theme_template),
14339
14346
  title: defer(() => product.name),
14340
14347
  type: defer(() => product.type),
14341
14348
  url: deferWith(product, (product2) => `/products/${product2.slug}`),
@@ -14361,6 +14368,38 @@ function ShopifyProductOptionValue(values) {
14361
14368
  function isLikeShopifyProduct(value) {
14362
14369
  return typeof value === "object" && value !== null && Object.hasOwn(value, "variants") && Object.hasOwn(value, "gift_card?") && Object.hasOwn(value, "price_varies") && Object.hasOwn(value, "has_only_default_variant");
14363
14370
  }
14371
+ function getOption(option, index, product, instance, depth, variants, variant) {
14372
+ const { queryParams } = instance.swell;
14373
+ return {
14374
+ ...option,
14375
+ name: option.name,
14376
+ position: index + 1,
14377
+ selected_value: void 0,
14378
+ values: option.values?.map(
14379
+ (value) => ShopifyProductOptionValue({
14380
+ ...value,
14381
+ available: isOptionValueAvailable(option, value, product, variants),
14382
+ id: value.id,
14383
+ name: value.name,
14384
+ product_url: void 0,
14385
+ selected: isOptionValueSelected(
14386
+ option,
14387
+ value,
14388
+ product,
14389
+ queryParams,
14390
+ variant
14391
+ ),
14392
+ swatch: void 0,
14393
+ variant: ShopifyVariant(
14394
+ instance,
14395
+ variant || product,
14396
+ product,
14397
+ depth + 1
14398
+ )
14399
+ })
14400
+ )
14401
+ };
14402
+ }
14364
14403
 
14365
14404
  // src/compatibility/shopify-objects/line_item.ts
14366
14405
  function ShopifyLineItem(instance, item, cart, options = {}) {
@@ -14475,26 +14514,8 @@ function isTrialSubscriptionItem(item) {
14475
14514
  function resolveSubscription(item) {
14476
14515
  const purchaseOption = item?.purchase_option;
14477
14516
  if (purchaseOption?.type !== "subscription") {
14478
- return void 0;
14479
- }
14480
- const trialDays = purchaseOption.billing_schedule?.trial_days || 0;
14481
- const trialText = trialDays > 0 ? ` (Includes ${trialDays} trial day${trialDays === 1 ? "" : "s"})` : "";
14482
- const intervalCount = purchaseOption.billing_schedule?.interval_count || 1;
14483
- let intervalText = "day";
14484
- switch (purchaseOption.billing_schedule?.interval) {
14485
- case "weekly":
14486
- intervalText = "wk";
14487
- break;
14488
- case "monthly":
14489
- intervalText = "mo";
14490
- break;
14491
- case "yearly":
14492
- intervalText = "yr";
14493
- break;
14494
- default:
14517
+ return;
14495
14518
  }
14496
- const periodText = `${intervalCount > 1 ? intervalCount : ""}${intervalText}`;
14497
- const text = `${periodText}${trialText}`;
14498
14519
  return {
14499
14520
  checkout_charge_amount: item.price,
14500
14521
  compare_at_price: item.price,
@@ -14504,14 +14525,11 @@ function resolveSubscription(item) {
14504
14525
  remaining_balance_charge_amount: 0,
14505
14526
  selling_plan_group_id: purchaseOption.plan_id,
14506
14527
  selling_plan: {
14507
- id: 0,
14528
+ id: purchaseOption.plan_id,
14508
14529
  group_id: purchaseOption.plan_id,
14509
14530
  name: purchaseOption.plan_name,
14510
14531
  description: purchaseOption.plan_description,
14511
- // billing_schedule: purchaseOption.billing_schedule,
14512
14532
  options: [],
14513
- // provide as separate parts to properly render currency
14514
- // planPriceText: text,
14515
14533
  checkout_charge: { value: item.price, value_type: "price" },
14516
14534
  recurring_deliveries: item.delivery === "shipment",
14517
14535
  price_adjustments: [],
@@ -14636,10 +14654,7 @@ function ShopifyCart(instance, cart) {
14636
14654
  }),
14637
14655
  items_subtotal_price: defer(() => cart.sub_total),
14638
14656
  note: defer(() => cart.comments),
14639
- original_total_price: deferWith(
14640
- cart,
14641
- (cart2) => cart2.sub_total + cart2.item_discount
14642
- ),
14657
+ original_total_price: deferWith(cart, (cart2) => cart2.capture_total),
14643
14658
  requires_shipping: defer(() => Boolean(cart.shipment_delivery)),
14644
14659
  taxes_included: defer(() => Boolean(cart.item_tax_included)),
14645
14660
  total_discount: defer(() => cart.discount_total),
@@ -14847,7 +14862,7 @@ function ShopifyCollection(instance, category) {
14847
14862
  sort_by: defer(() => category.sort),
14848
14863
  sort_options: defer(() => category.sort_options),
14849
14864
  tags: [],
14850
- template_suffix: void 0,
14865
+ template_suffix: defer(() => category.theme_template),
14851
14866
  title: defer(() => category.name),
14852
14867
  url: deferWith(category, (category2) => `/collections/${category2.slug}`)
14853
14868
  });
@@ -15648,8 +15663,7 @@ function ShopifyPage(_instance, page) {
15648
15663
  page,
15649
15664
  (page2) => page2.date_published || page2.date_created
15650
15665
  ),
15651
- template_suffix: void 0,
15652
- // TODO
15666
+ template_suffix: defer(() => page.theme_template),
15653
15667
  title: deferWith(page, (page2) => page2.title || page2.name),
15654
15668
  // Due to deprecated name field
15655
15669
  url: deferWith(page, (page2) => `/pages/${page2.slug}`)
@@ -15985,17 +15999,13 @@ var ShopifyCompatibility3 = class {
15985
15999
  this.queryParamsMap = this.getQueryParamsMap();
15986
16000
  }
15987
16001
  initGlobals(globals) {
15988
- const { request, page } = globals;
15989
- this.pageId = this.getPageType(globals.page?.id);
15990
- globals.page = {
15991
- ...page || void 0
15992
- };
16002
+ const { request } = globals;
15993
16003
  globals.request = {
15994
16004
  ...request || void 0,
15995
16005
  design_mode: this.swell.isEditor,
15996
16006
  visual_section_preview: false,
15997
16007
  // TODO: Add support for visual section preview
15998
- page_type: page?.id
16008
+ page_type: ""
15999
16009
  };
16000
16010
  globals.collections = new CollectionsDrop(this);
16001
16011
  globals.current_page = this.swell.queryParams.page || 1;
@@ -16004,6 +16014,8 @@ var ShopifyCompatibility3 = class {
16004
16014
  adaptGlobals(globals, prevGlobals) {
16005
16015
  if (globals.page) {
16006
16016
  this.pageId = this.getPageType(globals.page.id);
16017
+ const request = globals.request || prevGlobals.request;
16018
+ request.page_type = globals.page.id;
16007
16019
  }
16008
16020
  if (globals.request) {
16009
16021
  const page = globals.page || prevGlobals.page;
@@ -19082,12 +19094,10 @@ var SwellTheme3 = class {
19082
19094
  getSwellAppThemeProps(swellConfig) {
19083
19095
  return swellConfig?.storefront?.theme || {};
19084
19096
  }
19085
- async initGlobals(pageId) {
19086
- this.pageId = pageId;
19097
+ async initGlobals() {
19087
19098
  await this.themeLoader.init(this.themeConfigs || void 0);
19088
19099
  const { store, session, menus, geo, configs } = await this.getSettingsAndConfigs();
19089
- const { settings, request, page, cart, account, customer } = await this.resolvePageData(store, configs, pageId);
19090
- this.page = page;
19100
+ const { settings, request, cart, account, customer } = await this.resolvePageData(store, configs);
19091
19101
  const globals = {
19092
19102
  ...this.globalData,
19093
19103
  store,
@@ -19095,7 +19105,7 @@ var SwellTheme3 = class {
19095
19105
  session,
19096
19106
  request,
19097
19107
  menus,
19098
- page,
19108
+ page: {},
19099
19109
  cart,
19100
19110
  account,
19101
19111
  customer,
@@ -19126,6 +19136,45 @@ var SwellTheme3 = class {
19126
19136
  ...this.globals
19127
19137
  };
19128
19138
  }
19139
+ async initPageGlobals(pageId, altTemplate) {
19140
+ this.pageId = pageId;
19141
+ const swellPage = this.props.pages?.find(
19142
+ (page2) => page2.id === pageId
19143
+ );
19144
+ const page = {
19145
+ ...swellPage,
19146
+ current: Number(this.swell.queryParams.page) || 1,
19147
+ url: this.swell.url.pathname,
19148
+ custom: !swellPage,
19149
+ slug: void 0,
19150
+ description: void 0,
19151
+ $locale: void 0
19152
+ };
19153
+ if (pageId) {
19154
+ const templateConfig = await this.getThemeTemplateConfigByType(
19155
+ "templates",
19156
+ pageId,
19157
+ altTemplate
19158
+ );
19159
+ let pageSchema;
19160
+ try {
19161
+ pageSchema = import_json56.default.parse(
19162
+ templateConfig?.file_data || "{}"
19163
+ );
19164
+ } catch (err) {
19165
+ console.warn(err);
19166
+ }
19167
+ if (pageSchema?.page) {
19168
+ const { slug, label, description, $locale } = pageSchema.page;
19169
+ page.slug = slug;
19170
+ page.label = label || page.label;
19171
+ page.description = description;
19172
+ page.$locale = $locale;
19173
+ }
19174
+ }
19175
+ this.page = page;
19176
+ this.setGlobals({ page });
19177
+ }
19129
19178
  async getSettingsAndConfigs() {
19130
19179
  const geo = GEO_DATA;
19131
19180
  const [storefrontSettings, settingConfigs] = await Promise.all([
@@ -19175,7 +19224,7 @@ var SwellTheme3 = class {
19175
19224
  configs
19176
19225
  };
19177
19226
  }
19178
- async resolvePageData(store, configs, pageId) {
19227
+ async resolvePageData(store, configs) {
19179
19228
  const configVersion = String(
19180
19229
  this.swell.swellHeaders["theme-config-version"]
19181
19230
  );
@@ -19207,39 +19256,6 @@ var SwellTheme3 = class {
19207
19256
  is_editor: this.swell.isEditor,
19208
19257
  is_preview: this.swell.isPreview
19209
19258
  };
19210
- const swellPage = this.props.pages?.find(
19211
- (page2) => page2.id === pageId
19212
- );
19213
- const page = {
19214
- ...swellPage,
19215
- current: Number(this.swell.queryParams.page) || 1,
19216
- url: this.swell.url.pathname,
19217
- custom: !swellPage,
19218
- slug: void 0,
19219
- description: void 0,
19220
- $locale: void 0
19221
- };
19222
- if (pageId) {
19223
- const templateConfig = await this.getThemeTemplateConfigByType(
19224
- "templates",
19225
- pageId
19226
- );
19227
- let pageSchema;
19228
- try {
19229
- pageSchema = import_json56.default.parse(
19230
- templateConfig?.file_data || "{}"
19231
- );
19232
- } catch (err) {
19233
- console.warn(err);
19234
- }
19235
- if (pageSchema?.page) {
19236
- const { slug, label, description, $locale } = pageSchema.page;
19237
- page.slug = slug;
19238
- page.label = label || page.label;
19239
- page.description = description;
19240
- page.$locale = $locale;
19241
- }
19242
- }
19243
19259
  const [cart, account] = await Promise.all([
19244
19260
  this.fetchSingletonResourceCached(
19245
19261
  "cart",
@@ -19262,7 +19278,6 @@ var SwellTheme3 = class {
19262
19278
  return {
19263
19279
  settings,
19264
19280
  request,
19265
- page,
19266
19281
  cart,
19267
19282
  account,
19268
19283
  customer
@@ -19622,15 +19637,15 @@ var SwellTheme3 = class {
19622
19637
  async preloadThemeConfigs(version, configs) {
19623
19638
  await this.themeLoader.preloadTheme(version, configs);
19624
19639
  }
19625
- getPageConfigPath(pageId) {
19640
+ getPageConfigPath(pageId, altTemplate) {
19626
19641
  if (this.shopifyCompatibility) {
19627
19642
  const configPath = this.shopifyCompatibility.getThemeFilePath(
19628
19643
  "templates",
19629
19644
  pageId
19630
19645
  );
19631
- return `theme/${configPath}.json`;
19646
+ return `${withSuffix(`theme/${configPath}`, altTemplate)}.json`;
19632
19647
  }
19633
- return `theme/templates/${pageId}.json`;
19648
+ return `${withSuffix(`theme/templates/${pageId}`, altTemplate)}.json`;
19634
19649
  }
19635
19650
  async getThemeConfig(filePath) {
19636
19651
  if (this.themeConfigs !== null) {
@@ -19659,12 +19674,11 @@ var SwellTheme3 = class {
19659
19674
  }
19660
19675
  return this.getThemeConfig(`${filePath}.liquid`);
19661
19676
  }
19662
- async getThemeTemplateConfigByType(type, name) {
19663
- const templatesByPriority = [`${type}/${name}`];
19677
+ async getThemeTemplateConfigByType(type, name, suffix) {
19678
+ const templatesByPriority = [withSuffix(`${type}/${name}`, suffix)];
19664
19679
  if (this.shopifyCompatibility) {
19665
- templatesByPriority.push(
19666
- this.shopifyCompatibility.getThemeFilePath(type, name)
19667
- );
19680
+ const path = this.shopifyCompatibility.getThemeFilePath(type, name);
19681
+ templatesByPriority.push(withSuffix(path, suffix));
19668
19682
  }
19669
19683
  for (const filePath of templatesByPriority) {
19670
19684
  const templateConfig = await this.getThemeTemplateConfig(
@@ -19833,7 +19847,8 @@ ${content.slice(pos)}`;
19833
19847
  if (altTemplateId) {
19834
19848
  templateConfig = await this.getThemeTemplateConfigByType(
19835
19849
  "templates",
19836
- `${name}.${altTemplateId}`
19850
+ name,
19851
+ altTemplateId
19837
19852
  );
19838
19853
  }
19839
19854
  if (!templateConfig) {
@@ -20130,10 +20145,11 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
20130
20145
  /**
20131
20146
  * Get a list of sections and section groups in a page layout.
20132
20147
  */
20133
- async getPageSectionGroups(pageId) {
20148
+ async getPageSectionGroups(pageId, altTemplate) {
20134
20149
  const pageConfig = await this.getThemeTemplateConfigByType(
20135
20150
  "templates",
20136
- pageId
20151
+ pageId,
20152
+ altTemplate
20137
20153
  );
20138
20154
  if (pageConfig === null) {
20139
20155
  return [];
@@ -20450,6 +20466,9 @@ function extractSchemaTag(template) {
20450
20466
  }
20451
20467
  return list[0];
20452
20468
  }
20469
+ function withSuffix(path, suffix) {
20470
+ return suffix ? `${path}.${suffix}` : path;
20471
+ }
20453
20472
 
20454
20473
  // src/menus.ts
20455
20474
  async function resolveMenuSettings(theme, menus, options) {