@wix/headless-stores 0.0.51 → 0.0.52
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.
|
@@ -3,9 +3,11 @@ import { SignalsServiceDefinition, } from "@wix/services-definitions/core-servic
|
|
|
3
3
|
import * as productsV3 from "@wix/auto_sdk_stores_products-v-3";
|
|
4
4
|
import * as inventoryItemsV3 from "@wix/auto_sdk_stores_inventory-items-v-3";
|
|
5
5
|
import { CurrentCartServiceDefinition } from "@wix/headless-ecom/services";
|
|
6
|
+
import { MediaGalleryServiceDefinition } from "@wix/headless-media/services";
|
|
6
7
|
import { ProductServiceDefinition } from "./product-service.js";
|
|
7
8
|
export const SelectedVariantServiceDefinition = defineService("selectedVariant");
|
|
8
9
|
export const SelectedVariantService = implementService.withConfig()(SelectedVariantServiceDefinition, ({ getService, config: { fetchInventoryData = true } }) => {
|
|
10
|
+
const mediaService = getService(MediaGalleryServiceDefinition);
|
|
9
11
|
const signalsService = getService(SignalsServiceDefinition);
|
|
10
12
|
const cartService = getService(CurrentCartServiceDefinition);
|
|
11
13
|
const productService = getService(ProductServiceDefinition);
|
|
@@ -15,15 +17,15 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
15
17
|
signalsService.effect(() => {
|
|
16
18
|
const product = productService.product.get();
|
|
17
19
|
const selectedChoicesValue = selectedChoices.get() || {};
|
|
18
|
-
|
|
20
|
+
let mediaToDisplay = [];
|
|
19
21
|
const productItemsImages = product?.media?.itemsInfo?.items
|
|
20
22
|
?.map((item) => item)
|
|
21
23
|
.filter(Boolean) ?? [];
|
|
22
24
|
if (productItemsImages.length) {
|
|
23
|
-
|
|
25
|
+
mediaToDisplay = productItemsImages;
|
|
24
26
|
}
|
|
25
27
|
else if (product?.media?.main) {
|
|
26
|
-
|
|
28
|
+
mediaToDisplay = [product.media.main];
|
|
27
29
|
}
|
|
28
30
|
// Get images based on selected choices if available
|
|
29
31
|
let selectedChoicesImages = [];
|
|
@@ -36,9 +38,9 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
36
38
|
}
|
|
37
39
|
});
|
|
38
40
|
if (selectedChoicesImages?.length) {
|
|
39
|
-
|
|
41
|
+
mediaToDisplay = selectedChoicesImages;
|
|
40
42
|
}
|
|
41
|
-
|
|
43
|
+
mediaService.setMediaToDisplay(mediaToDisplay ?? []);
|
|
42
44
|
});
|
|
43
45
|
const parsePrice = (amount) => {
|
|
44
46
|
if (!amount)
|
|
@@ -3,9 +3,11 @@ import { SignalsServiceDefinition, } from "@wix/services-definitions/core-servic
|
|
|
3
3
|
import * as productsV3 from "@wix/auto_sdk_stores_products-v-3";
|
|
4
4
|
import * as inventoryItemsV3 from "@wix/auto_sdk_stores_inventory-items-v-3";
|
|
5
5
|
import { CurrentCartServiceDefinition } from "@wix/headless-ecom/services";
|
|
6
|
+
import { MediaGalleryServiceDefinition } from "@wix/headless-media/services";
|
|
6
7
|
import { ProductServiceDefinition } from "./product-service.js";
|
|
7
8
|
export const SelectedVariantServiceDefinition = defineService("selectedVariant");
|
|
8
9
|
export const SelectedVariantService = implementService.withConfig()(SelectedVariantServiceDefinition, ({ getService, config: { fetchInventoryData = true } }) => {
|
|
10
|
+
const mediaService = getService(MediaGalleryServiceDefinition);
|
|
9
11
|
const signalsService = getService(SignalsServiceDefinition);
|
|
10
12
|
const cartService = getService(CurrentCartServiceDefinition);
|
|
11
13
|
const productService = getService(ProductServiceDefinition);
|
|
@@ -15,15 +17,15 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
15
17
|
signalsService.effect(() => {
|
|
16
18
|
const product = productService.product.get();
|
|
17
19
|
const selectedChoicesValue = selectedChoices.get() || {};
|
|
18
|
-
|
|
20
|
+
let mediaToDisplay = [];
|
|
19
21
|
const productItemsImages = product?.media?.itemsInfo?.items
|
|
20
22
|
?.map((item) => item)
|
|
21
23
|
.filter(Boolean) ?? [];
|
|
22
24
|
if (productItemsImages.length) {
|
|
23
|
-
|
|
25
|
+
mediaToDisplay = productItemsImages;
|
|
24
26
|
}
|
|
25
27
|
else if (product?.media?.main) {
|
|
26
|
-
|
|
28
|
+
mediaToDisplay = [product.media.main];
|
|
27
29
|
}
|
|
28
30
|
// Get images based on selected choices if available
|
|
29
31
|
let selectedChoicesImages = [];
|
|
@@ -36,9 +38,9 @@ export const SelectedVariantService = implementService.withConfig()(SelectedVari
|
|
|
36
38
|
}
|
|
37
39
|
});
|
|
38
40
|
if (selectedChoicesImages?.length) {
|
|
39
|
-
|
|
41
|
+
mediaToDisplay = selectedChoicesImages;
|
|
40
42
|
}
|
|
41
|
-
|
|
43
|
+
mediaService.setMediaToDisplay(mediaToDisplay ?? []);
|
|
42
44
|
});
|
|
43
45
|
const parsePrice = (amount) => {
|
|
44
46
|
if (!amount)
|