@swell/apps-sdk 1.0.128 → 1.0.130
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 +261 -230
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +259 -218
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +260 -224
- package/dist/index.mjs.map +4 -4
- package/dist/src/api.d.ts +1 -0
- package/dist/src/compatibility/shopify-objects/product.d.ts +1 -2
- package/dist/src/easyblocks/config.d.ts +1 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/resources/account.d.ts +6 -0
- package/dist/src/resources/blog.d.ts +6 -0
- package/dist/src/resources/blog_category.d.ts +6 -0
- package/dist/src/resources/cart.d.ts +6 -0
- package/dist/src/resources/category.d.ts +6 -0
- package/dist/src/resources/order.d.ts +6 -0
- package/dist/src/resources/page.d.ts +6 -0
- package/dist/src/resources/product.d.ts +8 -0
- package/dist/src/resources/product_helpers.d.ts +7 -0
- package/dist/src/resources/swell_types.d.ts +25 -0
- package/dist/src/resources/variant.d.ts +9 -0
- package/dist/src/resources.d.ts +2 -0
- package/dist/src/theme.d.ts +7 -7
- package/dist/types/swell.d.ts +1 -0
- package/package.json +1 -1
- package/dist/src/categories.d.ts +0 -5
- package/dist/src/products.d.ts +0 -9
package/dist/index.cjs
CHANGED
|
@@ -67,6 +67,7 @@ __export(index_exports, {
|
|
|
67
67
|
Swell: () => Swell,
|
|
68
68
|
SwellBackendAPI: () => SwellBackendAPI,
|
|
69
69
|
SwellError: () => SwellError,
|
|
70
|
+
SwellProduct: () => SwellProduct,
|
|
70
71
|
SwellStorefrontCollection: () => SwellStorefrontCollection,
|
|
71
72
|
SwellStorefrontPagination: () => SwellStorefrontPagination,
|
|
72
73
|
SwellStorefrontRecord: () => SwellStorefrontRecord,
|
|
@@ -93,9 +94,6 @@ __export(index_exports, {
|
|
|
93
94
|
getAllSections: () => getAllSections,
|
|
94
95
|
getBlog: () => getBlog,
|
|
95
96
|
getBlogs: () => getBlogs,
|
|
96
|
-
getCategories: () => getCategories,
|
|
97
|
-
getCategory: () => getCategory,
|
|
98
|
-
getCategoryWithProducts: () => getCategoryWithProducts,
|
|
99
97
|
getContentEntry: () => getContentEntry,
|
|
100
98
|
getContentList: () => getContentList,
|
|
101
99
|
getContentModel: () => getContentModel,
|
|
@@ -112,9 +110,6 @@ __export(index_exports, {
|
|
|
112
110
|
getMenuItemValueId: () => getMenuItemValueId,
|
|
113
111
|
getPage: () => getPage,
|
|
114
112
|
getPageSections: () => getPageSections,
|
|
115
|
-
getProduct: () => getProduct,
|
|
116
|
-
getProducts: () => getProducts,
|
|
117
|
-
getProductsFiltered: () => getProductsFiltered,
|
|
118
113
|
getSectionGroupProp: () => getSectionGroupProp,
|
|
119
114
|
getSectionSettingsFromProps: () => getSectionSettingsFromProps,
|
|
120
115
|
getThemeSettingsFromProps: () => getThemeSettingsFromProps,
|
|
@@ -639,12 +634,18 @@ var StorefrontResource = class {
|
|
|
639
634
|
}
|
|
640
635
|
return instance[prop];
|
|
641
636
|
}
|
|
637
|
+
// add additional properties to the loaded result
|
|
638
|
+
_transformResult(result) {
|
|
639
|
+
return result;
|
|
640
|
+
}
|
|
642
641
|
async _get(..._args) {
|
|
643
642
|
if (this._getter) {
|
|
644
643
|
const getter = this._getter.bind(
|
|
645
644
|
this
|
|
646
645
|
);
|
|
647
646
|
return Promise.resolve().then(getter).then((result) => {
|
|
647
|
+
return this._transformResult(result);
|
|
648
|
+
}).then((result) => {
|
|
648
649
|
this._result = result;
|
|
649
650
|
if (result) {
|
|
650
651
|
Object.assign(this, result);
|
|
@@ -720,6 +721,8 @@ var StorefrontResource = class {
|
|
|
720
721
|
function cloneStorefrontResource(input) {
|
|
721
722
|
const resourceName = input._resourceName;
|
|
722
723
|
const clone = new StorefrontResource(input._getter);
|
|
724
|
+
clone._params = input._params;
|
|
725
|
+
clone._transformResult = input._transformResult.bind(clone);
|
|
723
726
|
Object.defineProperty(clone.constructor, "name", {
|
|
724
727
|
value: resourceName
|
|
725
728
|
});
|
|
@@ -890,10 +893,12 @@ var SwellStorefrontCollection = class _SwellStorefrontCollection extends SwellSt
|
|
|
890
893
|
};
|
|
891
894
|
var SwellStorefrontRecord = class extends SwellStorefrontResource {
|
|
892
895
|
_id;
|
|
896
|
+
_params;
|
|
893
897
|
constructor(swell, collection, id, query = {}, getter) {
|
|
894
898
|
super(swell, collection, getter);
|
|
895
899
|
this._id = id;
|
|
896
900
|
this._query = query;
|
|
901
|
+
this._params = {};
|
|
897
902
|
if (!getter) {
|
|
898
903
|
this._setGetter(this._defaultGetter());
|
|
899
904
|
}
|
|
@@ -931,6 +936,8 @@ var SwellStorefrontRecord = class extends SwellStorefrontResource {
|
|
|
931
936
|
],
|
|
932
937
|
getter
|
|
933
938
|
).then((result) => {
|
|
939
|
+
return this._transformResult(result);
|
|
940
|
+
}).then((result) => {
|
|
934
941
|
this._result = result;
|
|
935
942
|
if (result) {
|
|
936
943
|
Object.assign(this, result);
|
|
@@ -7171,6 +7178,169 @@ var ThemeCache = class extends Cache {
|
|
|
7171
7178
|
}
|
|
7172
7179
|
};
|
|
7173
7180
|
|
|
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
|
+
function getAvailableVariants(product) {
|
|
7228
|
+
return (product.variants?.results?.slice()?.reverse() || []).filter(
|
|
7229
|
+
(variant) => variant.stock_status === "in_stock" || !variant.stock_status
|
|
7230
|
+
);
|
|
7231
|
+
}
|
|
7232
|
+
function getSelectedSwellVariant(product, queryParams) {
|
|
7233
|
+
const { variant: queryVariant, option_values } = queryParams;
|
|
7234
|
+
const queryOptionValues = option_values;
|
|
7235
|
+
const variants = getAvailableVariants(product);
|
|
7236
|
+
let selectedVariant = void 0;
|
|
7237
|
+
if (queryVariant) {
|
|
7238
|
+
selectedVariant = variants.find((variant) => variant.id === queryVariant);
|
|
7239
|
+
} else if (queryOptionValues) {
|
|
7240
|
+
const optionValues = queryOptionValues.split(",");
|
|
7241
|
+
selectedVariant = variants.find(
|
|
7242
|
+
(variant) => variant.option_value_ids.every(
|
|
7243
|
+
(optionValueId) => optionValues.includes(optionValueId)
|
|
7244
|
+
)
|
|
7245
|
+
);
|
|
7246
|
+
}
|
|
7247
|
+
return selectedVariant || variants?.[0] || void 0;
|
|
7248
|
+
}
|
|
7249
|
+
function getSelectedVariant(product, queryParams) {
|
|
7250
|
+
return getSelectedSwellVariant(
|
|
7251
|
+
product,
|
|
7252
|
+
queryParams
|
|
7253
|
+
);
|
|
7254
|
+
}
|
|
7255
|
+
function getSelectedOptionValues(product, queryParams) {
|
|
7256
|
+
const variant = getSelectedSwellVariant(product, queryParams);
|
|
7257
|
+
return getSelectedVariantOptionValues(product, variant, queryParams);
|
|
7258
|
+
}
|
|
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
|
+
}
|
|
7282
|
+
}
|
|
7283
|
+
return values;
|
|
7284
|
+
}
|
|
7285
|
+
|
|
7286
|
+
// src/resources/variant.ts
|
|
7287
|
+
function transformSwellVariant(params, product, variant) {
|
|
7288
|
+
if (!product) {
|
|
7289
|
+
return product;
|
|
7290
|
+
}
|
|
7291
|
+
if (!variant) {
|
|
7292
|
+
return variant;
|
|
7293
|
+
}
|
|
7294
|
+
return {
|
|
7295
|
+
...variant,
|
|
7296
|
+
// add swell properties there
|
|
7297
|
+
price: calculateAddOptionsVariantPrice(product, variant, params),
|
|
7298
|
+
selected_option_values: getSelectedVariantOptionValues(
|
|
7299
|
+
product,
|
|
7300
|
+
variant,
|
|
7301
|
+
params
|
|
7302
|
+
)
|
|
7303
|
+
};
|
|
7304
|
+
}
|
|
7305
|
+
|
|
7306
|
+
// src/resources/product.ts
|
|
7307
|
+
function transformSwellProduct(params, product) {
|
|
7308
|
+
if (!product) {
|
|
7309
|
+
return product;
|
|
7310
|
+
}
|
|
7311
|
+
const newProduct = {
|
|
7312
|
+
...product,
|
|
7313
|
+
// add swell properties there
|
|
7314
|
+
price: calculateAddOptionsPrice(product, params),
|
|
7315
|
+
selected_option_values: getSelectedOptionValues(product, params)
|
|
7316
|
+
};
|
|
7317
|
+
if (Array.isArray(newProduct.variants?.results)) {
|
|
7318
|
+
newProduct.variants = {
|
|
7319
|
+
...newProduct.variants,
|
|
7320
|
+
results: newProduct.variants.results.map(
|
|
7321
|
+
(variant) => transformSwellVariant(params, product, variant)
|
|
7322
|
+
)
|
|
7323
|
+
};
|
|
7324
|
+
}
|
|
7325
|
+
return newProduct;
|
|
7326
|
+
}
|
|
7327
|
+
var SwellProduct = class extends SwellStorefrontRecord {
|
|
7328
|
+
_params;
|
|
7329
|
+
constructor(swell, id, query = {}, getter) {
|
|
7330
|
+
super(swell, "products", id, query, getter);
|
|
7331
|
+
this._params = swell.queryParams;
|
|
7332
|
+
return this._getProxy();
|
|
7333
|
+
}
|
|
7334
|
+
// add swell properties to the resolved object
|
|
7335
|
+
_transformResult(result) {
|
|
7336
|
+
const res = transformSwellProduct(
|
|
7337
|
+
this._params,
|
|
7338
|
+
result
|
|
7339
|
+
);
|
|
7340
|
+
return res;
|
|
7341
|
+
}
|
|
7342
|
+
};
|
|
7343
|
+
|
|
7174
7344
|
// src/api.ts
|
|
7175
7345
|
var DEFAULT_API_HOST = "https://api.schema.io";
|
|
7176
7346
|
var resourceCaches = /* @__PURE__ */ new Map();
|
|
@@ -7606,39 +7776,6 @@ ${formattedMessage}`;
|
|
|
7606
7776
|
}
|
|
7607
7777
|
};
|
|
7608
7778
|
|
|
7609
|
-
// src/products.ts
|
|
7610
|
-
function getProducts(swell, query) {
|
|
7611
|
-
return new SwellStorefrontCollection(swell, "products", query);
|
|
7612
|
-
}
|
|
7613
|
-
function getProduct(swell, id, query) {
|
|
7614
|
-
return new SwellStorefrontRecord(swell, "products", id, query);
|
|
7615
|
-
}
|
|
7616
|
-
function getProductsFiltered(swell, {
|
|
7617
|
-
search,
|
|
7618
|
-
filter,
|
|
7619
|
-
sort
|
|
7620
|
-
}) {
|
|
7621
|
-
return new SwellStorefrontCollection(swell, "products", {
|
|
7622
|
-
search,
|
|
7623
|
-
filter,
|
|
7624
|
-
sort
|
|
7625
|
-
});
|
|
7626
|
-
}
|
|
7627
|
-
|
|
7628
|
-
// src/categories.ts
|
|
7629
|
-
function getCategories(swell, query) {
|
|
7630
|
-
return new SwellStorefrontCollection(swell, "categories", query);
|
|
7631
|
-
}
|
|
7632
|
-
function getCategory(swell, id, query) {
|
|
7633
|
-
return new SwellStorefrontRecord(swell, "categories", id, query);
|
|
7634
|
-
}
|
|
7635
|
-
async function getCategoryWithProducts(swell, id, query) {
|
|
7636
|
-
const category = getCategory(swell, id, query);
|
|
7637
|
-
const categoryId = await category.id;
|
|
7638
|
-
category.products = getProducts(swell, { category: categoryId });
|
|
7639
|
-
return category;
|
|
7640
|
-
}
|
|
7641
|
-
|
|
7642
7779
|
// src/content.ts
|
|
7643
7780
|
function getContentModel(swell, name) {
|
|
7644
7781
|
return swell.getCachedResource(
|
|
@@ -7671,11 +7808,12 @@ async function getBlog(swell, id, query) {
|
|
|
7671
7808
|
var import_json53 = __toESM(require("json5"), 1);
|
|
7672
7809
|
var import_lodash_es4 = require("lodash-es");
|
|
7673
7810
|
var NO_INLINE = true;
|
|
7674
|
-
async function getEasyblocksPageTemplate(theme, pageId) {
|
|
7811
|
+
async function getEasyblocksPageTemplate(theme, pageId, altTemplate) {
|
|
7675
7812
|
let templateConfig = null;
|
|
7676
7813
|
templateConfig = await theme.getThemeTemplateConfigByType(
|
|
7677
7814
|
"templates",
|
|
7678
|
-
pageId
|
|
7815
|
+
pageId,
|
|
7816
|
+
altTemplate
|
|
7679
7817
|
);
|
|
7680
7818
|
if (templateConfig) {
|
|
7681
7819
|
if (templateConfig.file_path.endsWith(".liquid")) {
|
|
@@ -13729,8 +13867,7 @@ function ShopifyArticle(instance, blog, blogCategory) {
|
|
|
13729
13867
|
(blog2) => blog2.date_published || blog2.date_created
|
|
13730
13868
|
),
|
|
13731
13869
|
tags: defer(() => blog.tags),
|
|
13732
|
-
template_suffix:
|
|
13733
|
-
// TODO
|
|
13870
|
+
template_suffix: defer(() => blog.theme_template),
|
|
13734
13871
|
title: defer(() => blog.title),
|
|
13735
13872
|
updated_at: deferWith(
|
|
13736
13873
|
blog,
|
|
@@ -13799,8 +13936,7 @@ function ShopifyBlog(instance, blogCategory) {
|
|
|
13799
13936
|
// TODO
|
|
13800
13937
|
tags: allTags,
|
|
13801
13938
|
// TODO: this should only apply to articles in the current view
|
|
13802
|
-
template_suffix:
|
|
13803
|
-
// TODO
|
|
13939
|
+
template_suffix: defer(() => blogCategory.theme_template),
|
|
13804
13940
|
title: defer(() => blogCategory.title),
|
|
13805
13941
|
url: deferWith(
|
|
13806
13942
|
blogCategory,
|
|
@@ -13831,11 +13967,15 @@ function ShopifyVariant(instance, variant, productIn, depth = 0) {
|
|
|
13831
13967
|
if (variant instanceof ShopifyResource) {
|
|
13832
13968
|
return variant.clone();
|
|
13833
13969
|
}
|
|
13970
|
+
let swellVariant = {};
|
|
13834
13971
|
if (variant instanceof StorefrontResource) {
|
|
13835
13972
|
variant = cloneStorefrontResource(variant);
|
|
13973
|
+
} else {
|
|
13974
|
+
swellVariant = { ...variant };
|
|
13836
13975
|
}
|
|
13837
13976
|
const product = productIn || variant.product || {};
|
|
13838
13977
|
return new ShopifyResource({
|
|
13978
|
+
...swellVariant,
|
|
13839
13979
|
available: deferWith(
|
|
13840
13980
|
variant,
|
|
13841
13981
|
(variant2) => Boolean(variant2.stock_status === "in_stock" || !variant2.stock_status)
|
|
@@ -13881,25 +14021,19 @@ function ShopifyVariant(instance, variant, productIn, depth = 0) {
|
|
|
13881
14021
|
metafields: {},
|
|
13882
14022
|
next_incoming_date: void 0,
|
|
13883
14023
|
options: getOptions(product, variant),
|
|
13884
|
-
// @ts-expect-error: move this to swell product class
|
|
13885
|
-
selected_option_values: deferWith(
|
|
13886
|
-
[product, variant],
|
|
13887
|
-
(product2, variant2) => getSelectedVariantOptionValues(
|
|
13888
|
-
product2,
|
|
13889
|
-
variant2,
|
|
13890
|
-
instance.swell.queryParams
|
|
13891
|
-
)
|
|
13892
|
-
),
|
|
13893
14024
|
option1: getOptionByIndex(product, variant, 0),
|
|
13894
14025
|
// Deprecated by Shopify
|
|
13895
14026
|
option2: getOptionByIndex(product, variant, 1),
|
|
13896
14027
|
// Deprecated by Shopify
|
|
13897
14028
|
option3: getOptionByIndex(product, variant, 2),
|
|
13898
14029
|
// Deprecated by Shopify
|
|
13899
|
-
price: deferWith(
|
|
13900
|
-
|
|
13901
|
-
(
|
|
13902
|
-
|
|
14030
|
+
price: deferWith([product, variant], (product2, variant2) => {
|
|
14031
|
+
let price = product2.price;
|
|
14032
|
+
if (variant2.price !== null && variant2.price !== void 0) {
|
|
14033
|
+
price = variant2.price;
|
|
14034
|
+
}
|
|
14035
|
+
return price;
|
|
14036
|
+
}),
|
|
13903
14037
|
product: deferWith(product, (product2) => {
|
|
13904
14038
|
return ShopifyProduct(
|
|
13905
14039
|
instance,
|
|
@@ -13986,30 +14120,6 @@ function getOptionByIndex(product, variant, index) {
|
|
|
13986
14120
|
}
|
|
13987
14121
|
);
|
|
13988
14122
|
}
|
|
13989
|
-
function getVariantPrice(product, variant, queryParams) {
|
|
13990
|
-
const { option_values: queryOptionValues = "" } = queryParams;
|
|
13991
|
-
const optionValues = queryOptionValues.split(",");
|
|
13992
|
-
const addPrice = product.options?.reduce((acc, option) => {
|
|
13993
|
-
if (option.variant || // skip variant options
|
|
13994
|
-
!option.active || !option.values || option.values.length <= 0) {
|
|
13995
|
-
return acc;
|
|
13996
|
-
}
|
|
13997
|
-
if (option.input_type !== "select") {
|
|
13998
|
-
return acc;
|
|
13999
|
-
}
|
|
14000
|
-
for (const value of option.values) {
|
|
14001
|
-
if (optionValues.includes(value.id)) {
|
|
14002
|
-
return acc + (value.price || 0);
|
|
14003
|
-
}
|
|
14004
|
-
}
|
|
14005
|
-
return acc + (option.values[0].price || 0);
|
|
14006
|
-
}, 0);
|
|
14007
|
-
let price = product.price;
|
|
14008
|
-
if (variant.price !== null && variant.price !== void 0) {
|
|
14009
|
-
price = variant.price;
|
|
14010
|
-
}
|
|
14011
|
-
return price + (addPrice || 0);
|
|
14012
|
-
}
|
|
14013
14123
|
|
|
14014
14124
|
// src/compatibility/shopify-objects/product.ts
|
|
14015
14125
|
function ShopifyProduct(instance, product, depth = 0) {
|
|
@@ -14085,12 +14195,6 @@ function ShopifyProduct(instance, product, depth = 0) {
|
|
|
14085
14195
|
}
|
|
14086
14196
|
return product2.options.filter((option) => option.active && option.name).map((option) => option.name);
|
|
14087
14197
|
}),
|
|
14088
|
-
// all options values including non-variant
|
|
14089
|
-
// @ts-expect-error: move this to swell product class
|
|
14090
|
-
selected_option_values: deferWith(
|
|
14091
|
-
product,
|
|
14092
|
-
(product2) => getSelectedOptionValues(product2, instance.swell.queryParams)
|
|
14093
|
-
),
|
|
14094
14198
|
options_by_name: deferWith(product, (product2) => {
|
|
14095
14199
|
if (!Array.isArray(product2.options)) {
|
|
14096
14200
|
return {};
|
|
@@ -14158,10 +14262,7 @@ function ShopifyProduct(instance, product, depth = 0) {
|
|
|
14158
14262
|
});
|
|
14159
14263
|
}
|
|
14160
14264
|
),
|
|
14161
|
-
price: deferWith(
|
|
14162
|
-
product,
|
|
14163
|
-
(product2) => calculateAddOptionsPrice(product2, instance.swell.queryParams)
|
|
14164
|
-
),
|
|
14265
|
+
price: deferWith(product, (product2) => product2.price),
|
|
14165
14266
|
price_max: deferWith(product, (product2) => {
|
|
14166
14267
|
if (!Array.isArray(product2.variants?.results)) {
|
|
14167
14268
|
return product2.price;
|
|
@@ -14196,6 +14297,8 @@ function ShopifyProduct(instance, product, depth = 0) {
|
|
|
14196
14297
|
product,
|
|
14197
14298
|
(product2) => product2.prices?.length > 0
|
|
14198
14299
|
),
|
|
14300
|
+
// ShopifyProduct does not have this property
|
|
14301
|
+
// @ts-expect-error property
|
|
14199
14302
|
quantity_rule: deferWith(product, (product2) => {
|
|
14200
14303
|
let inventory = product2.stock_level || 0;
|
|
14201
14304
|
if (inventory < 0) {
|
|
@@ -14231,7 +14334,7 @@ function ShopifyProduct(instance, product, depth = 0) {
|
|
|
14231
14334
|
selected_variant: void 0,
|
|
14232
14335
|
selling_plan_groups: [],
|
|
14233
14336
|
tags: defer(() => product.tags),
|
|
14234
|
-
template_suffix:
|
|
14337
|
+
template_suffix: defer(() => product.theme_template),
|
|
14235
14338
|
title: defer(() => product.name),
|
|
14236
14339
|
type: defer(() => product.type),
|
|
14237
14340
|
url: deferWith(product, (product2) => `/products/${product2.slug}`),
|
|
@@ -14254,77 +14357,6 @@ function ShopifyProduct(instance, product, depth = 0) {
|
|
|
14254
14357
|
function ShopifyProductOptionValue(values) {
|
|
14255
14358
|
return new ShopifyResource(values, "name");
|
|
14256
14359
|
}
|
|
14257
|
-
function getSelectedVariant(product, queryParams) {
|
|
14258
|
-
const { variant: queryVariant, option_values: queryOptionValues } = queryParams;
|
|
14259
|
-
const variants = getAvailableVariants(product);
|
|
14260
|
-
let selectedVariant = void 0;
|
|
14261
|
-
if (queryVariant) {
|
|
14262
|
-
selectedVariant = variants.find(
|
|
14263
|
-
(variant) => variant.id === queryVariant
|
|
14264
|
-
);
|
|
14265
|
-
} else if (queryOptionValues) {
|
|
14266
|
-
const optionValues = queryOptionValues.split(",");
|
|
14267
|
-
selectedVariant = variants.find(
|
|
14268
|
-
(variant) => variant.option_value_ids.every(
|
|
14269
|
-
(optionValueId) => optionValues.includes(optionValueId)
|
|
14270
|
-
)
|
|
14271
|
-
);
|
|
14272
|
-
}
|
|
14273
|
-
return selectedVariant || variants?.[0] || void 0;
|
|
14274
|
-
}
|
|
14275
|
-
function getAvailableVariants(product) {
|
|
14276
|
-
return (product.variants?.results?.slice()?.reverse() || []).filter(
|
|
14277
|
-
(variant) => variant.stock_status === "in_stock" || !variant.stock_status
|
|
14278
|
-
);
|
|
14279
|
-
}
|
|
14280
|
-
function calculateAddOptionsPrice(product, queryParams) {
|
|
14281
|
-
const { option_values: queryOptionValues = "" } = queryParams;
|
|
14282
|
-
const optionValues = queryOptionValues.split(",");
|
|
14283
|
-
const addPrice = product.options?.reduce((acc, option) => {
|
|
14284
|
-
if (!option.active || !option.values || option.values.length <= 0) {
|
|
14285
|
-
return acc;
|
|
14286
|
-
}
|
|
14287
|
-
if (option.input_type !== "select") {
|
|
14288
|
-
return acc;
|
|
14289
|
-
}
|
|
14290
|
-
for (const value of option.values) {
|
|
14291
|
-
if (optionValues.includes(value.id)) {
|
|
14292
|
-
return acc + (value.price || 0);
|
|
14293
|
-
}
|
|
14294
|
-
}
|
|
14295
|
-
return acc + (option.values[0].price || 0);
|
|
14296
|
-
}, 0);
|
|
14297
|
-
return product.price + (addPrice || 0);
|
|
14298
|
-
}
|
|
14299
|
-
function getSelectedOptionValues(product, queryParams) {
|
|
14300
|
-
const variant = getSelectedVariant(product, queryParams);
|
|
14301
|
-
return getSelectedVariantOptionValues(product, variant, queryParams);
|
|
14302
|
-
}
|
|
14303
|
-
function getSelectedVariantOptionValues(product, variant, queryParams) {
|
|
14304
|
-
const { option_values: queryOptionValues = "" } = queryParams;
|
|
14305
|
-
const optionValues = queryOptionValues.split(",");
|
|
14306
|
-
const selectedValues = variant ? [...variant.option_value_ids || []] : [];
|
|
14307
|
-
const values = [];
|
|
14308
|
-
for (const option of product.options || []) {
|
|
14309
|
-
if (option.active && option.values?.length > 0 && option.input_type === "select") {
|
|
14310
|
-
let selectedByVariantId = "";
|
|
14311
|
-
let selectedByOptionId = "";
|
|
14312
|
-
for (const value of option.values) {
|
|
14313
|
-
if (selectedValues.includes(value.id)) {
|
|
14314
|
-
selectedByVariantId = value.id;
|
|
14315
|
-
break;
|
|
14316
|
-
}
|
|
14317
|
-
if (optionValues.includes(value.id)) {
|
|
14318
|
-
selectedByOptionId = value.id;
|
|
14319
|
-
}
|
|
14320
|
-
}
|
|
14321
|
-
values.push(
|
|
14322
|
-
selectedByVariantId || selectedByOptionId || option.values[0].id
|
|
14323
|
-
);
|
|
14324
|
-
}
|
|
14325
|
-
}
|
|
14326
|
-
return values;
|
|
14327
|
-
}
|
|
14328
14360
|
function isLikeShopifyProduct(value) {
|
|
14329
14361
|
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");
|
|
14330
14362
|
}
|
|
@@ -14814,7 +14846,7 @@ function ShopifyCollection(instance, category) {
|
|
|
14814
14846
|
sort_by: defer(() => category.sort),
|
|
14815
14847
|
sort_options: defer(() => category.sort_options),
|
|
14816
14848
|
tags: [],
|
|
14817
|
-
template_suffix:
|
|
14849
|
+
template_suffix: defer(() => category.theme_template),
|
|
14818
14850
|
title: defer(() => category.name),
|
|
14819
14851
|
url: deferWith(category, (category2) => `/collections/${category2.slug}`)
|
|
14820
14852
|
});
|
|
@@ -15615,8 +15647,7 @@ function ShopifyPage(_instance, page) {
|
|
|
15615
15647
|
page,
|
|
15616
15648
|
(page2) => page2.date_published || page2.date_created
|
|
15617
15649
|
),
|
|
15618
|
-
template_suffix:
|
|
15619
|
-
// TODO
|
|
15650
|
+
template_suffix: defer(() => page.theme_template),
|
|
15620
15651
|
title: deferWith(page, (page2) => page2.title || page2.name),
|
|
15621
15652
|
// Due to deprecated name field
|
|
15622
15653
|
url: deferWith(page, (page2) => `/pages/${page2.slug}`)
|
|
@@ -15952,17 +15983,13 @@ var ShopifyCompatibility3 = class {
|
|
|
15952
15983
|
this.queryParamsMap = this.getQueryParamsMap();
|
|
15953
15984
|
}
|
|
15954
15985
|
initGlobals(globals) {
|
|
15955
|
-
const { request
|
|
15956
|
-
this.pageId = this.getPageType(globals.page?.id);
|
|
15957
|
-
globals.page = {
|
|
15958
|
-
...page || void 0
|
|
15959
|
-
};
|
|
15986
|
+
const { request } = globals;
|
|
15960
15987
|
globals.request = {
|
|
15961
15988
|
...request || void 0,
|
|
15962
15989
|
design_mode: this.swell.isEditor,
|
|
15963
15990
|
visual_section_preview: false,
|
|
15964
15991
|
// TODO: Add support for visual section preview
|
|
15965
|
-
page_type:
|
|
15992
|
+
page_type: ""
|
|
15966
15993
|
};
|
|
15967
15994
|
globals.collections = new CollectionsDrop(this);
|
|
15968
15995
|
globals.current_page = this.swell.queryParams.page || 1;
|
|
@@ -15971,6 +15998,8 @@ var ShopifyCompatibility3 = class {
|
|
|
15971
15998
|
adaptGlobals(globals, prevGlobals) {
|
|
15972
15999
|
if (globals.page) {
|
|
15973
16000
|
this.pageId = this.getPageType(globals.page.id);
|
|
16001
|
+
const request = globals.request || prevGlobals.request;
|
|
16002
|
+
request.page_type = globals.page.id;
|
|
15974
16003
|
}
|
|
15975
16004
|
if (globals.request) {
|
|
15976
16005
|
const page = globals.page || prevGlobals.page;
|
|
@@ -19049,12 +19078,10 @@ var SwellTheme3 = class {
|
|
|
19049
19078
|
getSwellAppThemeProps(swellConfig) {
|
|
19050
19079
|
return swellConfig?.storefront?.theme || {};
|
|
19051
19080
|
}
|
|
19052
|
-
async initGlobals(
|
|
19053
|
-
this.pageId = pageId;
|
|
19081
|
+
async initGlobals() {
|
|
19054
19082
|
await this.themeLoader.init(this.themeConfigs || void 0);
|
|
19055
19083
|
const { store, session, menus, geo, configs } = await this.getSettingsAndConfigs();
|
|
19056
|
-
const { settings, request,
|
|
19057
|
-
this.page = page;
|
|
19084
|
+
const { settings, request, cart, account, customer } = await this.resolvePageData(store, configs);
|
|
19058
19085
|
const globals = {
|
|
19059
19086
|
...this.globalData,
|
|
19060
19087
|
store,
|
|
@@ -19062,7 +19089,7 @@ var SwellTheme3 = class {
|
|
|
19062
19089
|
session,
|
|
19063
19090
|
request,
|
|
19064
19091
|
menus,
|
|
19065
|
-
page,
|
|
19092
|
+
page: {},
|
|
19066
19093
|
cart,
|
|
19067
19094
|
account,
|
|
19068
19095
|
customer,
|
|
@@ -19093,6 +19120,45 @@ var SwellTheme3 = class {
|
|
|
19093
19120
|
...this.globals
|
|
19094
19121
|
};
|
|
19095
19122
|
}
|
|
19123
|
+
async initPageGlobals(pageId, altTemplate) {
|
|
19124
|
+
this.pageId = pageId;
|
|
19125
|
+
const swellPage = this.props.pages?.find(
|
|
19126
|
+
(page2) => page2.id === pageId
|
|
19127
|
+
);
|
|
19128
|
+
const page = {
|
|
19129
|
+
...swellPage,
|
|
19130
|
+
current: Number(this.swell.queryParams.page) || 1,
|
|
19131
|
+
url: this.swell.url.pathname,
|
|
19132
|
+
custom: !swellPage,
|
|
19133
|
+
slug: void 0,
|
|
19134
|
+
description: void 0,
|
|
19135
|
+
$locale: void 0
|
|
19136
|
+
};
|
|
19137
|
+
if (pageId) {
|
|
19138
|
+
const templateConfig = await this.getThemeTemplateConfigByType(
|
|
19139
|
+
"templates",
|
|
19140
|
+
pageId,
|
|
19141
|
+
altTemplate
|
|
19142
|
+
);
|
|
19143
|
+
let pageSchema;
|
|
19144
|
+
try {
|
|
19145
|
+
pageSchema = import_json56.default.parse(
|
|
19146
|
+
templateConfig?.file_data || "{}"
|
|
19147
|
+
);
|
|
19148
|
+
} catch (err) {
|
|
19149
|
+
console.warn(err);
|
|
19150
|
+
}
|
|
19151
|
+
if (pageSchema?.page) {
|
|
19152
|
+
const { slug, label, description, $locale } = pageSchema.page;
|
|
19153
|
+
page.slug = slug;
|
|
19154
|
+
page.label = label || page.label;
|
|
19155
|
+
page.description = description;
|
|
19156
|
+
page.$locale = $locale;
|
|
19157
|
+
}
|
|
19158
|
+
}
|
|
19159
|
+
this.page = page;
|
|
19160
|
+
this.setGlobals({ page });
|
|
19161
|
+
}
|
|
19096
19162
|
async getSettingsAndConfigs() {
|
|
19097
19163
|
const geo = GEO_DATA;
|
|
19098
19164
|
const [storefrontSettings, settingConfigs] = await Promise.all([
|
|
@@ -19142,7 +19208,7 @@ var SwellTheme3 = class {
|
|
|
19142
19208
|
configs
|
|
19143
19209
|
};
|
|
19144
19210
|
}
|
|
19145
|
-
async resolvePageData(store, configs
|
|
19211
|
+
async resolvePageData(store, configs) {
|
|
19146
19212
|
const configVersion = String(
|
|
19147
19213
|
this.swell.swellHeaders["theme-config-version"]
|
|
19148
19214
|
);
|
|
@@ -19174,39 +19240,6 @@ var SwellTheme3 = class {
|
|
|
19174
19240
|
is_editor: this.swell.isEditor,
|
|
19175
19241
|
is_preview: this.swell.isPreview
|
|
19176
19242
|
};
|
|
19177
|
-
const swellPage = this.props.pages?.find(
|
|
19178
|
-
(page2) => page2.id === pageId
|
|
19179
|
-
);
|
|
19180
|
-
const page = {
|
|
19181
|
-
...swellPage,
|
|
19182
|
-
current: Number(this.swell.queryParams.page) || 1,
|
|
19183
|
-
url: this.swell.url.pathname,
|
|
19184
|
-
custom: !swellPage,
|
|
19185
|
-
slug: void 0,
|
|
19186
|
-
description: void 0,
|
|
19187
|
-
$locale: void 0
|
|
19188
|
-
};
|
|
19189
|
-
if (pageId) {
|
|
19190
|
-
const templateConfig = await this.getThemeTemplateConfigByType(
|
|
19191
|
-
"templates",
|
|
19192
|
-
pageId
|
|
19193
|
-
);
|
|
19194
|
-
let pageSchema;
|
|
19195
|
-
try {
|
|
19196
|
-
pageSchema = import_json56.default.parse(
|
|
19197
|
-
templateConfig?.file_data || "{}"
|
|
19198
|
-
);
|
|
19199
|
-
} catch (err) {
|
|
19200
|
-
console.warn(err);
|
|
19201
|
-
}
|
|
19202
|
-
if (pageSchema?.page) {
|
|
19203
|
-
const { slug, label, description, $locale } = pageSchema.page;
|
|
19204
|
-
page.slug = slug;
|
|
19205
|
-
page.label = label || page.label;
|
|
19206
|
-
page.description = description;
|
|
19207
|
-
page.$locale = $locale;
|
|
19208
|
-
}
|
|
19209
|
-
}
|
|
19210
19243
|
const [cart, account] = await Promise.all([
|
|
19211
19244
|
this.fetchSingletonResourceCached(
|
|
19212
19245
|
"cart",
|
|
@@ -19229,7 +19262,6 @@ var SwellTheme3 = class {
|
|
|
19229
19262
|
return {
|
|
19230
19263
|
settings,
|
|
19231
19264
|
request,
|
|
19232
|
-
page,
|
|
19233
19265
|
cart,
|
|
19234
19266
|
account,
|
|
19235
19267
|
customer
|
|
@@ -19589,15 +19621,15 @@ var SwellTheme3 = class {
|
|
|
19589
19621
|
async preloadThemeConfigs(version, configs) {
|
|
19590
19622
|
await this.themeLoader.preloadTheme(version, configs);
|
|
19591
19623
|
}
|
|
19592
|
-
getPageConfigPath(pageId) {
|
|
19624
|
+
getPageConfigPath(pageId, altTemplate) {
|
|
19593
19625
|
if (this.shopifyCompatibility) {
|
|
19594
19626
|
const configPath = this.shopifyCompatibility.getThemeFilePath(
|
|
19595
19627
|
"templates",
|
|
19596
19628
|
pageId
|
|
19597
19629
|
);
|
|
19598
|
-
return `theme/${configPath}.json`;
|
|
19630
|
+
return `${withSuffix(`theme/${configPath}`, altTemplate)}.json`;
|
|
19599
19631
|
}
|
|
19600
|
-
return `theme/templates/${pageId}.json`;
|
|
19632
|
+
return `${withSuffix(`theme/templates/${pageId}`, altTemplate)}.json`;
|
|
19601
19633
|
}
|
|
19602
19634
|
async getThemeConfig(filePath) {
|
|
19603
19635
|
if (this.themeConfigs !== null) {
|
|
@@ -19626,12 +19658,11 @@ var SwellTheme3 = class {
|
|
|
19626
19658
|
}
|
|
19627
19659
|
return this.getThemeConfig(`${filePath}.liquid`);
|
|
19628
19660
|
}
|
|
19629
|
-
async getThemeTemplateConfigByType(type, name) {
|
|
19630
|
-
const templatesByPriority = [`${type}/${name}
|
|
19661
|
+
async getThemeTemplateConfigByType(type, name, suffix) {
|
|
19662
|
+
const templatesByPriority = [withSuffix(`${type}/${name}`, suffix)];
|
|
19631
19663
|
if (this.shopifyCompatibility) {
|
|
19632
|
-
|
|
19633
|
-
|
|
19634
|
-
);
|
|
19664
|
+
const path = this.shopifyCompatibility.getThemeFilePath(type, name);
|
|
19665
|
+
templatesByPriority.push(withSuffix(path, suffix));
|
|
19635
19666
|
}
|
|
19636
19667
|
for (const filePath of templatesByPriority) {
|
|
19637
19668
|
const templateConfig = await this.getThemeTemplateConfig(
|
|
@@ -19800,7 +19831,8 @@ ${content.slice(pos)}`;
|
|
|
19800
19831
|
if (altTemplateId) {
|
|
19801
19832
|
templateConfig = await this.getThemeTemplateConfigByType(
|
|
19802
19833
|
"templates",
|
|
19803
|
-
|
|
19834
|
+
name,
|
|
19835
|
+
altTemplateId
|
|
19804
19836
|
);
|
|
19805
19837
|
}
|
|
19806
19838
|
if (!templateConfig) {
|
|
@@ -20097,10 +20129,11 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
|
|
|
20097
20129
|
/**
|
|
20098
20130
|
* Get a list of sections and section groups in a page layout.
|
|
20099
20131
|
*/
|
|
20100
|
-
async getPageSectionGroups(pageId) {
|
|
20132
|
+
async getPageSectionGroups(pageId, altTemplate) {
|
|
20101
20133
|
const pageConfig = await this.getThemeTemplateConfigByType(
|
|
20102
20134
|
"templates",
|
|
20103
|
-
pageId
|
|
20135
|
+
pageId,
|
|
20136
|
+
altTemplate
|
|
20104
20137
|
);
|
|
20105
20138
|
if (pageConfig === null) {
|
|
20106
20139
|
return [];
|
|
@@ -20417,6 +20450,9 @@ function extractSchemaTag(template) {
|
|
|
20417
20450
|
}
|
|
20418
20451
|
return list[0];
|
|
20419
20452
|
}
|
|
20453
|
+
function withSuffix(path, suffix) {
|
|
20454
|
+
return suffix ? `${path}.${suffix}` : path;
|
|
20455
|
+
}
|
|
20420
20456
|
|
|
20421
20457
|
// src/menus.ts
|
|
20422
20458
|
async function resolveMenuSettings(theme, menus, options) {
|
|
@@ -20843,6 +20879,7 @@ function getResourceQuery(slug, query) {
|
|
|
20843
20879
|
Swell,
|
|
20844
20880
|
SwellBackendAPI,
|
|
20845
20881
|
SwellError,
|
|
20882
|
+
SwellProduct,
|
|
20846
20883
|
SwellStorefrontCollection,
|
|
20847
20884
|
SwellStorefrontPagination,
|
|
20848
20885
|
SwellStorefrontRecord,
|
|
@@ -20869,9 +20906,6 @@ function getResourceQuery(slug, query) {
|
|
|
20869
20906
|
getAllSections,
|
|
20870
20907
|
getBlog,
|
|
20871
20908
|
getBlogs,
|
|
20872
|
-
getCategories,
|
|
20873
|
-
getCategory,
|
|
20874
|
-
getCategoryWithProducts,
|
|
20875
20909
|
getContentEntry,
|
|
20876
20910
|
getContentList,
|
|
20877
20911
|
getContentModel,
|
|
@@ -20888,9 +20922,6 @@ function getResourceQuery(slug, query) {
|
|
|
20888
20922
|
getMenuItemValueId,
|
|
20889
20923
|
getPage,
|
|
20890
20924
|
getPageSections,
|
|
20891
|
-
getProduct,
|
|
20892
|
-
getProducts,
|
|
20893
|
-
getProductsFiltered,
|
|
20894
20925
|
getSectionGroupProp,
|
|
20895
20926
|
getSectionSettingsFromProps,
|
|
20896
20927
|
getThemeSettingsFromProps,
|