@gem-sdk/core 1.14.0-next.96 → 1.14.0
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/cjs/components/AddOn.js +18 -1
- package/dist/cjs/components/ComponentWrapper.js +28 -1
- package/dist/cjs/components/ComponentWrapperPreview.js +72 -1
- package/dist/cjs/components/Empty.js +7 -1
- package/dist/cjs/components/Render.js +65 -1
- package/dist/cjs/components/Render.liquid.js +158 -3
- package/dist/cjs/components/RenderBlock.js +54 -1
- package/dist/cjs/components/RenderPreview.js +66 -1
- package/dist/cjs/components/RenderSection.js +23 -1
- package/dist/cjs/components/constant.js +39 -1
- package/dist/cjs/contexts/AddonContext.js +36 -1
- package/dist/cjs/contexts/BuilderComponent.js +34 -1
- package/dist/cjs/contexts/BuilderContext.js +35 -1
- package/dist/cjs/contexts/BuilderPreviewContext.js +370 -1
- package/dist/cjs/contexts/CartLineContext.js +29 -1
- package/dist/cjs/contexts/CollectionContext.js +38 -1
- package/dist/cjs/contexts/ModalContext.js +47 -1
- package/dist/cjs/contexts/ProductContext.js +149 -1
- package/dist/cjs/contexts/ProductListContext.js +32 -1
- package/dist/cjs/contexts/SectionContext.js +53 -1
- package/dist/cjs/contexts/ShopContext.js +70 -1
- package/dist/cjs/graphql/fragments/analytic.generated.js +6 -2
- package/dist/cjs/graphql/fragments/collection-detail.generated.js +6 -2
- package/dist/cjs/graphql/fragments/collection-product.generated.js +6 -2
- package/dist/cjs/graphql/fragments/collection.generated.js +6 -2
- package/dist/cjs/graphql/fragments/custom-code.generated.js +6 -2
- package/dist/cjs/graphql/fragments/data-seo.generated.js +6 -2
- package/dist/cjs/graphql/fragments/media.generated.js +6 -3
- package/dist/cjs/graphql/fragments/product-little.generated.js +6 -2
- package/dist/cjs/graphql/fragments/product-option-value.generated.js +6 -2
- package/dist/cjs/graphql/fragments/product-option.generated.js +6 -2
- package/dist/cjs/graphql/fragments/product.generated.js +6 -2
- package/dist/cjs/graphql/fragments/published-custom-section.generated.js +6 -2
- package/dist/cjs/graphql/fragments/published-page-section.generated.js +6 -2
- package/dist/cjs/graphql/fragments/published-theme-page.generated.js +6 -2
- package/dist/cjs/graphql/fragments/published-theme-style.generated.js +6 -2
- package/dist/cjs/graphql/fragments/selected-option.generated.js +6 -2
- package/dist/cjs/graphql/fragments/variant.generated.js +6 -2
- package/dist/cjs/graphql/mutations/page-view-up.generated.js +7 -3
- package/dist/cjs/graphql/queries/collection-detail-filter.generated.js +16 -2
- package/dist/cjs/graphql/queries/collection.generated.js +14 -2
- package/dist/cjs/graphql/queries/collections.generated.js +9 -2
- package/dist/cjs/graphql/queries/preview-page.generated.js +14 -2
- package/dist/cjs/graphql/queries/product-little-detail.generated.js +11 -2
- package/dist/cjs/graphql/queries/product-medias.generated.js +8 -2
- package/dist/cjs/graphql/queries/product-variants.generated.js +10 -2
- package/dist/cjs/graphql/queries/products.generated.js +17 -3
- package/dist/cjs/graphql/queries/published-theme-pages.generated.js +14 -2
- package/dist/cjs/graphql/queries/store-property.generated.js +6 -2
- package/dist/cjs/helpers/GlobalEvent.js +19 -1
- package/dist/cjs/helpers/background.js +109 -1
- package/dist/cjs/helpers/borders.js +183 -4
- package/dist/cjs/helpers/clone-deep.js +5 -1
- package/dist/cjs/helpers/cls.js +16 -1
- package/dist/cjs/helpers/colors.js +183 -1
- package/dist/cjs/helpers/compose-advance-style.js +188 -1
- package/dist/cjs/helpers/constant.js +23 -1
- package/dist/cjs/helpers/convert.js +7 -1
- package/dist/cjs/helpers/css-variable.js +7 -1
- package/dist/cjs/helpers/email.js +11 -1
- package/dist/cjs/helpers/flatten-connection.js +9 -1
- package/dist/cjs/helpers/get-resonsive-value.js +31 -1
- package/dist/cjs/helpers/get-shortname.js +92 -1
- package/dist/cjs/helpers/is-browser.js +9 -1
- package/dist/cjs/helpers/is-defined.js +7 -1
- package/dist/cjs/helpers/is-empty-children.js +12 -1
- package/dist/cjs/helpers/is-safari.js +9 -1
- package/dist/cjs/helpers/layout.js +59 -1
- package/dist/cjs/helpers/load-script.js +31 -1
- package/dist/cjs/helpers/make-style.js +128 -1
- package/dist/cjs/helpers/normalize-builder-data.js +23 -1
- package/dist/cjs/helpers/prefetch-queries.js +78 -1
- package/dist/cjs/helpers/product.js +45 -1
- package/dist/cjs/helpers/queries/get-collection.js +220 -1
- package/dist/cjs/helpers/queries/get-collections.js +21 -1
- package/dist/cjs/helpers/queries/get-product-by-slug.js +125 -1
- package/dist/cjs/helpers/queries/get-product.js +154 -1
- package/dist/cjs/helpers/queries/get-products.js +161 -1
- package/dist/cjs/helpers/query.js +29 -1
- package/dist/cjs/helpers/radius.js +131 -6
- package/dist/cjs/helpers/render.js +71 -1
- package/dist/cjs/helpers/shadow.js +56 -1
- package/dist/cjs/helpers/size.js +35 -4
- package/dist/cjs/helpers/spacing.js +43 -1
- package/dist/cjs/helpers/tracking/fpixel.js +28 -1
- package/dist/cjs/helpers/tracking/gtag.js +93 -1
- package/dist/cjs/helpers/tracking/tiktokpixel.js +17 -1
- package/dist/cjs/helpers/typography.js +105 -17
- package/dist/cjs/helpers/variant.js +8 -1
- package/dist/cjs/hooks/cart/use-add-to-cart.js +20 -1
- package/dist/cjs/hooks/cart/use-cart-data.js +28 -1
- package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +20 -1
- package/dist/cjs/hooks/cart/use-cart-note-update.js +20 -1
- package/dist/cjs/hooks/cart/use-create-cart.js +22 -1
- package/dist/cjs/hooks/cart/use-remove-cart-item.js +20 -1
- package/dist/cjs/hooks/cart/use-update-cart-item.js +20 -1
- package/dist/cjs/hooks/shop/use-collection-query.js +22 -1
- package/dist/cjs/hooks/shop/use-collections-query.js +17 -1
- package/dist/cjs/hooks/shop/use-product-query.js +22 -1
- package/dist/cjs/hooks/shop/use-products-query.js +22 -1
- package/dist/cjs/hooks/shop.js +126 -1
- package/dist/cjs/hooks/use-current-device.js +21 -1
- package/dist/cjs/hooks/use-lazy-video.js +15 -1
- package/dist/cjs/hooks/useCartId.js +44 -1
- package/dist/cjs/hooks/useCartLine.js +11 -1
- package/dist/cjs/hooks/useCartUI.js +48 -1
- package/dist/cjs/hooks/useCollection.js +9 -1
- package/dist/cjs/hooks/useFetchHandle.js +13 -1
- package/dist/cjs/hooks/useFormatMoney.js +58 -1
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +10 -1
- package/dist/cjs/hooks/useLoadScript.js +32 -1
- package/dist/cjs/hooks/useMoney.js +84 -1
- package/dist/cjs/hooks/usePrevious.js +19 -1
- package/dist/cjs/hooks/useProduct.js +124 -1
- package/dist/cjs/hooks/useProductList.js +21 -1
- package/dist/cjs/hooks/useSuspenseFetch.js +27 -1
- package/dist/cjs/hooks/useSwatchesOptions.js +41 -1
- package/dist/cjs/index.js +291 -1
- package/dist/cjs/types/global-style.js +14 -1
- package/dist/cjs/types/shop.js +2 -1
- package/dist/esm/components/AddOn.js +14 -1
- package/dist/esm/components/ComponentWrapper.js +24 -1
- package/dist/esm/components/ComponentWrapperPreview.js +68 -1
- package/dist/esm/components/Empty.js +3 -1
- package/dist/esm/components/Render.js +61 -1
- package/dist/esm/components/Render.liquid.js +153 -3
- package/dist/esm/components/RenderBlock.js +50 -1
- package/dist/esm/components/RenderPreview.js +62 -1
- package/dist/esm/components/RenderSection.js +19 -1
- package/dist/esm/components/constant.js +37 -1
- package/dist/esm/contexts/AddonContext.js +32 -1
- package/dist/esm/contexts/BuilderComponent.js +31 -1
- package/dist/esm/contexts/BuilderContext.js +32 -1
- package/dist/esm/contexts/BuilderPreviewContext.js +367 -1
- package/dist/esm/contexts/CartLineContext.js +26 -1
- package/dist/esm/contexts/CollectionContext.js +35 -1
- package/dist/esm/contexts/ModalContext.js +44 -1
- package/dist/esm/contexts/ProductContext.js +146 -1
- package/dist/esm/contexts/ProductListContext.js +28 -1
- package/dist/esm/contexts/SectionContext.js +49 -1
- package/dist/esm/contexts/ShopContext.js +67 -1
- package/dist/esm/graphql/fragments/analytic.generated.js +4 -2
- package/dist/esm/graphql/fragments/collection-detail.generated.js +4 -2
- package/dist/esm/graphql/fragments/collection-product.generated.js +4 -2
- package/dist/esm/graphql/fragments/collection.generated.js +4 -2
- package/dist/esm/graphql/fragments/custom-code.generated.js +4 -2
- package/dist/esm/graphql/fragments/data-seo.generated.js +4 -2
- package/dist/esm/graphql/fragments/media.generated.js +4 -3
- package/dist/esm/graphql/fragments/product-little.generated.js +4 -2
- package/dist/esm/graphql/fragments/product-option-value.generated.js +4 -2
- package/dist/esm/graphql/fragments/product-option.generated.js +4 -2
- package/dist/esm/graphql/fragments/product.generated.js +4 -2
- package/dist/esm/graphql/fragments/published-custom-section.generated.js +4 -2
- package/dist/esm/graphql/fragments/published-page-section.generated.js +4 -2
- package/dist/esm/graphql/fragments/published-theme-page.generated.js +4 -2
- package/dist/esm/graphql/fragments/published-theme-style.generated.js +4 -2
- package/dist/esm/graphql/fragments/selected-option.generated.js +4 -2
- package/dist/esm/graphql/fragments/variant.generated.js +4 -2
- package/dist/esm/graphql/mutations/page-view-up.generated.js +5 -3
- package/dist/esm/graphql/queries/collection-detail-filter.generated.js +22 -10
- package/dist/esm/graphql/queries/collection.generated.js +18 -8
- package/dist/esm/graphql/queries/collections.generated.js +8 -3
- package/dist/esm/graphql/queries/preview-page.generated.js +18 -8
- package/dist/esm/graphql/queries/product-little-detail.generated.js +12 -5
- package/dist/esm/graphql/queries/product-medias.generated.js +6 -2
- package/dist/esm/graphql/queries/product-variants.generated.js +10 -4
- package/dist/esm/graphql/queries/products.generated.js +20 -9
- package/dist/esm/graphql/queries/published-theme-pages.generated.js +18 -8
- package/dist/esm/graphql/queries/store-property.generated.js +4 -2
- package/dist/esm/helpers/GlobalEvent.js +15 -1
- package/dist/esm/helpers/background.js +106 -1
- package/dist/esm/helpers/borders.js +175 -4
- package/dist/esm/helpers/clone-deep.js +3 -1
- package/dist/esm/helpers/cls.js +14 -1
- package/dist/esm/helpers/colors.js +168 -1
- package/dist/esm/helpers/compose-advance-style.js +185 -1
- package/dist/esm/helpers/constant.js +19 -1
- package/dist/esm/helpers/convert.js +4 -1
- package/dist/esm/helpers/css-variable.js +5 -1
- package/dist/esm/helpers/email.js +6 -1
- package/dist/esm/helpers/flatten-connection.js +7 -1
- package/dist/esm/helpers/get-resonsive-value.js +27 -1
- package/dist/esm/helpers/get-shortname.js +90 -1
- package/dist/esm/helpers/is-browser.js +5 -1
- package/dist/esm/helpers/is-defined.js +5 -1
- package/dist/esm/helpers/is-empty-children.js +7 -1
- package/dist/esm/helpers/is-safari.js +5 -1
- package/dist/esm/helpers/layout.js +54 -1
- package/dist/esm/helpers/load-script.js +29 -1
- package/dist/esm/helpers/make-style.js +117 -1
- package/dist/esm/helpers/normalize-builder-data.js +21 -1
- package/dist/esm/helpers/prefetch-queries.js +76 -1
- package/dist/esm/helpers/product.js +41 -1
- package/dist/esm/helpers/queries/get-collection.js +217 -1
- package/dist/esm/helpers/queries/get-collections.js +19 -1
- package/dist/esm/helpers/queries/get-product-by-slug.js +123 -1
- package/dist/esm/helpers/queries/get-product.js +150 -1
- package/dist/esm/helpers/queries/get-products.js +159 -1
- package/dist/esm/helpers/query.js +25 -1
- package/dist/esm/helpers/radius.js +124 -6
- package/dist/esm/helpers/render.js +64 -1
- package/dist/esm/helpers/shadow.js +51 -1
- package/dist/esm/helpers/size.js +31 -4
- package/dist/esm/helpers/spacing.js +40 -1
- package/dist/esm/helpers/tracking/fpixel.js +24 -1
- package/dist/esm/helpers/tracking/gtag.js +87 -1
- package/dist/esm/helpers/tracking/tiktokpixel.js +15 -1
- package/dist/esm/helpers/typography.js +96 -17
- package/dist/esm/helpers/variant.js +6 -1
- package/dist/esm/hooks/cart/use-add-to-cart.js +18 -1
- package/dist/esm/hooks/cart/use-cart-data.js +26 -1
- package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +18 -1
- package/dist/esm/hooks/cart/use-cart-note-update.js +18 -1
- package/dist/esm/hooks/cart/use-create-cart.js +20 -1
- package/dist/esm/hooks/cart/use-remove-cart-item.js +18 -1
- package/dist/esm/hooks/cart/use-update-cart-item.js +18 -1
- package/dist/esm/hooks/shop/use-collection-query.js +20 -1
- package/dist/esm/hooks/shop/use-collections-query.js +15 -1
- package/dist/esm/hooks/shop/use-product-query.js +20 -1
- package/dist/esm/hooks/shop/use-products-query.js +20 -1
- package/dist/esm/hooks/shop.js +111 -1
- package/dist/esm/hooks/use-current-device.js +19 -1
- package/dist/esm/hooks/use-lazy-video.js +13 -1
- package/dist/esm/hooks/useCartId.js +40 -1
- package/dist/esm/hooks/useCartLine.js +7 -1
- package/dist/esm/hooks/useCartUI.js +44 -1
- package/dist/esm/hooks/useCollection.js +7 -1
- package/dist/esm/hooks/useFetchHandle.js +11 -1
- package/dist/esm/hooks/useFormatMoney.js +56 -1
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +6 -1
- package/dist/esm/hooks/useLoadScript.js +28 -1
- package/dist/esm/hooks/useMoney.js +80 -1
- package/dist/esm/hooks/usePrevious.js +17 -1
- package/dist/esm/hooks/useProduct.js +111 -1
- package/dist/esm/hooks/useProductList.js +16 -1
- package/dist/esm/hooks/useSuspenseFetch.js +23 -1
- package/dist/esm/hooks/useSwatchesOptions.js +37 -1
- package/dist/esm/index.js +92 -1
- package/dist/esm/types/global-style.js +11 -1
- package/dist/types/index.d.ts +26 -28
- package/package.json +2 -2
|
@@ -1 +1,76 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { unstable_serialize } from 'swr';
|
|
2
|
+
import { getCollection } from './queries/get-collection.js';
|
|
3
|
+
import { getProduct } from './queries/get-product.js';
|
|
4
|
+
import { getProducts } from './queries/get-products.js';
|
|
5
|
+
import { generateCollectionQueryKey, generateProductsQueryKey, generateProductQueryKey } from './query.js';
|
|
6
|
+
|
|
7
|
+
const prefetchQueries = (input, options)=>{
|
|
8
|
+
const queries = [];
|
|
9
|
+
Object.keys(input).forEach((key)=>{
|
|
10
|
+
const item = input[key];
|
|
11
|
+
let data = undefined;
|
|
12
|
+
switch(item.tag){
|
|
13
|
+
case 'Product':
|
|
14
|
+
{
|
|
15
|
+
if (item.settings?.isAuto) break;
|
|
16
|
+
const variables = {
|
|
17
|
+
id: item.settings?.productSetting?.productId ?? 'latest',
|
|
18
|
+
isSample: options?.isSample,
|
|
19
|
+
isStorefront: options?.isStorefront
|
|
20
|
+
};
|
|
21
|
+
data = {
|
|
22
|
+
key: unstable_serialize(generateProductQueryKey(variables)),
|
|
23
|
+
func: getProduct,
|
|
24
|
+
variables
|
|
25
|
+
};
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
case 'ProductList':
|
|
29
|
+
{
|
|
30
|
+
const productSetting = item.settings?.productSetting;
|
|
31
|
+
if (productSetting?.productSrc === 'Collection') {
|
|
32
|
+
const variables = {
|
|
33
|
+
id: productSetting?.collectionId ?? 'latest',
|
|
34
|
+
numberOfProducts: item.settings?.numberOfProducts ?? 4,
|
|
35
|
+
orderBy: item.settings?.orderBy,
|
|
36
|
+
isSample: options?.isSample,
|
|
37
|
+
isStorefront: options?.isStorefront
|
|
38
|
+
};
|
|
39
|
+
data = {
|
|
40
|
+
key: unstable_serialize(generateCollectionQueryKey(variables)),
|
|
41
|
+
func: getCollection,
|
|
42
|
+
variables
|
|
43
|
+
};
|
|
44
|
+
} else {
|
|
45
|
+
const variables = {
|
|
46
|
+
ids: [
|
|
47
|
+
...productSetting?.productIds ?? []
|
|
48
|
+
].sort(),
|
|
49
|
+
isSample: options?.isSample,
|
|
50
|
+
isStorefront: options?.isStorefront
|
|
51
|
+
};
|
|
52
|
+
data = {
|
|
53
|
+
key: unstable_serialize(generateProductsQueryKey(variables)),
|
|
54
|
+
func: getProducts,
|
|
55
|
+
variables
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (data) {
|
|
62
|
+
queries.push(data);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return queries.reduce((accumulator, current)=>{
|
|
66
|
+
if (!accumulator.some((x)=>x.key === current.key)) {
|
|
67
|
+
return [
|
|
68
|
+
...accumulator,
|
|
69
|
+
current
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
return accumulator;
|
|
73
|
+
}, []);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { prefetchQueries };
|
|
@@ -1 +1,41 @@
|
|
|
1
|
-
import{checkInStock
|
|
1
|
+
import { checkInStock } from './variant.js';
|
|
2
|
+
|
|
3
|
+
function getSelectedVariant(variants, choices) {
|
|
4
|
+
/**
|
|
5
|
+
* Ensure the user has selected all the required options, not just some.
|
|
6
|
+
*/ if (!variants || !variants.length || !choices || variants[0]?.selectedOptions.length !== Object.keys(choices).length) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
return variants.find((variant)=>{
|
|
10
|
+
return Object.entries(choices).every(([name, value])=>{
|
|
11
|
+
return variant?.selectedOptions.some((option)=>option.name === name && option.value === value);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function parseSelectedOption(options) {
|
|
16
|
+
if (!options || options && options.length === 0) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
return options.reduce((acc, { name, value })=>{
|
|
20
|
+
if (name && value) {
|
|
21
|
+
return {
|
|
22
|
+
...acc,
|
|
23
|
+
[name]: value
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return acc;
|
|
27
|
+
}, {});
|
|
28
|
+
}
|
|
29
|
+
function checkAvailableVariantInStock(variants, optionId, optionValue) {
|
|
30
|
+
return variants ? variants.some((item)=>{
|
|
31
|
+
if (item) {
|
|
32
|
+
const { selectedOptions } = item;
|
|
33
|
+
const opt = selectedOptions?.some((option)=>option?.name === optionId && option.value === optionValue);
|
|
34
|
+
const isInStock = checkInStock(item);
|
|
35
|
+
return opt && isInStock;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}) : false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { checkAvailableVariantInStock, getSelectedVariant, parseSelectedOption };
|
|
@@ -1 +1,217 @@
|
|
|
1
|
-
import{CollectionDetailFilterDocument
|
|
1
|
+
import { CollectionDetailFilterDocument } from '../../graphql/queries/collection-detail-filter.generated.js';
|
|
2
|
+
import { ProductVariantsDocument } from '../../graphql/queries/product-variants.generated.js';
|
|
3
|
+
import { isDefined } from '../is-defined.js';
|
|
4
|
+
|
|
5
|
+
const PRODUCT_PER_PAGE = 8; // number of products per page
|
|
6
|
+
function productSortedByOrder(key) {
|
|
7
|
+
switch(key){
|
|
8
|
+
case 'TITLE_ASC':
|
|
9
|
+
return {
|
|
10
|
+
direction: 'ASC',
|
|
11
|
+
field: 'TITLE'
|
|
12
|
+
};
|
|
13
|
+
case 'TITLE_DESC':
|
|
14
|
+
return {
|
|
15
|
+
direction: 'DESC',
|
|
16
|
+
field: 'TITLE'
|
|
17
|
+
};
|
|
18
|
+
case 'CREATED_AT_ASC':
|
|
19
|
+
return {
|
|
20
|
+
direction: 'ASC',
|
|
21
|
+
field: 'CREATED_AT'
|
|
22
|
+
};
|
|
23
|
+
case 'CREATED_AT_DESC':
|
|
24
|
+
return {
|
|
25
|
+
direction: 'DESC',
|
|
26
|
+
field: 'CREATED_AT'
|
|
27
|
+
};
|
|
28
|
+
case 'none':
|
|
29
|
+
default:
|
|
30
|
+
return {
|
|
31
|
+
direction: 'ASC',
|
|
32
|
+
field: 'TITLE'
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const getCollection = async (fetcher, arg)=>{
|
|
37
|
+
const collections = await loopFetchCollection(fetcher, arg);
|
|
38
|
+
if (!collections) {
|
|
39
|
+
throw new Error('collections not found');
|
|
40
|
+
}
|
|
41
|
+
// merge product collection variant
|
|
42
|
+
const mergeProducts = await mergeProductCollectionVariant(fetcher, collections, arg.isSample);
|
|
43
|
+
return mergeProducts;
|
|
44
|
+
};
|
|
45
|
+
const fetchCollection = async (fetcher, variables)=>{
|
|
46
|
+
return fetcher([
|
|
47
|
+
CollectionDetailFilterDocument,
|
|
48
|
+
variables
|
|
49
|
+
]);
|
|
50
|
+
};
|
|
51
|
+
const calculateFirstProduct = (numberOfProducts, currentPage, productsPerPage)=>{
|
|
52
|
+
const remainingProducts = numberOfProducts - productsPerPage * currentPage;
|
|
53
|
+
if (numberOfProducts < productsPerPage) return numberOfProducts;
|
|
54
|
+
return remainingProducts > 0 ? productsPerPage : productsPerPage + remainingProducts;
|
|
55
|
+
};
|
|
56
|
+
const chunkArray = (array, size)=>{
|
|
57
|
+
const chunked_arr = [];
|
|
58
|
+
let index = 0;
|
|
59
|
+
while(index < array.length){
|
|
60
|
+
chunked_arr.push(array.slice(index, size + index));
|
|
61
|
+
index += size;
|
|
62
|
+
}
|
|
63
|
+
return chunked_arr;
|
|
64
|
+
};
|
|
65
|
+
const loopFetchCollection = async (fetcher, arg)=>{
|
|
66
|
+
let variables; // variables of collection query
|
|
67
|
+
let productAfterFetcher; // product after of collection query
|
|
68
|
+
let dataCollection; // data of collection query
|
|
69
|
+
let hasNextPage; //
|
|
70
|
+
let firstCollection;
|
|
71
|
+
let currentPage = 1;
|
|
72
|
+
if (arg.numberOfProducts) {
|
|
73
|
+
const pages = Math.ceil(arg.numberOfProducts / PRODUCT_PER_PAGE);
|
|
74
|
+
while(currentPage <= pages && hasNextPage !== false){
|
|
75
|
+
variables = {
|
|
76
|
+
firstVariant: 1,
|
|
77
|
+
firstMedia: 30,
|
|
78
|
+
orderBy: {
|
|
79
|
+
field: 'PLATFORM_CREATED_AT',
|
|
80
|
+
direction: 'DESC'
|
|
81
|
+
},
|
|
82
|
+
orderByMedia: {
|
|
83
|
+
field: 'POSITION',
|
|
84
|
+
direction: 'ASC'
|
|
85
|
+
},
|
|
86
|
+
firstProduct: calculateFirstProduct(arg.numberOfProducts, currentPage, PRODUCT_PER_PAGE),
|
|
87
|
+
...!arg.id || arg.id.toLowerCase() === 'latest' ? {
|
|
88
|
+
where: {
|
|
89
|
+
hasCollectionProducts: true,
|
|
90
|
+
isSample: arg.isSample
|
|
91
|
+
}
|
|
92
|
+
} : {
|
|
93
|
+
where: {
|
|
94
|
+
baseID: arg.id
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
orderByProduct: productSortedByOrder(arg.orderBy),
|
|
98
|
+
whereProduct: {
|
|
99
|
+
status: 'ACTIVE',
|
|
100
|
+
...arg.isStorefront && {
|
|
101
|
+
isStorefront: arg.isStorefront
|
|
102
|
+
},
|
|
103
|
+
isSample: arg.isSample
|
|
104
|
+
},
|
|
105
|
+
...productAfterFetcher ? {
|
|
106
|
+
productsAfter: productAfterFetcher
|
|
107
|
+
} : undefined
|
|
108
|
+
};
|
|
109
|
+
const pageData = await fetchCollection(fetcher, variables);
|
|
110
|
+
productAfterFetcher = pageData?.collections?.edges?.[0]?.node?.products?.pageInfo?.endCursor;
|
|
111
|
+
if (currentPage === 1) {
|
|
112
|
+
dataCollection = pageData; // set data of first page
|
|
113
|
+
firstCollection = dataCollection?.collections?.edges?.[0];
|
|
114
|
+
} else if (firstCollection?.node?.products && pageData?.collections?.edges?.[0]?.node?.products?.edges) {
|
|
115
|
+
// concat new values to the old ones
|
|
116
|
+
firstCollection.node.products = {
|
|
117
|
+
pageInfo: pageData?.collections?.edges?.[0]?.node?.products?.pageInfo,
|
|
118
|
+
edges: firstCollection.node?.products?.edges.concat(pageData?.collections?.edges?.[0]?.node?.products?.edges)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
currentPage++;
|
|
122
|
+
// hasNextPage = false if there is no more pages then break the loop
|
|
123
|
+
if (!firstCollection?.node?.products?.pageInfo?.hasNextPage) {
|
|
124
|
+
hasNextPage = false;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return dataCollection;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const mergeProductCollectionVariant = async (fetcher, collection, isSample)=>{
|
|
132
|
+
const node = collection?.collections?.edges?.[0]?.node;
|
|
133
|
+
if (!node) return collection;
|
|
134
|
+
const productList = node?.products?.edges;
|
|
135
|
+
const listBaseId = productList?.map((product)=>product?.node?.baseID).filter(isDefined);
|
|
136
|
+
const ProductListWithVariants = await fetchVariantsByBaseIds(fetcher, {
|
|
137
|
+
ids: listBaseId,
|
|
138
|
+
isSample
|
|
139
|
+
});
|
|
140
|
+
// mapping variant to product list in collections
|
|
141
|
+
const newProductList = productList?.map((product)=>{
|
|
142
|
+
const productVariants = ProductListWithVariants?.variants?.edges?.filter((productV)=>productV?.node?.id === product?.node?.id);
|
|
143
|
+
return {
|
|
144
|
+
...product,
|
|
145
|
+
node: product.node ? {
|
|
146
|
+
...product.node,
|
|
147
|
+
variants: product.node?.variants ? {
|
|
148
|
+
...product.node?.variants,
|
|
149
|
+
edges: productVariants?.[0]?.node?.variants?.edges ?? []
|
|
150
|
+
} : undefined
|
|
151
|
+
} : undefined
|
|
152
|
+
};
|
|
153
|
+
}) ?? [];
|
|
154
|
+
const newCollection = {
|
|
155
|
+
...collection,
|
|
156
|
+
collections: {
|
|
157
|
+
edges: [
|
|
158
|
+
{
|
|
159
|
+
node: {
|
|
160
|
+
...node,
|
|
161
|
+
products: {
|
|
162
|
+
edges: newProductList
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
cursor: undefined
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
return newCollection;
|
|
171
|
+
};
|
|
172
|
+
const fetchVariantsByBaseIds = async (fetcher, { ids, isSample, isStorefront })=>{
|
|
173
|
+
const chunkedIds = chunkArray(ids ?? [], 8);
|
|
174
|
+
const defaultEdges = [];
|
|
175
|
+
const query = async (variables)=>{
|
|
176
|
+
try {
|
|
177
|
+
return await fetcher([
|
|
178
|
+
ProductVariantsDocument,
|
|
179
|
+
variables
|
|
180
|
+
]);
|
|
181
|
+
} catch {
|
|
182
|
+
return {};
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const promises = chunkedIds.map((chunkedId)=>{
|
|
186
|
+
const variables = {
|
|
187
|
+
firstVariant: 100,
|
|
188
|
+
first: chunkedId.length,
|
|
189
|
+
orderBy: {
|
|
190
|
+
field: 'TITLE',
|
|
191
|
+
direction: 'ASC'
|
|
192
|
+
},
|
|
193
|
+
where: {
|
|
194
|
+
status: 'ACTIVE',
|
|
195
|
+
isSample,
|
|
196
|
+
...isStorefront && {
|
|
197
|
+
isStorefront
|
|
198
|
+
},
|
|
199
|
+
...chunkedId.length && {
|
|
200
|
+
baseIDIn: chunkedId.sort()
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
return query(variables);
|
|
205
|
+
});
|
|
206
|
+
const responses = await Promise.all(promises);
|
|
207
|
+
const edges = responses?.reduce((acc, response)=>{
|
|
208
|
+
return acc.concat(response?.variants?.edges ?? []);
|
|
209
|
+
}, defaultEdges);
|
|
210
|
+
return {
|
|
211
|
+
variants: {
|
|
212
|
+
edges
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export { calculateFirstProduct, getCollection };
|
|
@@ -1 +1,19 @@
|
|
|
1
|
-
import{CollectionsDocument
|
|
1
|
+
import { CollectionsDocument } from '../../graphql/queries/collections.generated.js';
|
|
2
|
+
|
|
3
|
+
const getCollections = async (fetcher, variable)=>{
|
|
4
|
+
const collections = await fetchCollections(fetcher, variable ?? {});
|
|
5
|
+
if (!collections) {
|
|
6
|
+
throw new Error('Collection not found');
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
...collections
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
const fetchCollections = async (fetcher, variables)=>{
|
|
13
|
+
return fetcher([
|
|
14
|
+
CollectionsDocument,
|
|
15
|
+
variables
|
|
16
|
+
]);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { getCollections };
|
|
@@ -1 +1,123 @@
|
|
|
1
|
-
import{ProductLittleDetailDocument
|
|
1
|
+
import { ProductLittleDetailDocument } from '../../graphql/queries/product-little-detail.generated.js';
|
|
2
|
+
import { ProductMediasDocument } from '../../graphql/queries/product-medias.generated.js';
|
|
3
|
+
import { ProductVariantsDocument } from '../../graphql/queries/product-variants.generated.js';
|
|
4
|
+
|
|
5
|
+
const getProductBySlug = async (fetcher, slug)=>{
|
|
6
|
+
const [product, variants, medias] = await Promise.all([
|
|
7
|
+
fetchProduct(fetcher, slug),
|
|
8
|
+
fetchVariants(fetcher, slug),
|
|
9
|
+
fetchMedias(fetcher, slug)
|
|
10
|
+
]);
|
|
11
|
+
if (!product) {
|
|
12
|
+
throw new Error('Product not found');
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
...product,
|
|
16
|
+
variants: {
|
|
17
|
+
edges: variants
|
|
18
|
+
},
|
|
19
|
+
medias: {
|
|
20
|
+
edges: medias
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const orderBy = {
|
|
25
|
+
field: 'PLATFORM_UPDATED_AT',
|
|
26
|
+
direction: 'DESC'
|
|
27
|
+
};
|
|
28
|
+
const fetchProduct = async (fetcher, handle, isStorefront)=>{
|
|
29
|
+
const variables = {
|
|
30
|
+
orderBy,
|
|
31
|
+
where: {
|
|
32
|
+
status: 'ACTIVE',
|
|
33
|
+
handle,
|
|
34
|
+
...isStorefront && {
|
|
35
|
+
isStorefront
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const response = await fetcher([
|
|
40
|
+
ProductLittleDetailDocument,
|
|
41
|
+
variables
|
|
42
|
+
]);
|
|
43
|
+
return response.product?.edges?.[0]?.node;
|
|
44
|
+
};
|
|
45
|
+
const fetchVariants = async (fetcher, handle, isStorefront)=>{
|
|
46
|
+
const initVariables = {
|
|
47
|
+
orderBy,
|
|
48
|
+
orderByVariant: {
|
|
49
|
+
field: 'POSITION',
|
|
50
|
+
direction: 'ASC'
|
|
51
|
+
},
|
|
52
|
+
where: {
|
|
53
|
+
status: 'ACTIVE',
|
|
54
|
+
handle,
|
|
55
|
+
...isStorefront && {
|
|
56
|
+
isStorefront
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const query = async (variables, olds)=>{
|
|
61
|
+
try {
|
|
62
|
+
const response = await fetcher([
|
|
63
|
+
ProductVariantsDocument,
|
|
64
|
+
variables
|
|
65
|
+
]);
|
|
66
|
+
const product = response.variants?.edges?.[0];
|
|
67
|
+
const items = olds?.concat(product?.node?.variants?.edges ?? []);
|
|
68
|
+
if (product?.node?.variants?.pageInfo?.hasNextPage) {
|
|
69
|
+
return query({
|
|
70
|
+
...variables,
|
|
71
|
+
afterVariant: product?.node?.variants?.pageInfo.endCursor
|
|
72
|
+
}, items);
|
|
73
|
+
}
|
|
74
|
+
return items ?? [];
|
|
75
|
+
} catch {
|
|
76
|
+
return olds ?? [];
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return query(initVariables, []);
|
|
80
|
+
};
|
|
81
|
+
const fetchMedias = async (fetcher, handle, isStorefront)=>{
|
|
82
|
+
const initVariables = {
|
|
83
|
+
orderBy,
|
|
84
|
+
where: {
|
|
85
|
+
status: 'ACTIVE',
|
|
86
|
+
handle,
|
|
87
|
+
...isStorefront && {
|
|
88
|
+
isStorefront
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
orderByMedia: {
|
|
92
|
+
field: 'POSITION',
|
|
93
|
+
direction: 'ASC'
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const query = async (variables)=>{
|
|
97
|
+
try {
|
|
98
|
+
const response = await fetcher([
|
|
99
|
+
ProductMediasDocument,
|
|
100
|
+
variables
|
|
101
|
+
]);
|
|
102
|
+
const product = response.medias?.edges?.[0];
|
|
103
|
+
const items = product?.node?.medias?.edges ?? [];
|
|
104
|
+
if (product?.node?.medias?.pageInfo?.hasNextPage) {
|
|
105
|
+
try {
|
|
106
|
+
const newData = await query({
|
|
107
|
+
...variables,
|
|
108
|
+
afterMedia: product?.node?.medias?.pageInfo.endCursor
|
|
109
|
+
});
|
|
110
|
+
return items.concat(newData);
|
|
111
|
+
} catch {
|
|
112
|
+
return items;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return items;
|
|
116
|
+
} catch {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
return query(initVariables);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export { getProductBySlug };
|
|
@@ -1 +1,150 @@
|
|
|
1
|
-
import{ProductLittleDetailDocument
|
|
1
|
+
import { ProductLittleDetailDocument } from '../../graphql/queries/product-little-detail.generated.js';
|
|
2
|
+
import { ProductMediasDocument } from '../../graphql/queries/product-medias.generated.js';
|
|
3
|
+
import { ProductVariantsDocument } from '../../graphql/queries/product-variants.generated.js';
|
|
4
|
+
|
|
5
|
+
const getProduct = async (fetcher, { id, isSample, isStorefront })=>{
|
|
6
|
+
const [product, variants, medias] = await Promise.all([
|
|
7
|
+
fetchProduct(fetcher, {
|
|
8
|
+
id,
|
|
9
|
+
isSample,
|
|
10
|
+
isStorefront
|
|
11
|
+
}),
|
|
12
|
+
fetchVariants(fetcher, {
|
|
13
|
+
id,
|
|
14
|
+
isSample,
|
|
15
|
+
isStorefront
|
|
16
|
+
}),
|
|
17
|
+
fetchMedias(fetcher, {
|
|
18
|
+
id,
|
|
19
|
+
isSample,
|
|
20
|
+
isStorefront
|
|
21
|
+
})
|
|
22
|
+
]);
|
|
23
|
+
if (!product) {
|
|
24
|
+
throw new Error('Product not found');
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
...product,
|
|
28
|
+
variants: {
|
|
29
|
+
edges: variants
|
|
30
|
+
},
|
|
31
|
+
medias: {
|
|
32
|
+
edges: medias
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const orderBy = {
|
|
37
|
+
field: 'CREATED_AT',
|
|
38
|
+
direction: 'DESC'
|
|
39
|
+
};
|
|
40
|
+
const fetchProduct = async (fetcher, { id, isSample, isStorefront })=>{
|
|
41
|
+
const variables = {
|
|
42
|
+
orderBy,
|
|
43
|
+
where: {
|
|
44
|
+
isSample,
|
|
45
|
+
...isStorefront && {
|
|
46
|
+
isStorefront
|
|
47
|
+
},
|
|
48
|
+
...(!id || id && id.toLowerCase() == 'latest') && {
|
|
49
|
+
status: 'ACTIVE'
|
|
50
|
+
},
|
|
51
|
+
...id && id.toLowerCase() !== 'latest' && {
|
|
52
|
+
baseID: id
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const response = await fetcher([
|
|
57
|
+
ProductLittleDetailDocument,
|
|
58
|
+
variables
|
|
59
|
+
]);
|
|
60
|
+
return response.product?.edges?.[0]?.node;
|
|
61
|
+
};
|
|
62
|
+
const fetchVariants = async (fetcher, { id, isSample, isStorefront })=>{
|
|
63
|
+
const initVariables = {
|
|
64
|
+
orderBy,
|
|
65
|
+
where: {
|
|
66
|
+
isSample,
|
|
67
|
+
...isStorefront && {
|
|
68
|
+
isStorefront
|
|
69
|
+
},
|
|
70
|
+
...(!id || id && id.toLowerCase() == 'latest') && {
|
|
71
|
+
status: 'ACTIVE'
|
|
72
|
+
},
|
|
73
|
+
...id && id.toLowerCase() !== 'latest' && {
|
|
74
|
+
baseID: id
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
orderByVariant: {
|
|
78
|
+
field: 'POSITION',
|
|
79
|
+
direction: 'ASC'
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const query = async (variables, olds)=>{
|
|
83
|
+
try {
|
|
84
|
+
const response = await fetcher([
|
|
85
|
+
ProductVariantsDocument,
|
|
86
|
+
variables
|
|
87
|
+
]);
|
|
88
|
+
const product = response.variants?.edges?.[0];
|
|
89
|
+
const items = olds?.concat(product?.node?.variants?.edges ?? []);
|
|
90
|
+
if (product?.node?.variants?.pageInfo?.hasNextPage) {
|
|
91
|
+
return query({
|
|
92
|
+
...variables,
|
|
93
|
+
afterVariant: product?.node?.variants?.pageInfo.endCursor
|
|
94
|
+
}, items);
|
|
95
|
+
}
|
|
96
|
+
return items ?? [];
|
|
97
|
+
} catch {
|
|
98
|
+
return olds ?? [];
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return query(initVariables, []);
|
|
102
|
+
};
|
|
103
|
+
const fetchMedias = async (fetcher, { id, isSample, isStorefront })=>{
|
|
104
|
+
const initVariables = {
|
|
105
|
+
orderBy,
|
|
106
|
+
where: {
|
|
107
|
+
isSample,
|
|
108
|
+
...isStorefront && {
|
|
109
|
+
isStorefront
|
|
110
|
+
},
|
|
111
|
+
...(!id || id && id.toLowerCase() == 'latest') && {
|
|
112
|
+
status: 'ACTIVE'
|
|
113
|
+
},
|
|
114
|
+
...id && id.toLowerCase() !== 'latest' && {
|
|
115
|
+
baseID: id
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
orderByMedia: {
|
|
119
|
+
field: 'POSITION',
|
|
120
|
+
direction: 'ASC'
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const query = async (variables)=>{
|
|
124
|
+
try {
|
|
125
|
+
const response = await fetcher([
|
|
126
|
+
ProductMediasDocument,
|
|
127
|
+
variables
|
|
128
|
+
]);
|
|
129
|
+
const product = response.medias?.edges?.[0];
|
|
130
|
+
const items = product?.node?.medias?.edges ?? [];
|
|
131
|
+
if (product?.node?.medias?.pageInfo?.hasNextPage) {
|
|
132
|
+
try {
|
|
133
|
+
const newData = await query({
|
|
134
|
+
...variables,
|
|
135
|
+
afterMedia: product?.node?.medias?.pageInfo.endCursor
|
|
136
|
+
});
|
|
137
|
+
return items.concat(newData);
|
|
138
|
+
} catch {
|
|
139
|
+
return items;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return items;
|
|
143
|
+
} catch {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
return query(initVariables);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export { fetchMedias, fetchVariants, getProduct };
|