@wix/headless-stores 0.0.11 → 0.0.14
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/cjs/dist/astro/actions/custom-checkout.d.ts +4 -2
- package/cjs/dist/astro/actions/custom-checkout.js +4 -8
- package/cjs/dist/astro/actions/index.d.ts +1 -1
- package/cjs/dist/astro/actions/index.js +1 -17
- package/cjs/dist/enums/index.d.ts +2 -2
- package/cjs/dist/enums/index.js +2 -18
- package/cjs/dist/enums/social-platform-enums.js +4 -7
- package/cjs/dist/enums/sort-enums.js +3 -6
- package/cjs/dist/react/BuyNow.js +6 -11
- package/cjs/dist/react/Category.d.ts +2 -2
- package/cjs/dist/react/Category.js +6 -10
- package/cjs/dist/react/Collection.d.ts +1 -1
- package/cjs/dist/react/Collection.js +31 -39
- package/cjs/dist/react/FilteredCollection.d.ts +7 -20
- package/cjs/dist/react/FilteredCollection.js +29 -57
- package/cjs/dist/react/PayNow.js +4 -9
- package/cjs/dist/react/Product.d.ts +3 -3
- package/cjs/dist/react/Product.js +6 -11
- package/cjs/dist/react/ProductActions.js +12 -17
- package/cjs/dist/react/ProductModifiers.d.ts +3 -1
- package/cjs/dist/react/ProductModifiers.js +23 -29
- package/cjs/dist/react/ProductVariantSelector.d.ts +1 -1
- package/cjs/dist/react/ProductVariantSelector.js +18 -28
- package/cjs/dist/react/RelatedProducts.d.ts +2 -2
- package/cjs/dist/react/RelatedProducts.js +35 -33
- package/cjs/dist/react/SelectedVariant.js +8 -14
- package/cjs/dist/react/SocialSharing.d.ts +2 -2
- package/cjs/dist/react/SocialSharing.js +35 -33
- package/cjs/dist/react/Sort.d.ts +3 -2
- package/cjs/dist/react/Sort.js +6 -9
- package/cjs/dist/react/index.d.ts +13 -13
- package/cjs/dist/react/index.js +13 -52
- package/cjs/dist/server-actions/custom-checkout-action.js +8 -11
- package/cjs/dist/server-actions/index.d.ts +1 -1
- package/cjs/dist/server-actions/index.js +1 -17
- package/cjs/dist/services/buy-now-service.d.ts +44 -3
- package/cjs/dist/services/buy-now-service.js +20 -22
- package/cjs/dist/services/catalog-options-service.d.ts +3 -3
- package/cjs/dist/services/catalog-options-service.js +45 -46
- package/cjs/dist/services/catalog-price-range-service.d.ts +3 -3
- package/cjs/dist/services/catalog-price-range-service.js +21 -25
- package/cjs/dist/services/category-service.d.ts +7 -7
- package/cjs/dist/services/category-service.js +20 -22
- package/cjs/dist/services/collection-service.d.ts +8 -8
- package/cjs/dist/services/collection-service.js +102 -133
- package/cjs/dist/services/filter-service.d.ts +4 -4
- package/cjs/dist/services/filter-service.js +47 -61
- package/cjs/dist/services/index.d.ts +13 -2
- package/cjs/dist/services/index.js +13 -9
- package/cjs/dist/services/pay-now-service.d.ts +4 -3
- package/cjs/dist/services/pay-now-service.js +11 -16
- package/cjs/dist/services/product-modifiers-service.d.ts +6 -6
- package/cjs/dist/services/product-modifiers-service.js +17 -21
- package/cjs/dist/services/product-service.d.ts +8 -8
- package/cjs/dist/services/product-service.js +22 -26
- package/cjs/dist/services/related-products-service.d.ts +5 -5
- package/cjs/dist/services/related-products-service.js +9 -13
- package/cjs/dist/services/selected-variant-service.d.ts +11 -8
- package/cjs/dist/services/selected-variant-service.js +73 -90
- package/cjs/dist/services/social-sharing-service.d.ts +2 -9
- package/cjs/dist/services/social-sharing-service.js +48 -60
- package/cjs/dist/services/sort-service.d.ts +3 -3
- package/cjs/dist/services/sort-service.js +14 -19
- package/cjs/dist/utils/index.js +6 -9
- package/cjs/dist/utils/url-params.js +5 -9
- package/dist/astro/actions/custom-checkout.d.ts +1 -1
- package/dist/astro/actions/custom-checkout.js +1 -1
- package/dist/astro/actions/index.d.ts +1 -1
- package/dist/astro/actions/index.js +1 -1
- package/dist/enums/index.d.ts +2 -2
- package/dist/enums/index.js +2 -2
- package/dist/react/BuyNow.js +4 -6
- package/dist/react/Category.d.ts +2 -2
- package/dist/react/Category.js +2 -2
- package/dist/react/Collection.d.ts +1 -1
- package/dist/react/Collection.js +20 -20
- package/dist/react/FilteredCollection.d.ts +7 -20
- package/dist/react/FilteredCollection.js +17 -35
- package/dist/react/PayNow.js +2 -4
- package/dist/react/Product.d.ts +3 -3
- package/dist/react/Product.js +2 -2
- package/dist/react/ProductActions.js +9 -10
- package/dist/react/ProductModifiers.d.ts +3 -1
- package/dist/react/ProductModifiers.js +14 -12
- package/dist/react/ProductVariantSelector.d.ts +1 -1
- package/dist/react/ProductVariantSelector.js +6 -8
- package/dist/react/RelatedProducts.d.ts +2 -2
- package/dist/react/RelatedProducts.js +25 -15
- package/dist/react/SelectedVariant.js +2 -2
- package/dist/react/SocialSharing.d.ts +2 -2
- package/dist/react/SocialSharing.js +24 -13
- package/dist/react/Sort.d.ts +3 -2
- package/dist/react/Sort.js +2 -2
- package/dist/react/index.d.ts +13 -13
- package/dist/react/index.js +13 -13
- package/dist/server-actions/index.d.ts +1 -1
- package/dist/server-actions/index.js +1 -1
- package/dist/services/buy-now-service.d.ts +44 -3
- package/dist/services/buy-now-service.js +7 -4
- package/dist/services/catalog-options-service.d.ts +3 -3
- package/dist/services/catalog-options-service.js +33 -30
- package/dist/services/catalog-price-range-service.d.ts +3 -3
- package/dist/services/catalog-price-range-service.js +18 -18
- package/dist/services/category-service.d.ts +7 -7
- package/dist/services/category-service.js +17 -15
- package/dist/services/collection-service.d.ts +8 -8
- package/dist/services/collection-service.js +80 -74
- package/dist/services/filter-service.d.ts +4 -4
- package/dist/services/filter-service.js +37 -48
- package/dist/services/index.d.ts +13 -2
- package/dist/services/index.js +13 -2
- package/dist/services/pay-now-service.d.ts +4 -3
- package/dist/services/pay-now-service.js +1 -1
- package/dist/services/product-modifiers-service.d.ts +6 -6
- package/dist/services/product-modifiers-service.js +13 -13
- package/dist/services/product-service.d.ts +8 -8
- package/dist/services/product-service.js +19 -19
- package/dist/services/related-products-service.d.ts +5 -5
- package/dist/services/related-products-service.js +6 -6
- package/dist/services/selected-variant-service.d.ts +11 -8
- package/dist/services/selected-variant-service.js +71 -85
- package/dist/services/social-sharing-service.d.ts +2 -9
- package/dist/services/social-sharing-service.js +29 -37
- package/dist/services/sort-service.d.ts +3 -3
- package/dist/services/sort-service.js +8 -10
- package/dist/utils/url-params.js +4 -4
- package/package.json +5 -5
- package/cjs/dist/services/product-media-gallery-service.d.ts +0 -25
- package/cjs/dist/services/product-media-gallery-service.js +0 -105
- package/dist/services/product-media-gallery-service.d.ts +0 -25
- package/dist/services/product-media-gallery-service.js +0 -101
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { defineService, implementService } from
|
|
2
|
-
import { SignalsServiceDefinition } from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import { ProductServiceDefinition } from
|
|
7
|
-
|
|
8
|
-
export const
|
|
1
|
+
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
|
+
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
|
+
import * as productsV3 from "@wix/auto_sdk_stores_products-v-3";
|
|
4
|
+
import * as inventoryItemsV3 from "@wix/auto_sdk_stores_inventory-items-v-3";
|
|
5
|
+
import { CurrentCartServiceDefinition } from "@wix/headless-ecom/services";
|
|
6
|
+
import { ProductServiceDefinition } from "./product-service.js";
|
|
7
|
+
import { MediaGalleryServiceDefinition } from "@wix/headless-media/services";
|
|
8
|
+
export const SelectedVariantServiceDefinition = defineService("selectedVariant");
|
|
9
|
+
export const SelectedVariantService = implementService.withConfig()(SelectedVariantServiceDefinition, ({ getService, config: { fetchInventoryData = true } }) => {
|
|
9
10
|
const signalsService = getService(SignalsServiceDefinition);
|
|
10
|
-
|
|
11
|
+
const cartService = getService(CurrentCartServiceDefinition);
|
|
11
12
|
const productService = getService(ProductServiceDefinition);
|
|
12
|
-
|
|
13
|
+
const mediaService = getService(MediaGalleryServiceDefinition);
|
|
13
14
|
const selectedChoices = signalsService.signal({});
|
|
14
15
|
const preOrderMessage = signalsService.signal(null);
|
|
15
16
|
const initialProduct = productService.product.get();
|
|
@@ -17,8 +18,9 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
17
18
|
const product = productService.product.get();
|
|
18
19
|
const selectedChoicesValue = selectedChoices.get() || {};
|
|
19
20
|
let mediaToDisplay = [];
|
|
20
|
-
const productItemsImages = product?.media?.itemsInfo?.items
|
|
21
|
-
|
|
21
|
+
const productItemsImages = product?.media?.itemsInfo?.items
|
|
22
|
+
?.map((item) => item)
|
|
23
|
+
.filter(Boolean) ?? [];
|
|
22
24
|
if (productItemsImages.length) {
|
|
23
25
|
mediaToDisplay = productItemsImages;
|
|
24
26
|
}
|
|
@@ -27,7 +29,7 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
27
29
|
}
|
|
28
30
|
// Get images based on selected choices if available
|
|
29
31
|
let selectedChoicesImages = [];
|
|
30
|
-
Object.keys(selectedChoicesValue).forEach(choiceKey => {
|
|
32
|
+
Object.keys(selectedChoicesValue).forEach((choiceKey) => {
|
|
31
33
|
const productOption = product?.options
|
|
32
34
|
?.find((option) => option.name === choiceKey)
|
|
33
35
|
?.choicesSettings?.choices?.find((choice) => choice.name === selectedChoicesValue[choiceKey]);
|
|
@@ -38,8 +40,7 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
38
40
|
if (selectedChoicesImages?.length) {
|
|
39
41
|
mediaToDisplay = selectedChoicesImages;
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
// mediaService.setMediaToDisplay(mediaToDisplay ?? []);
|
|
43
|
+
mediaService.setMediaToDisplay(mediaToDisplay ?? []);
|
|
43
44
|
});
|
|
44
45
|
const parsePrice = (amount) => {
|
|
45
46
|
if (!amount)
|
|
@@ -61,20 +62,12 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
61
62
|
return choices;
|
|
62
63
|
};
|
|
63
64
|
const findVariantByChoices = (variants, selectedChoices) => {
|
|
64
|
-
return (variants.find(variant => {
|
|
65
|
+
return (variants.find((variant) => {
|
|
65
66
|
const variantChoices = processVariantChoices(variant);
|
|
66
67
|
const choiceKeys = Object.keys(selectedChoices);
|
|
67
|
-
return choiceKeys.every(key => variantChoices[key] === selectedChoices[key]);
|
|
68
|
+
return choiceKeys.every((key) => variantChoices[key] === selectedChoices[key]);
|
|
68
69
|
}) || null);
|
|
69
70
|
};
|
|
70
|
-
const findVariantWithMinPrice = () => {
|
|
71
|
-
const variantsList = variants.get();
|
|
72
|
-
const variantPrices = variantsList.map(x => Number(x.price?.actualPrice?.formattedAmount) ||
|
|
73
|
-
Number(x.price?.actualPrice?.amount));
|
|
74
|
-
const minPrice = String(Math.min(...variantPrices));
|
|
75
|
-
return variantsList.find(x => x.price?.actualPrice?.formattedAmount === minPrice ||
|
|
76
|
-
x.price?.actualPrice?.amount === minPrice);
|
|
77
|
-
};
|
|
78
71
|
const updateInventoryItemData = async (variantId, inStock, preOrderEnabled) => {
|
|
79
72
|
if (!variantId) {
|
|
80
73
|
preOrderMessage.set(null);
|
|
@@ -82,8 +75,9 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
82
75
|
}
|
|
83
76
|
try {
|
|
84
77
|
// Use the correct Wix inventoryItemsV3.queryInventoryItems() API
|
|
85
|
-
const queryResult = await
|
|
86
|
-
.
|
|
78
|
+
const queryResult = await inventoryItemsV3
|
|
79
|
+
.queryInventoryItems()
|
|
80
|
+
.eq("variantId", variantId)
|
|
87
81
|
.find();
|
|
88
82
|
const inventoryItem = queryResult.items?.[0];
|
|
89
83
|
const isTrackingQuantity = inventoryItem?.trackQuantity ?? false;
|
|
@@ -104,7 +98,7 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
catch (error) {
|
|
107
|
-
console.error(
|
|
101
|
+
console.error("Failed to fetch inventory quantity:", error);
|
|
108
102
|
// Fallback on error
|
|
109
103
|
quantityAvailable.set(null);
|
|
110
104
|
trackQuantity.set(false);
|
|
@@ -115,11 +109,21 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
115
109
|
const inStock = variant.inventoryStatus?.inStock ?? true;
|
|
116
110
|
const preOrderEnabled = variant.inventoryStatus?.preorderEnabled ?? false;
|
|
117
111
|
// update the quantity available, tracking indication and pre-order message from the inventory API
|
|
118
|
-
|
|
112
|
+
// only if fetchInventoryData is enabled (defaults to true for backward compatibility)
|
|
113
|
+
if (fetchInventoryData) {
|
|
114
|
+
updateInventoryItemData(variant._id, inStock, preOrderEnabled);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// Set default values when inventory fetching is disabled
|
|
118
|
+
quantityAvailable.set(null);
|
|
119
|
+
trackQuantity.set(false);
|
|
120
|
+
preOrderMessage.set(null);
|
|
121
|
+
}
|
|
119
122
|
}
|
|
120
123
|
else {
|
|
121
124
|
quantityAvailable.set(0);
|
|
122
125
|
trackQuantity.set(false);
|
|
126
|
+
preOrderMessage.set(null);
|
|
123
127
|
}
|
|
124
128
|
};
|
|
125
129
|
const isLoading = signalsService.signal(false);
|
|
@@ -132,13 +136,13 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
132
136
|
const quantityAvailable = signalsService.signal(null);
|
|
133
137
|
const trackQuantity = signalsService.signal(false);
|
|
134
138
|
const selectedQuantity = signalsService.signal(1);
|
|
135
|
-
const productId = signalsService.signal(
|
|
139
|
+
const productId = signalsService.signal("");
|
|
136
140
|
const ribbonLabel = signalsService.signal(null);
|
|
137
141
|
const v3Product = signalsService.signal(initialProduct);
|
|
138
142
|
const init = (currentProduct) => {
|
|
139
143
|
if (currentProduct) {
|
|
140
144
|
v3Product.set(currentProduct);
|
|
141
|
-
productId.set(currentProduct._id ||
|
|
145
|
+
productId.set(currentProduct._id || "");
|
|
142
146
|
ribbonLabel.set(currentProduct.ribbon?.name || null);
|
|
143
147
|
const actualPrice = currentProduct.actualPriceRange?.minValue?.amount;
|
|
144
148
|
const compareAtPrice = currentProduct.compareAtPriceRange?.minValue?.amount;
|
|
@@ -150,7 +154,7 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
150
154
|
const optionsMap = {};
|
|
151
155
|
currentProduct.options.forEach((option) => {
|
|
152
156
|
if (option.name && option.choicesSettings?.choices) {
|
|
153
|
-
optionsMap[option.name] = option.choicesSettings.choices.map((choice) => choice.name ||
|
|
157
|
+
optionsMap[option.name] = option.choicesSettings.choices.map((choice) => choice.name || "");
|
|
154
158
|
}
|
|
155
159
|
});
|
|
156
160
|
options.set(optionsMap);
|
|
@@ -158,12 +162,12 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
158
162
|
if (currentProduct.variantSummary.variantCount > 1) {
|
|
159
163
|
variants.set(currentProduct.variantsInfo?.variants || []);
|
|
160
164
|
if (currentProduct.variantsInfo?.variants?.length) {
|
|
161
|
-
|
|
165
|
+
updateDataFromVariant(currentProduct.variantsInfo?.variants[0] || null);
|
|
162
166
|
}
|
|
163
167
|
}
|
|
164
168
|
else {
|
|
165
169
|
const singleVariant = {
|
|
166
|
-
_id:
|
|
170
|
+
_id: "default",
|
|
167
171
|
visible: true,
|
|
168
172
|
choices: [],
|
|
169
173
|
price: {
|
|
@@ -172,10 +176,11 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
172
176
|
},
|
|
173
177
|
inventoryStatus: {
|
|
174
178
|
inStock: currentProduct.inventory?.availabilityStatus ===
|
|
175
|
-
InventoryAvailabilityStatus.IN_STOCK ||
|
|
179
|
+
productsV3.InventoryAvailabilityStatus.IN_STOCK ||
|
|
176
180
|
currentProduct.inventory?.availabilityStatus ===
|
|
177
|
-
InventoryAvailabilityStatus
|
|
178
|
-
|
|
181
|
+
productsV3.InventoryAvailabilityStatus
|
|
182
|
+
.PARTIALLY_OUT_OF_STOCK,
|
|
183
|
+
preorderEnabled: currentProduct.inventory?.preorderStatus === "ENABLED",
|
|
179
184
|
},
|
|
180
185
|
};
|
|
181
186
|
variants.set([singleVariant]);
|
|
@@ -194,7 +199,8 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
194
199
|
return null;
|
|
195
200
|
return (variantsList.find((variant) => {
|
|
196
201
|
const variantChoices = processVariantChoices(variant);
|
|
197
|
-
if (Object.keys(choices).length !==
|
|
202
|
+
if (Object.keys(choices).length !==
|
|
203
|
+
Object.keys(variantChoices).length)
|
|
198
204
|
return false;
|
|
199
205
|
return Object.entries(choices).every(([optionName, optionValue]) => {
|
|
200
206
|
return variantChoices[optionName] === optionValue;
|
|
@@ -205,19 +211,8 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
205
211
|
const variant = currentVariant.get();
|
|
206
212
|
return variant?._id || null;
|
|
207
213
|
});
|
|
208
|
-
const variantWithMinPrice = findVariantWithMinPrice();
|
|
209
214
|
const currentPrice = signalsService.computed(() => {
|
|
210
215
|
const variant = currentVariant.get();
|
|
211
|
-
if (!variant && variantWithMinPrice) {
|
|
212
|
-
const formattedAmount = variantWithMinPrice?.price?.actualPrice?.formattedAmount;
|
|
213
|
-
if (formattedAmount) {
|
|
214
|
-
return formattedAmount;
|
|
215
|
-
}
|
|
216
|
-
const amount = variantWithMinPrice?.price?.actualPrice?.amount;
|
|
217
|
-
if (amount) {
|
|
218
|
-
return `$${amount}`;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
216
|
const prod = v3Product.get();
|
|
222
217
|
// Try to get formatted amount first (if fields worked)
|
|
223
218
|
if (variant?.price?.actualPrice?.formattedAmount) {
|
|
@@ -234,21 +229,11 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
234
229
|
else if (prod?.actualPriceRange?.minValue?.amount) {
|
|
235
230
|
rawAmount = prod.actualPriceRange.minValue.amount;
|
|
236
231
|
}
|
|
237
|
-
return rawAmount ? `$${rawAmount}` :
|
|
232
|
+
return rawAmount ? `$${rawAmount}` : "";
|
|
238
233
|
});
|
|
239
234
|
const currentCompareAtPrice = signalsService.computed(() => {
|
|
240
235
|
const variant = currentVariant.get();
|
|
241
236
|
const prod = v3Product.get();
|
|
242
|
-
if (!variant && variantWithMinPrice) {
|
|
243
|
-
const formattedAmount = variantWithMinPrice?.price?.compareAtPrice?.formattedAmount;
|
|
244
|
-
if (formattedAmount) {
|
|
245
|
-
return formattedAmount;
|
|
246
|
-
}
|
|
247
|
-
const amount = variantWithMinPrice?.price?.compareAtPrice?.amount;
|
|
248
|
-
if (amount) {
|
|
249
|
-
return `$${amount}`;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
237
|
// Try to get formatted compare-at price first
|
|
253
238
|
if (variant?.price?.compareAtPrice?.formattedAmount) {
|
|
254
239
|
return variant.price.compareAtPrice.formattedAmount;
|
|
@@ -286,12 +271,12 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
286
271
|
});
|
|
287
272
|
const currency = signalsService.computed(() => {
|
|
288
273
|
const prod = v3Product.get();
|
|
289
|
-
return prod?.currency ||
|
|
274
|
+
return prod?.currency || "USD";
|
|
290
275
|
});
|
|
291
276
|
const selectedVariant = () => {
|
|
292
277
|
const variantId = selectedVariantId.get();
|
|
293
278
|
const variantsList = variants.get();
|
|
294
|
-
return variantsList.find(v => v._id === variantId) || null;
|
|
279
|
+
return variantsList.find((v) => v._id === variantId) || null;
|
|
295
280
|
};
|
|
296
281
|
const finalPrice = () => {
|
|
297
282
|
const discount = discountPrice.get();
|
|
@@ -309,20 +294,20 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
309
294
|
const matchingVariant = findVariantByChoices(variants.get(), choices);
|
|
310
295
|
updateDataFromVariant(matchingVariant);
|
|
311
296
|
};
|
|
312
|
-
const addToCart = async (
|
|
297
|
+
const addToCart = async (quantity = 1, modifiers) => {
|
|
313
298
|
try {
|
|
314
299
|
isLoading.set(true);
|
|
315
300
|
error.set(null);
|
|
316
301
|
const prod = v3Product.get();
|
|
317
302
|
const variant = currentVariant.get();
|
|
318
303
|
if (!prod?._id) {
|
|
319
|
-
throw new Error(
|
|
304
|
+
throw new Error("Product not found");
|
|
320
305
|
}
|
|
321
306
|
// Build catalog reference with modifiers if provided
|
|
322
307
|
const catalogReference = {
|
|
323
308
|
catalogItemId: prod._id,
|
|
324
|
-
appId:
|
|
325
|
-
options: variant?._id && variant._id !==
|
|
309
|
+
appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e",
|
|
310
|
+
options: variant?._id && variant._id !== "default"
|
|
326
311
|
? {
|
|
327
312
|
variantId: variant._id,
|
|
328
313
|
preOrderRequested: !!variant?.inventoryStatus?.preorderEnabled,
|
|
@@ -337,21 +322,22 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
337
322
|
const productModifiers = prod.modifiers || [];
|
|
338
323
|
Object.values(modifiers).forEach((modifierValue) => {
|
|
339
324
|
const modifierName = modifierValue.modifierName;
|
|
340
|
-
const productModifier = productModifiers.find(m => m.name === modifierName);
|
|
325
|
+
const productModifier = productModifiers.find((m) => m.name === modifierName);
|
|
341
326
|
if (!productModifier)
|
|
342
327
|
return;
|
|
343
328
|
const renderType = productModifier.modifierRenderType;
|
|
344
|
-
if (renderType === ModifierRenderType.TEXT_CHOICES ||
|
|
345
|
-
renderType === ModifierRenderType.SWATCH_CHOICES) {
|
|
329
|
+
if (renderType === productsV3.ModifierRenderType.TEXT_CHOICES ||
|
|
330
|
+
renderType === productsV3.ModifierRenderType.SWATCH_CHOICES) {
|
|
346
331
|
// For choice modifiers, use the modifier key and choice value
|
|
347
332
|
const modifierKey = productModifier.key || modifierName;
|
|
348
333
|
if (modifierValue.choiceValue) {
|
|
349
334
|
options[modifierKey] = modifierValue.choiceValue;
|
|
350
335
|
}
|
|
351
336
|
}
|
|
352
|
-
else if (renderType === ModifierRenderType.FREE_TEXT) {
|
|
337
|
+
else if (renderType === productsV3.ModifierRenderType.FREE_TEXT) {
|
|
353
338
|
// For free text modifiers, use the freeTextSettings key
|
|
354
|
-
const freeTextKey = productModifier.freeTextSettings?.key ||
|
|
339
|
+
const freeTextKey = productModifier.freeTextSettings?.key ||
|
|
340
|
+
modifierName;
|
|
355
341
|
if (modifierValue.freeTextValue) {
|
|
356
342
|
customTextFields[freeTextKey] = modifierValue.freeTextValue;
|
|
357
343
|
}
|
|
@@ -371,16 +357,16 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
371
357
|
};
|
|
372
358
|
}
|
|
373
359
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
360
|
+
const lineItems = [
|
|
361
|
+
{
|
|
362
|
+
catalogReference,
|
|
363
|
+
quantity,
|
|
364
|
+
},
|
|
365
|
+
];
|
|
366
|
+
await cartService.addToCart(lineItems);
|
|
381
367
|
}
|
|
382
368
|
catch (err) {
|
|
383
|
-
error.set(err instanceof Error ? err.message :
|
|
369
|
+
error.set(err instanceof Error ? err.message : "Failed to add to cart");
|
|
384
370
|
}
|
|
385
371
|
finally {
|
|
386
372
|
isLoading.set(false);
|
|
@@ -393,7 +379,7 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
393
379
|
};
|
|
394
380
|
const selectVariantById = (id) => {
|
|
395
381
|
const variantsList = variants.get();
|
|
396
|
-
const variant = variantsList.find(v => v._id === id);
|
|
382
|
+
const variant = variantsList.find((v) => v._id === id);
|
|
397
383
|
if (variant) {
|
|
398
384
|
const variantChoices = processVariantChoices(variant);
|
|
399
385
|
selectedChoices.set(variantChoices);
|
|
@@ -427,7 +413,7 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
427
413
|
const variantsList = variants.get();
|
|
428
414
|
// Get all possible choices for this option that result in valid variants
|
|
429
415
|
const availableChoices = new Set();
|
|
430
|
-
variantsList.forEach(variant => {
|
|
416
|
+
variantsList.forEach((variant) => {
|
|
431
417
|
const variantChoices = processVariantChoices(variant);
|
|
432
418
|
// Check if this variant matches all currently selected choices (except for the option we're checking)
|
|
433
419
|
const matchesOtherChoices = Object.entries(currentChoices)
|
|
@@ -449,7 +435,7 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
449
435
|
};
|
|
450
436
|
// Get all variants and find one that matches these choices
|
|
451
437
|
const variantsList = variants.get();
|
|
452
|
-
const matchingVariants = variantsList.filter(variant => {
|
|
438
|
+
const matchingVariants = variantsList.filter((variant) => {
|
|
453
439
|
if (!variant.choices)
|
|
454
440
|
return false;
|
|
455
441
|
const variantChoices = {};
|
|
@@ -465,9 +451,9 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
465
451
|
});
|
|
466
452
|
const isAvailable = matchingVariants.length > 0;
|
|
467
453
|
// Check if ANY of the matching variants are in stock
|
|
468
|
-
const isInStock = matchingVariants.some(variant => variant.inventoryStatus?.inStock === true);
|
|
454
|
+
const isInStock = matchingVariants.some((variant) => variant.inventoryStatus?.inStock === true);
|
|
469
455
|
// Check if ANY of the matching variants have pre-order enabled
|
|
470
|
-
const isPreOrderEnabled = matchingVariants.some(variant => variant.inventoryStatus?.preorderEnabled === true);
|
|
456
|
+
const isPreOrderEnabled = matchingVariants.some((variant) => variant.inventoryStatus?.preorderEnabled === true);
|
|
471
457
|
return { isAvailable, isInStock, isPreOrderEnabled };
|
|
472
458
|
};
|
|
473
459
|
// Simplified methods using the core getChoiceInfo
|
|
@@ -487,7 +473,7 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
487
473
|
const IsAllVariantsAreOutOfStock = () => {
|
|
488
474
|
const variantsList = variants.get();
|
|
489
475
|
// All variants must be out of stock AND none should have preorder enabled
|
|
490
|
-
return (variantsList?.every(variant => !variant.inventoryStatus?.inStock &&
|
|
476
|
+
return (variantsList?.every((variant) => !variant.inventoryStatus?.inStock &&
|
|
491
477
|
!variant.inventoryStatus?.preorderEnabled) ?? true);
|
|
492
478
|
};
|
|
493
479
|
return {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type { Signal } from '../../Signal';
|
|
1
|
+
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
3
2
|
export interface SharingPlatform {
|
|
4
3
|
name: string;
|
|
5
4
|
icon: string;
|
|
@@ -32,10 +31,4 @@ export declare const SocialSharingService: import("@wix/services-definitions").S
|
|
|
32
31
|
__api: SocialSharingServiceAPI;
|
|
33
32
|
__config: {};
|
|
34
33
|
isServiceDefinition?: boolean;
|
|
35
|
-
} & SocialSharingServiceAPI, {
|
|
36
|
-
productName: string;
|
|
37
|
-
productUrl: string;
|
|
38
|
-
productDescription?: string;
|
|
39
|
-
productImage?: string;
|
|
40
|
-
}, import("@wix/services-definitions").ThreadMode.MAIN>;
|
|
41
|
-
export declare function loadSocialSharingServiceConfig(productName: string, productUrl: string, productDescription?: string, productImage?: string): Promise<ServiceFactoryConfig<typeof SocialSharingService>>;
|
|
34
|
+
} & SocialSharingServiceAPI, {}>;
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { defineService, implementService
|
|
2
|
-
import { SignalsServiceDefinition } from
|
|
3
|
-
import { SocialPlatform, SocialPlatformShareUrl, } from
|
|
4
|
-
export const SocialSharingServiceDefinition = defineService(
|
|
1
|
+
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
|
+
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
|
+
import { SocialPlatform, SocialPlatformShareUrl, } from "../enums/social-platform-enums.js";
|
|
4
|
+
export const SocialSharingServiceDefinition = defineService("socialSharing");
|
|
5
5
|
export const SocialSharingService = implementService.withConfig()(SocialSharingServiceDefinition, ({ getService }) => {
|
|
6
6
|
const signalsService = getService(SignalsServiceDefinition);
|
|
7
7
|
// Platform metadata is handled in components layer, only business logic here
|
|
8
8
|
const availablePlatforms = signalsService.signal([
|
|
9
9
|
{
|
|
10
|
-
name:
|
|
11
|
-
icon:
|
|
12
|
-
color:
|
|
10
|
+
name: "Facebook",
|
|
11
|
+
icon: "facebook",
|
|
12
|
+
color: "#1877F2",
|
|
13
13
|
shareUrl: SocialPlatformShareUrl.FACEBOOK,
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
|
-
name:
|
|
17
|
-
icon:
|
|
18
|
-
color:
|
|
16
|
+
name: "Twitter",
|
|
17
|
+
icon: "twitter",
|
|
18
|
+
color: "#1DA1F2",
|
|
19
19
|
shareUrl: SocialPlatformShareUrl.TWITTER,
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
|
-
name:
|
|
23
|
-
icon:
|
|
24
|
-
color:
|
|
22
|
+
name: "LinkedIn",
|
|
23
|
+
icon: "linkedin",
|
|
24
|
+
color: "#0A66C2",
|
|
25
25
|
shareUrl: SocialPlatformShareUrl.LINKEDIN,
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
name:
|
|
29
|
-
icon:
|
|
30
|
-
color:
|
|
28
|
+
name: "WhatsApp",
|
|
29
|
+
icon: "whatsapp",
|
|
30
|
+
color: "#25D366",
|
|
31
31
|
shareUrl: SocialPlatformShareUrl.WHATSAPP,
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
|
-
name:
|
|
35
|
-
icon:
|
|
36
|
-
color:
|
|
34
|
+
name: "Email",
|
|
35
|
+
icon: "mail",
|
|
36
|
+
color: "#EA4335",
|
|
37
37
|
shareUrl: SocialPlatformShareUrl.EMAIL,
|
|
38
38
|
},
|
|
39
39
|
]);
|
|
@@ -49,25 +49,25 @@ export const SocialSharingService = implementService.withConfig()(SocialSharingS
|
|
|
49
49
|
};
|
|
50
50
|
const shareToFacebook = (url, title, description) => {
|
|
51
51
|
const shareUrl = new URL(SocialPlatformShareUrl.FACEBOOK);
|
|
52
|
-
shareUrl.searchParams.set(
|
|
53
|
-
shareUrl.searchParams.set(
|
|
52
|
+
shareUrl.searchParams.set("u", url);
|
|
53
|
+
shareUrl.searchParams.set("quote", `${title}${description ? ` - ${description}` : ""}`);
|
|
54
54
|
openShareWindow(shareUrl.toString(), SocialPlatform.FACEBOOK);
|
|
55
55
|
};
|
|
56
56
|
const shareToTwitter = (url, text, hashtags) => {
|
|
57
57
|
const shareUrl = new URL(SocialPlatformShareUrl.TWITTER);
|
|
58
|
-
shareUrl.searchParams.set(
|
|
59
|
-
shareUrl.searchParams.set(
|
|
58
|
+
shareUrl.searchParams.set("url", url);
|
|
59
|
+
shareUrl.searchParams.set("text", text);
|
|
60
60
|
if (hashtags && hashtags.length > 0) {
|
|
61
|
-
shareUrl.searchParams.set(
|
|
61
|
+
shareUrl.searchParams.set("hashtags", hashtags.join(","));
|
|
62
62
|
}
|
|
63
63
|
openShareWindow(shareUrl.toString(), SocialPlatform.TWITTER);
|
|
64
64
|
};
|
|
65
65
|
const shareToLinkedIn = (url, title, summary) => {
|
|
66
66
|
const shareUrl = new URL(SocialPlatformShareUrl.LINKEDIN);
|
|
67
|
-
shareUrl.searchParams.set(
|
|
68
|
-
shareUrl.searchParams.set(
|
|
67
|
+
shareUrl.searchParams.set("url", url);
|
|
68
|
+
shareUrl.searchParams.set("title", title);
|
|
69
69
|
if (summary) {
|
|
70
|
-
shareUrl.searchParams.set(
|
|
70
|
+
shareUrl.searchParams.set("summary", summary);
|
|
71
71
|
}
|
|
72
72
|
openShareWindow(shareUrl.toString(), SocialPlatform.LINKEDIN);
|
|
73
73
|
};
|
|
@@ -89,7 +89,7 @@ export const SocialSharingService = implementService.withConfig()(SocialSharingS
|
|
|
89
89
|
return true;
|
|
90
90
|
}
|
|
91
91
|
catch (err) {
|
|
92
|
-
console.error(
|
|
92
|
+
console.error("Failed to copy to clipboard:", err);
|
|
93
93
|
return false;
|
|
94
94
|
}
|
|
95
95
|
};
|
|
@@ -103,7 +103,7 @@ export const SocialSharingService = implementService.withConfig()(SocialSharingS
|
|
|
103
103
|
return false;
|
|
104
104
|
}
|
|
105
105
|
catch (err) {
|
|
106
|
-
console.error(
|
|
106
|
+
console.error("Failed to share natively:", err);
|
|
107
107
|
return false;
|
|
108
108
|
}
|
|
109
109
|
};
|
|
@@ -127,11 +127,3 @@ export const SocialSharingService = implementService.withConfig()(SocialSharingS
|
|
|
127
127
|
trackShare,
|
|
128
128
|
};
|
|
129
129
|
});
|
|
130
|
-
export async function loadSocialSharingServiceConfig(productName, productUrl, productDescription, productImage) {
|
|
131
|
-
return {
|
|
132
|
-
productName,
|
|
133
|
-
productUrl,
|
|
134
|
-
productDescription,
|
|
135
|
-
productImage,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { SortType } from
|
|
1
|
+
import { type Signal } from "@wix/services-definitions/core-services/signals";
|
|
2
|
+
import { SortType } from "../enums/sort-enums.js";
|
|
3
3
|
export type SortBy = SortType;
|
|
4
4
|
export interface SortServiceAPI {
|
|
5
5
|
currentSort: Signal<SortBy>;
|
|
@@ -17,4 +17,4 @@ export declare const SortService: import("@wix/services-definitions").ServiceFac
|
|
|
17
17
|
isServiceDefinition?: boolean;
|
|
18
18
|
} & SortServiceAPI, {
|
|
19
19
|
initialSort?: SortBy;
|
|
20
|
-
}
|
|
20
|
+
}>;
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import { defineService, implementService } from
|
|
2
|
-
import { SignalsServiceDefinition } from
|
|
3
|
-
import { URLParamsUtils } from
|
|
4
|
-
import { SortType, DEFAULT_SORT_TYPE } from
|
|
5
|
-
export const SortServiceDefinition = defineService(
|
|
1
|
+
import { defineService, implementService } from "@wix/services-definitions";
|
|
2
|
+
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
|
+
import { URLParamsUtils } from "../utils/url-params.js";
|
|
4
|
+
import { SortType, DEFAULT_SORT_TYPE } from "../enums/sort-enums.js";
|
|
5
|
+
export const SortServiceDefinition = defineService("sort");
|
|
6
6
|
export const defaultSort = DEFAULT_SORT_TYPE;
|
|
7
7
|
export const SortService = implementService.withConfig()(SortServiceDefinition, ({ getService, config }) => {
|
|
8
8
|
const signalsService = getService(SignalsServiceDefinition);
|
|
9
|
-
const currentSort = signalsService.signal((config
|
|
9
|
+
const currentSort = signalsService.signal((config?.initialSort || defaultSort));
|
|
10
10
|
const setSortBy = async (sortBy) => {
|
|
11
11
|
currentSort.set(sortBy);
|
|
12
12
|
// Update URL with sort parameter
|
|
13
13
|
const currentParams = URLParamsUtils.getURLParams();
|
|
14
14
|
const urlParams = { ...currentParams };
|
|
15
15
|
if (sortBy !== SortType.NEWEST) {
|
|
16
|
-
|
|
17
|
-
urlParams.sort = sortBy;
|
|
16
|
+
urlParams["sort"] = sortBy;
|
|
18
17
|
}
|
|
19
18
|
else {
|
|
20
|
-
|
|
21
|
-
delete urlParams.sort;
|
|
19
|
+
delete urlParams["sort"];
|
|
22
20
|
}
|
|
23
21
|
URLParamsUtils.updateURL(urlParams);
|
|
24
22
|
};
|
package/dist/utils/url-params.js
CHANGED
|
@@ -19,14 +19,14 @@ export class URLParamsUtils {
|
|
|
19
19
|
return params;
|
|
20
20
|
}
|
|
21
21
|
static updateURL(params) {
|
|
22
|
-
if (typeof window ===
|
|
22
|
+
if (typeof window === 'undefined')
|
|
23
23
|
return;
|
|
24
24
|
const url = new URL(window.location.href);
|
|
25
25
|
const urlParams = new URLSearchParams();
|
|
26
26
|
// Add all parameters
|
|
27
27
|
Object.entries(params).forEach(([key, value]) => {
|
|
28
28
|
if (Array.isArray(value)) {
|
|
29
|
-
value.forEach(
|
|
29
|
+
value.forEach(v => urlParams.append(key, v));
|
|
30
30
|
}
|
|
31
31
|
else if (value) {
|
|
32
32
|
urlParams.set(key, value);
|
|
@@ -36,10 +36,10 @@ export class URLParamsUtils {
|
|
|
36
36
|
const newURL = urlParams.toString()
|
|
37
37
|
? `${url.pathname}?${urlParams.toString()}`
|
|
38
38
|
: url.pathname;
|
|
39
|
-
window.history.replaceState({},
|
|
39
|
+
window.history.replaceState({}, '', newURL);
|
|
40
40
|
}
|
|
41
41
|
static getURLParams() {
|
|
42
|
-
if (typeof window ===
|
|
42
|
+
if (typeof window === 'undefined')
|
|
43
43
|
return {};
|
|
44
44
|
return this.parseSearchParams(new URLSearchParams(window.location.search));
|
|
45
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/headless-stores",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npm run build:esm && npm run build:cjs",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
"@wix/auto_sdk_stores_inventory-items-v-3": "^1.0.26",
|
|
56
56
|
"@wix/auto_sdk_stores_products-v-3": "^1.0.53",
|
|
57
57
|
"@wix/auto_sdk_stores_read-only-variants-v-3": "^1.0.23",
|
|
58
|
-
"@wix/categories": "^1.0.137",
|
|
59
|
-
"@wix/ecom": "^1.0.1169",
|
|
60
58
|
"@wix/essentials": "^0.1.22",
|
|
59
|
+
"@wix/headless-ecom": "^0.0.2",
|
|
60
|
+
"@wix/headless-media": "^0.0.1",
|
|
61
61
|
"@wix/redirects": "^1.0.79",
|
|
62
|
-
"@wix/services-definitions": "^0.1.
|
|
63
|
-
"@wix/services-manager-react": "^0.1.
|
|
62
|
+
"@wix/services-definitions": "^0.1.4",
|
|
63
|
+
"@wix/services-manager-react": "^0.1.26"
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { type ServiceFactoryConfig } from "@wix/services-definitions";
|
|
2
|
-
import type { Signal, ReadOnlySignal } from "../../Signal";
|
|
3
|
-
import { V3Product } from "@wix/auto_sdk_stores_products-v-3";
|
|
4
|
-
export interface ProductMediaGalleryServiceAPI {
|
|
5
|
-
selectedImageIndex: Signal<number>;
|
|
6
|
-
relevantImages: ReadOnlySignal<string[]>;
|
|
7
|
-
product: ReadOnlySignal<V3Product | null>;
|
|
8
|
-
isLoading: ReadOnlySignal<boolean>;
|
|
9
|
-
totalImages: ReadOnlySignal<number>;
|
|
10
|
-
productName: ReadOnlySignal<string>;
|
|
11
|
-
setSelectedImageIndex: (index: number) => void;
|
|
12
|
-
nextImage: () => void;
|
|
13
|
-
previousImage: () => void;
|
|
14
|
-
}
|
|
15
|
-
export declare const ProductMediaGalleryServiceDefinition: string & {
|
|
16
|
-
__api: ProductMediaGalleryServiceAPI;
|
|
17
|
-
__config: {};
|
|
18
|
-
isServiceDefinition?: boolean;
|
|
19
|
-
} & ProductMediaGalleryServiceAPI;
|
|
20
|
-
export declare const ProductMediaGalleryService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
21
|
-
__api: ProductMediaGalleryServiceAPI;
|
|
22
|
-
__config: {};
|
|
23
|
-
isServiceDefinition?: boolean;
|
|
24
|
-
} & ProductMediaGalleryServiceAPI, {}, import("@wix/services-definitions").ThreadMode.MAIN>;
|
|
25
|
-
export declare function loadProductMediaGalleryServiceConfig(productSlug: string): Promise<ServiceFactoryConfig<typeof ProductMediaGalleryService>>;
|