@shopgate/pwa-common-commerce 7.30.0-alpha.7 → 7.30.0-alpha.9
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/cart/action-creators/addCouponsToCart.js +9 -2
- package/cart/action-creators/addProductsToCart.js +9 -2
- package/cart/action-creators/deleteCouponsFromCart.js +9 -2
- package/cart/action-creators/deleteProductsFromCart.js +9 -2
- package/cart/action-creators/errorAddCouponsToCart.js +10 -2
- package/cart/action-creators/errorAddProductsToCart.js +10 -2
- package/cart/action-creators/errorCart.js +8 -2
- package/cart/action-creators/errorDeleteCouponsFromCart.js +10 -2
- package/cart/action-creators/errorDeleteProductsFromCart.js +10 -2
- package/cart/action-creators/errorUpdateProductsInCart.js +10 -2
- package/cart/action-creators/receiveCart.js +9 -2
- package/cart/action-creators/requestCart.js +8 -2
- package/cart/action-creators/setCartProductPendingCount.js +9 -2
- package/cart/action-creators/setCouponFieldError.js +9 -2
- package/cart/action-creators/setCouponFieldValue.js +9 -2
- package/cart/action-creators/setFulfillmentSlot.js +9 -2
- package/cart/action-creators/successAddCouponsToCart.js +10 -2
- package/cart/action-creators/successAddProductsToCart.js +8 -2
- package/cart/action-creators/successDeleteCouponsFromCart.js +8 -2
- package/cart/action-creators/successDeleteProductsFromCart.js +8 -2
- package/cart/action-creators/successUpdateProductsInCart.js +8 -2
- package/cart/action-creators/updateProductsInCart.js +9 -2
- package/cart/actions/addCouponsToCart.js +52 -8
- package/cart/actions/addProductsToCart.js +80 -11
- package/cart/actions/deleteCouponsFromCart.js +39 -6
- package/cart/actions/deleteProductsFromCart.js +38 -6
- package/cart/actions/fetchCart.js +52 -8
- package/cart/actions/updateProductsInCart.js +44 -6
- package/cart/constants/PipelineErrors.js +6 -1
- package/cart/constants/Pipelines.js +6 -1
- package/cart/constants/Portals.js +85 -1
- package/cart/constants/index.js +39 -2
- package/cart/helpers/config.js +47 -2
- package/cart/helpers/createPipelineErrorList.js +30 -4
- package/cart/helpers/fulfillmentSlots.js +37 -4
- package/cart/helpers/index.js +14 -3
- package/cart/helpers/quantity.js +23 -4
- package/cart/helpers/shipping.js +57 -2
- package/cart/helpers/tax.js +26 -2
- package/cart/index.js +25 -5
- package/cart/mock.js +130 -1
- package/cart/reducers/couponField.js +30 -2
- package/cart/reducers/data.js +98 -6
- package/cart/reducers/index.js +7 -1
- package/cart/selectors/index.js +181 -31
- package/cart/selectors/spec.js +189 -2
- package/cart/streams/index.js +176 -29
- package/cart/subscriptions/index.js +307 -30
- package/category/action-creators/errorCategory.js +10 -2
- package/category/action-creators/errorCategoryChildren.js +9 -2
- package/category/action-creators/errorRootCategories.js +8 -2
- package/category/action-creators/receiveCategory.js +12 -2
- package/category/action-creators/receiveCategoryChildren.js +10 -2
- package/category/action-creators/receiveRootCategories.js +9 -2
- package/category/action-creators/requestCategory.js +9 -2
- package/category/action-creators/requestCategoryChildren.js +9 -2
- package/category/action-creators/requestRootCategories.js +8 -2
- package/category/actions/fetchCategory.js +47 -5
- package/category/actions/fetchCategoryChildren.js +30 -2
- package/category/actions/fetchCategoryOrRootCategories.js +16 -2
- package/category/actions/fetchCategoryProducts.js +36 -2
- package/category/actions/fetchRootCategories.js +31 -2
- package/category/actions/getCategory.js +10 -2
- package/category/constants/Pipelines.js +3 -1
- package/category/constants/Portals.js +56 -3
- package/category/constants/index.js +17 -2
- package/category/helpers/index.js +27 -3
- package/category/index.js +19 -5
- package/category/mock.js +176 -1
- package/category/reducers/categoriesById.js +65 -3
- package/category/reducers/childrenByCategoryId.js +55 -4
- package/category/reducers/helpers/handleCategoryCollection.js +24 -3
- package/category/reducers/helpers/handleReceivedCategories.js +3 -1
- package/category/reducers/index.js +12 -2
- package/category/reducers/rootCategories.js +31 -2
- package/category/selectors/index.js +115 -16
- package/category/streams/index.js +82 -4
- package/category/subscriptions/index.js +96 -3
- package/checkout/action-creators/successCheckout.js +9 -2
- package/checkout/actions/fetchCheckoutUrl.js +28 -3
- package/checkout/constants/Pipelines.js +1 -1
- package/checkout/constants/index.js +3 -2
- package/checkout/index.js +11 -4
- package/checkout/selectors/index.js +7 -2
- package/checkout/streams/index.js +8 -2
- package/checkout/subscriptions/index.js +35 -6
- package/favorites/action-creators/index.js +206 -24
- package/favorites/actions/addFavorites.js +41 -3
- package/favorites/actions/addFavoritesList.js +27 -2
- package/favorites/actions/fetchFavoriteIds.js +49 -5
- package/favorites/actions/fetchFavorites.js +60 -5
- package/favorites/actions/fetchFavoritesList.js +47 -3
- package/favorites/actions/fetchFavoritesListsWithItems.js +32 -3
- package/favorites/actions/getFavorites.js +6 -2
- package/favorites/actions/removeFavorites.js +32 -3
- package/favorites/actions/removeFavoritesList.js +24 -2
- package/favorites/actions/toggleFavorites.js +68 -10
- package/favorites/actions/updateFavorites.js +39 -3
- package/favorites/actions/updateFavoritesList.js +26 -2
- package/favorites/constants/Pipelines.js +9 -1
- package/favorites/constants/Portals.js +32 -4
- package/favorites/constants/index.js +37 -5
- package/favorites/index.js +14 -4
- package/favorites/mock.js +89 -4
- package/favorites/reducers/index.js +7 -1
- package/favorites/reducers/lists.js +74 -2
- package/favorites/reducers/products.js +231 -24
- package/favorites/selectors/index.js +188 -24
- package/favorites/streams/index.js +135 -23
- package/favorites/streams/spec.js +517 -8
- package/favorites/subscriptions/index.js +260 -25
- package/favorites/subscriptions/spec.js +700 -28
- package/filter/action-creators/errorFilters.js +9 -2
- package/filter/action-creators/index.js +4 -1
- package/filter/action-creators/receiveFilters.js +10 -2
- package/filter/action-creators/requestFilters.js +9 -2
- package/filter/action-creators/updateFilters.js +8 -2
- package/filter/actions/fetchFilters.js +46 -3
- package/filter/actions/getFilters.js +6 -2
- package/filter/actions/helpers/buildFilterParams.js +34 -2
- package/filter/actions/helpers/buildRequestFilters.js +35 -2
- package/filter/actions/helpers/processFilters.js +10 -2
- package/filter/actions/helpers/processParams.js +26 -2
- package/filter/constants/Pipelines.js +1 -1
- package/filter/constants/Portals.js +39 -3
- package/filter/constants/index.js +8 -1
- package/filter/index.js +12 -4
- package/filter/reducers/helpers/enrichFilters.js +11 -3
- package/filter/reducers/index.js +5 -1
- package/filter/reducers/resultsByHash.js +43 -3
- package/filter/selectors/index.js +47 -6
- package/filter/streams/index.js +30 -1
- package/filter/subscriptions/index.js +34 -2
- package/market/constants/Portals.js +22 -4
- package/market/constants/index.js +2 -1
- package/market/helpers/showReturnPolicy.js +3 -1
- package/market/helpers/showTaxDisclaimer.js +3 -1
- package/market/index.js +6 -2
- package/orders/constants.js +2 -1
- package/package.json +4 -4
- package/product/action-creators/deleteProductsByIds.js +10 -2
- package/product/action-creators/errorProduct.js +10 -2
- package/product/action-creators/errorProductDescription.js +10 -2
- package/product/action-creators/errorProductImages.js +10 -2
- package/product/action-creators/errorProductMedia.js +10 -2
- package/product/action-creators/errorProductOptions.js +10 -2
- package/product/action-creators/errorProductProperties.js +10 -2
- package/product/action-creators/errorProductRelations.js +9 -2
- package/product/action-creators/errorProductShipping.js +10 -2
- package/product/action-creators/errorProductVariants.js +10 -2
- package/product/action-creators/errorProducts.js +9 -2
- package/product/action-creators/expireProductById.js +10 -2
- package/product/action-creators/expireProductData.js +11 -2
- package/product/action-creators/expireProductsByHash.js +9 -2
- package/product/action-creators/productNotAvailable.js +10 -2
- package/product/action-creators/provideProduct.js +9 -2
- package/product/action-creators/receiveProduct.js +10 -2
- package/product/action-creators/receiveProductCached.js +9 -2
- package/product/action-creators/receiveProductDescription.js +10 -2
- package/product/action-creators/receiveProductImages.js +10 -2
- package/product/action-creators/receiveProductMedia.js +10 -2
- package/product/action-creators/receiveProductOptions.js +10 -2
- package/product/action-creators/receiveProductProperties.js +10 -2
- package/product/action-creators/receiveProductRelations.js +12 -2
- package/product/action-creators/receiveProductShipping.js +10 -2
- package/product/action-creators/receiveProductVariants.js +10 -2
- package/product/action-creators/receiveProducts.js +16 -2
- package/product/action-creators/receiveProductsCached.js +9 -2
- package/product/action-creators/refreshExpiredPDPData.js +8 -2
- package/product/action-creators/requestProduct.js +10 -2
- package/product/action-creators/requestProductDescription.js +9 -2
- package/product/action-creators/requestProductImages.js +9 -2
- package/product/action-creators/requestProductMedia.js +9 -2
- package/product/action-creators/requestProductOptions.js +9 -2
- package/product/action-creators/requestProductProperties.js +9 -2
- package/product/action-creators/requestProductRelations.js +10 -2
- package/product/action-creators/requestProductShipping.js +9 -2
- package/product/action-creators/requestProductVariants.js +9 -2
- package/product/action-creators/requestProducts.js +9 -2
- package/product/action-creators/setProductId.js +9 -2
- package/product/action-creators/setProductQuantity.js +9 -2
- package/product/action-creators/setProductVariantId.js +9 -2
- package/product/actions/changeSortOrder.js +21 -2
- package/product/actions/fetchHighlightProducts.js +18 -2
- package/product/actions/fetchLiveshoppingProducts.js +14 -2
- package/product/actions/fetchProduct.js +52 -3
- package/product/actions/fetchProductDescription.js +30 -2
- package/product/actions/fetchProductImages.js +31 -2
- package/product/actions/fetchProductMedia.js +35 -2
- package/product/actions/fetchProductOptions.js +31 -2
- package/product/actions/fetchProductProperties.js +30 -2
- package/product/actions/fetchProductRelations.js +63 -2
- package/product/actions/fetchProductShipping.js +31 -2
- package/product/actions/fetchProductVariants.js +31 -2
- package/product/actions/fetchProducts.js +189 -17
- package/product/actions/fetchProductsById.js +68 -8
- package/product/actions/fetchProductsByQuery.js +102 -18
- package/product/actions/getHighlightProducts.js +6 -2
- package/product/actions/getLiveshoppingProducts.js +6 -2
- package/product/actions/getProduct.js +6 -2
- package/product/actions/getProductDescription.js +6 -2
- package/product/actions/getProductImages.js +6 -2
- package/product/actions/getProductOptions.js +6 -2
- package/product/actions/getProductProperties.js +6 -2
- package/product/actions/getProductRelations.js +6 -2
- package/product/actions/getProductShipping.js +6 -2
- package/product/actions/getProductVariants.js +6 -2
- package/product/actions/getProducts.js +6 -2
- package/product/actions/getProductsById.js +6 -2
- package/product/actions/getProductsByQuery.js +6 -2
- package/product/actions/processProductFlags.js +35 -3
- package/product/actions/updateMetadata.js +17 -2
- package/product/collections/ProductImageFormats.js +48 -8
- package/product/collections/index.js +1 -1
- package/product/constants/Pipelines.js +12 -1
- package/product/constants/Portals.js +200 -33
- package/product/constants/index.js +90 -18
- package/product/helpers/index.js +61 -8
- package/product/index.js +36 -6
- package/product/mock.js +1002 -2
- package/product/reducers/descriptionsByProductId.js +54 -5
- package/product/reducers/helpers/formatOptions.js +17 -2
- package/product/reducers/helpers/handleProductCollection.js +19 -2
- package/product/reducers/imagesByProductId.js +51 -4
- package/product/reducers/index.js +23 -1
- package/product/reducers/mediaByProductId.js +55 -3
- package/product/reducers/optionsByProductId.js +41 -2
- package/product/reducers/productRelationsByHash.js +43 -2
- package/product/reducers/productsById.js +122 -7
- package/product/reducers/propertiesByProductId.js +48 -2
- package/product/reducers/resultsByHash.js +125 -9
- package/product/reducers/shippingByProductId.js +37 -2
- package/product/reducers/variantsByProductId.js +56 -2
- package/product/selectors/options.js +90 -13
- package/product/selectors/page.js +62 -13
- package/product/selectors/price.js +81 -18
- package/product/selectors/product.js +549 -59
- package/product/selectors/product.mock.js +327 -12
- package/product/selectors/relations.js +35 -5
- package/product/selectors/variants.js +91 -15
- package/product/streams/index.js +167 -13
- package/product/subscriptions/index.js +210 -4
- package/reviews/action-creators/errorProductReviews.js +9 -2
- package/reviews/action-creators/errorReviews.js +9 -2
- package/reviews/action-creators/errorSubmitReview.js +9 -2
- package/reviews/action-creators/errorUserReview.js +9 -2
- package/reviews/action-creators/flushUserReview.js +8 -2
- package/reviews/action-creators/receiveProductReviews.js +11 -2
- package/reviews/action-creators/receiveReviews.js +12 -2
- package/reviews/action-creators/receiveSubmitReview.js +9 -2
- package/reviews/action-creators/receiveUserReview.js +10 -2
- package/reviews/action-creators/requestProductReviews.js +10 -2
- package/reviews/action-creators/requestReviews.js +9 -2
- package/reviews/action-creators/requestSubmitReview.js +9 -2
- package/reviews/action-creators/requestUserReview.js +9 -2
- package/reviews/action-creators/resetSubmittedReview.js +9 -2
- package/reviews/action-creators/spec.js +40 -1
- package/reviews/actions/fetchProductReviews.js +37 -2
- package/reviews/actions/fetchReviews.js +38 -2
- package/reviews/actions/fetchUserReview.js +31 -2
- package/reviews/actions/flushUserReview.js +5 -1
- package/reviews/actions/getProductReviews.js +6 -2
- package/reviews/actions/getUserReview.js +6 -2
- package/reviews/actions/spec.js +241 -4
- package/reviews/actions/submitReview.js +63 -3
- package/reviews/constants/Pipelines.js +4 -1
- package/reviews/constants/Portals.js +4 -1
- package/reviews/constants/index.js +26 -7
- package/reviews/index.js +15 -4
- package/reviews/mock.js +172 -11
- package/reviews/reducers/index.js +11 -1
- package/reviews/reducers/mock.js +14 -2
- package/reviews/reducers/reviewsByHash.js +52 -6
- package/reviews/reducers/reviewsById.js +27 -2
- package/reviews/reducers/reviewsByProductId.js +47 -2
- package/reviews/reducers/spec.js +211 -2
- package/reviews/reducers/userReviewsByProductId.js +68 -2
- package/reviews/selectors/index.js +123 -19
- package/reviews/selectors/mock.js +100 -1
- package/reviews/selectors/spec.js +100 -1
- package/reviews/streams/index.js +37 -5
- package/reviews/streams/spec.js +25 -1
- package/reviews/subscriptions/index.js +27 -2
- package/scanner/action-creators/errorHandleScanner.js +11 -2
- package/scanner/action-creators/scannerFinished.js +11 -2
- package/scanner/action-creators/startScanner.js +8 -2
- package/scanner/action-creators/successHandleScanner.js +11 -2
- package/scanner/actions/handleBarCode.js +22 -2
- package/scanner/actions/handleNoResults.js +23 -2
- package/scanner/actions/handleQrCode.js +116 -6
- package/scanner/actions/handleSearch.js +33 -2
- package/scanner/constants/Portals.js +22 -1
- package/scanner/constants/index.js +17 -1
- package/scanner/helpers/index.js +115 -5
- package/scanner/index.js +19 -5
- package/scanner/streams/index.js +36 -1
- package/scanner/subscriptions/index.js +78 -8
- package/search/action-creators/errorSearchResults.js +10 -2
- package/search/action-creators/receiveSearchResults.js +11 -2
- package/search/action-creators/receiveSearchSuggestions.js +10 -2
- package/search/action-creators/requestSearchResults.js +10 -2
- package/search/action-creators/requestSearchSuggestions.js +9 -2
- package/search/actions/fetchSearchResults.js +66 -8
- package/search/actions/fetchSearchSuggestions.js +36 -2
- package/search/constants/Pipelines.js +1 -1
- package/search/constants/Portals.js +9 -2
- package/search/constants/index.js +10 -2
- package/search/helpers/index.js +5 -2
- package/search/helpers/removeHighlightingPlaceholders.js +4 -1
- package/search/helpers/spec.js +19 -1
- package/search/index.js +17 -5
- package/search/reducers/index.js +38 -2
- package/search/selectors/index.js +23 -4
- package/search/streams/index.js +51 -3
- package/search/subscriptions/index.js +132 -5
|
@@ -1,15 +1,330 @@
|
|
|
1
|
-
import cloneDeep from'lodash/cloneDeep'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
2
|
+
/* eslint-disable camelcase */
|
|
3
|
+
export const mockedRouterState = {
|
|
4
|
+
currentRoute: null,
|
|
5
|
+
stack: []
|
|
6
|
+
};
|
|
7
|
+
export const mockedProductMetadata = {
|
|
8
|
+
some: 'product metadata'
|
|
9
|
+
};
|
|
10
|
+
export const mockedVariantProductMetadata = {
|
|
11
|
+
some: 'variant product metadata'
|
|
12
|
+
};
|
|
13
|
+
export const mockedProductsById = {
|
|
14
|
+
// Base product with variants
|
|
15
|
+
product_1: {
|
|
16
|
+
isFetching: false,
|
|
17
|
+
productData: {
|
|
18
|
+
id: 'product_1',
|
|
19
|
+
active: true,
|
|
20
|
+
baseProductId: null,
|
|
21
|
+
flags: {
|
|
22
|
+
hasChildren: false,
|
|
23
|
+
hasOptions: false,
|
|
24
|
+
hasVariants: true
|
|
25
|
+
},
|
|
26
|
+
stock: {
|
|
27
|
+
ignoreQuantity: false,
|
|
28
|
+
quantity: 0,
|
|
29
|
+
info: 'Out of stock',
|
|
30
|
+
orderable: false,
|
|
31
|
+
minOrderQuantity: 1,
|
|
32
|
+
maxOrderQuantity: 10000
|
|
33
|
+
},
|
|
34
|
+
metadata: mockedProductMetadata
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
// Variant product of product_1
|
|
38
|
+
product_2: {
|
|
39
|
+
isFetching: false,
|
|
40
|
+
productData: {
|
|
41
|
+
id: 'product_2',
|
|
42
|
+
active: true,
|
|
43
|
+
baseProductId: 'product_1',
|
|
44
|
+
flags: {
|
|
45
|
+
hasChildren: false,
|
|
46
|
+
hasOptions: false,
|
|
47
|
+
hasVariants: false
|
|
48
|
+
},
|
|
49
|
+
stock: {
|
|
50
|
+
ignoreQuantity: true,
|
|
51
|
+
quantity: 200,
|
|
52
|
+
info: 'In stock',
|
|
53
|
+
orderable: true,
|
|
54
|
+
minOrderQuantity: 1,
|
|
55
|
+
maxOrderQuantity: 10000
|
|
56
|
+
},
|
|
57
|
+
metadata: mockedVariantProductMetadata
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
// Variant product of product_1 which is not orderable
|
|
61
|
+
product_3: {
|
|
62
|
+
isFetching: false,
|
|
63
|
+
productData: {
|
|
64
|
+
id: 'product_3',
|
|
65
|
+
active: true,
|
|
66
|
+
baseProductId: 'product_1',
|
|
67
|
+
flags: {
|
|
68
|
+
hasChildren: false,
|
|
69
|
+
hasOptions: false,
|
|
70
|
+
hasVariants: false
|
|
71
|
+
},
|
|
72
|
+
stock: {
|
|
73
|
+
ignoreQuantity: false,
|
|
74
|
+
quantity: 0,
|
|
75
|
+
info: 'Out of stock',
|
|
76
|
+
orderable: false,
|
|
77
|
+
minOrderQuantity: 1,
|
|
78
|
+
maxOrderQuantity: 10000
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
// Currently fetching product
|
|
83
|
+
product_4: {
|
|
84
|
+
isFetching: true,
|
|
85
|
+
productData: null
|
|
86
|
+
},
|
|
87
|
+
// Simple product without variants
|
|
88
|
+
product_5: {
|
|
89
|
+
isFetching: false,
|
|
90
|
+
productData: {
|
|
91
|
+
id: 'product_5',
|
|
92
|
+
active: true,
|
|
93
|
+
baseProductId: null,
|
|
94
|
+
flags: {
|
|
95
|
+
hasChildren: false,
|
|
96
|
+
hasOptions: false,
|
|
97
|
+
hasVariants: false
|
|
98
|
+
},
|
|
99
|
+
name: 'Fancy Product',
|
|
100
|
+
longName: 'Fancy Long Product Name',
|
|
101
|
+
manufacturer: 'ACME',
|
|
102
|
+
price: {
|
|
103
|
+
currency: 'EUR',
|
|
104
|
+
info: '',
|
|
105
|
+
unitPrice: 90,
|
|
106
|
+
unitPriceStriked: 95,
|
|
107
|
+
unitPriceMin: 0,
|
|
108
|
+
unitPriceMax: 0,
|
|
109
|
+
unitPriceNet: 150,
|
|
110
|
+
unitPriceWithTax: 150,
|
|
111
|
+
taxAmount: 0,
|
|
112
|
+
taxPercent: 0,
|
|
113
|
+
msrp: 100,
|
|
114
|
+
tiers: [],
|
|
115
|
+
discount: 10
|
|
116
|
+
},
|
|
117
|
+
rating: {
|
|
118
|
+
count: 2,
|
|
119
|
+
average: 50,
|
|
120
|
+
reviewCount: 2
|
|
121
|
+
},
|
|
122
|
+
stock: {
|
|
123
|
+
ignoreQuantity: true,
|
|
124
|
+
quantity: 200,
|
|
125
|
+
info: 'In stock',
|
|
126
|
+
orderable: true,
|
|
127
|
+
minOrderQuantity: 1,
|
|
128
|
+
maxOrderQuantity: 10000
|
|
129
|
+
},
|
|
130
|
+
availability: {
|
|
131
|
+
text: 'In stock',
|
|
132
|
+
state: 'ok'
|
|
133
|
+
},
|
|
134
|
+
metadata: {
|
|
135
|
+
some: 'metadata'
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
product_7: {
|
|
140
|
+
isFetching: false,
|
|
141
|
+
productData: {
|
|
142
|
+
name: 'Short product name'
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
// Taken from the original getKnownRelatives() selector test for variants.
|
|
146
|
+
parent: {
|
|
147
|
+
productData: {
|
|
148
|
+
id: 'parent',
|
|
149
|
+
baseProductId: null,
|
|
150
|
+
flags: {
|
|
151
|
+
hasVariants: true
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
child: {
|
|
156
|
+
productData: {
|
|
157
|
+
id: 'child',
|
|
158
|
+
baseProductId: 'parent',
|
|
159
|
+
flags: {
|
|
160
|
+
hasVariants: false
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
child2: {
|
|
165
|
+
productData: {
|
|
166
|
+
id: 'child2',
|
|
167
|
+
baseProductId: 'parent',
|
|
168
|
+
flags: {
|
|
169
|
+
hasVariants: false
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
notAChild: {
|
|
174
|
+
productData: {
|
|
175
|
+
id: 'notAChild',
|
|
176
|
+
baseProductId: 'foo',
|
|
177
|
+
flags: {
|
|
178
|
+
hasVariants: false
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
export const mockedShippingByProductId = {
|
|
184
|
+
product_1: {
|
|
185
|
+
isFetching: false,
|
|
186
|
+
shipping: {
|
|
187
|
+
currency: 'EUR',
|
|
188
|
+
price: 499
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
product_5: {
|
|
192
|
+
isFetching: true
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
export const mockedDescriptionsByProductId = {
|
|
196
|
+
product_1: {
|
|
197
|
+
isFetching: false,
|
|
198
|
+
description: 'Lorem ipsum dolor'
|
|
199
|
+
},
|
|
200
|
+
product_5: {
|
|
201
|
+
isFetching: true
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
export const mockedProperty1 = {
|
|
205
|
+
label: 'Article No.',
|
|
206
|
+
value: '9252529931'
|
|
207
|
+
};
|
|
208
|
+
export const mockedProperty2 = {
|
|
209
|
+
label: 'Manufacturer',
|
|
210
|
+
value: 'Nike'
|
|
211
|
+
};
|
|
212
|
+
export const mockedPropertiesByProductId = {
|
|
213
|
+
product_1: {
|
|
214
|
+
isFetching: false,
|
|
215
|
+
properties: [mockedProperty1, mockedProperty2]
|
|
216
|
+
},
|
|
217
|
+
product_5: {
|
|
218
|
+
isFetching: true
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
export const mockedProductImagesBase = ['https://img-cdn.shopgate.com/a43fac2d', 'https://img-cdn.shopgate.com/b543f421'];
|
|
222
|
+
export const mockedProductImagesVariant = ['https://img-cdn.shopgate.com/a43fac2d', 'https://img-cdn.shopgate.com/b543f421'];
|
|
223
|
+
export const mockedImagesByProductId = {
|
|
224
|
+
product_1: {
|
|
225
|
+
isFetching: false,
|
|
226
|
+
images: mockedProductImagesBase
|
|
227
|
+
},
|
|
228
|
+
product_2: {
|
|
229
|
+
isFetching: false,
|
|
230
|
+
images: mockedProductImagesVariant
|
|
231
|
+
},
|
|
232
|
+
product_3: {
|
|
233
|
+
isFetching: false,
|
|
234
|
+
images: []
|
|
235
|
+
},
|
|
236
|
+
product_5: {
|
|
237
|
+
isFetching: true
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
export const mockedVariantMetadata = {
|
|
241
|
+
some: 'variant metadata'
|
|
242
|
+
};
|
|
243
|
+
export const mockedVariantsByProductId = {
|
|
244
|
+
product_1: {
|
|
245
|
+
isFetching: false,
|
|
246
|
+
variants: {
|
|
247
|
+
products: [{
|
|
248
|
+
id: 'product_2',
|
|
249
|
+
characteristics: {
|
|
250
|
+
1: '1'
|
|
251
|
+
},
|
|
252
|
+
availability: {
|
|
253
|
+
text: 'In stock',
|
|
254
|
+
state: 'ok'
|
|
255
|
+
}
|
|
256
|
+
}, {
|
|
257
|
+
id: 'product_3',
|
|
258
|
+
characteristics: {
|
|
259
|
+
1: '2'
|
|
260
|
+
},
|
|
261
|
+
availability: {
|
|
262
|
+
text: 'Only 3 items left',
|
|
263
|
+
state: 'warning'
|
|
264
|
+
},
|
|
265
|
+
metadata: mockedVariantMetadata
|
|
266
|
+
}],
|
|
267
|
+
characteristics: [{
|
|
268
|
+
id: '1',
|
|
269
|
+
label: 'Color',
|
|
270
|
+
values: [{
|
|
271
|
+
id: '1',
|
|
272
|
+
label: 'Black'
|
|
273
|
+
}, {
|
|
274
|
+
id: '2',
|
|
275
|
+
label: 'Green'
|
|
276
|
+
}]
|
|
277
|
+
}]
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
export const mockedState = {
|
|
282
|
+
router: mockedRouterState,
|
|
283
|
+
product: {
|
|
284
|
+
productsById: mockedProductsById,
|
|
285
|
+
shippingByProductId: mockedShippingByProductId,
|
|
286
|
+
descriptionsByProductId: mockedDescriptionsByProductId,
|
|
287
|
+
propertiesByProductId: mockedPropertiesByProductId,
|
|
288
|
+
imagesByProductId: mockedImagesByProductId,
|
|
289
|
+
variantsByProductId: mockedVariantsByProductId,
|
|
290
|
+
optionsByProductId: {}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
/**
|
|
8
295
|
* The following mocked states can be used simplified product variant testing. They mimic the
|
|
9
296
|
* product state in different stages of product data fetching.
|
|
10
297
|
* product_1 is the base product of product_2 and product_2.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export
|
|
15
|
-
|
|
298
|
+
*/
|
|
299
|
+
|
|
300
|
+
// Base product and all its variants are available.
|
|
301
|
+
export const mockedVariantStateComplete = {
|
|
302
|
+
product: {
|
|
303
|
+
productsById: {
|
|
304
|
+
product_1: cloneDeep(mockedState.product.productsById.product_1),
|
|
305
|
+
product_2: cloneDeep(mockedState.product.productsById.product_2),
|
|
306
|
+
product_3: cloneDeep(mockedState.product.productsById.product_3)
|
|
307
|
+
},
|
|
308
|
+
variantsByProductId: mockedVariantsByProductId
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// Everything is fetching.
|
|
313
|
+
export const mockedVariantStateAllFetching = cloneDeep(mockedVariantStateComplete);
|
|
314
|
+
delete mockedVariantStateAllFetching.product.variantsByProductId.product_1;
|
|
315
|
+
delete mockedVariantStateAllFetching.product.productsById.product_1;
|
|
316
|
+
delete mockedVariantStateAllFetching.product.productsById.product_2;
|
|
317
|
+
delete mockedVariantStateAllFetching.product.productsById.product_3;
|
|
318
|
+
|
|
319
|
+
// Base product is available, but variants data and variants ara fetching.
|
|
320
|
+
export const mockedVariantStateVariantDataFetching = cloneDeep(mockedVariantStateComplete);
|
|
321
|
+
delete mockedVariantStateVariantDataFetching.product.variantsByProductId.product_1;
|
|
322
|
+
delete mockedVariantStateVariantDataFetching.product.productsById.product_2;
|
|
323
|
+
delete mockedVariantStateVariantDataFetching.product.productsById.product_3;
|
|
324
|
+
|
|
325
|
+
// Base product and variants data is available, but variants ara fetching.
|
|
326
|
+
export const mockedVariantStateVariantsFetching = cloneDeep(mockedVariantStateComplete);
|
|
327
|
+
delete mockedVariantStateVariantsFetching.product.productsById.product_2;
|
|
328
|
+
delete mockedVariantStateVariantsFetching.product.productsById.product_3;
|
|
329
|
+
|
|
330
|
+
/* eslint-enable camelcase */
|
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
import{createSelector}from'reselect';
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
import { generateProductRelationsHash } from "../helpers";
|
|
3
|
+
import { getProducts } from "./product";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Returns productRelations state.
|
|
3
7
|
* @param {Object} state State.
|
|
4
8
|
* @returns {Object}
|
|
5
9
|
* @deprecated
|
|
6
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
export const getProductRelationsState = state => state.product.productRelationsByHash;
|
|
12
|
+
|
|
13
|
+
/**
|
|
7
14
|
* Factory of a function that returns selector of product relations state for given hash.
|
|
8
15
|
* @param {string} hash State hash.
|
|
9
16
|
* @returns {Function}
|
|
10
17
|
* @deprecated
|
|
11
|
-
*/
|
|
18
|
+
*/
|
|
19
|
+
export const getProductRelationsByHash = hash => createSelector(getProductRelationsState, state => {
|
|
20
|
+
if (state[hash]) {
|
|
21
|
+
return state[hash].productIds;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
12
27
|
* Selector factory.
|
|
13
28
|
* Accepts parameters as arguments. When used within `mapStateToProps` factory won't be called
|
|
14
29
|
* as long as `state` and `props` didn't change (shallow comparison).
|
|
@@ -18,10 +33,25 @@ import{createSelector}from'reselect';import{generateProductRelationsHash}from"..
|
|
|
18
33
|
* @param {number} limit Query limit.
|
|
19
34
|
* @returns {Function} Selector.
|
|
20
35
|
* @deprecated Use `makeGetProductRelations` from `@shopgate/engage/products` instead.
|
|
21
|
-
*/
|
|
36
|
+
*/
|
|
37
|
+
export const getProductRelations = ({
|
|
38
|
+
productId,
|
|
39
|
+
type,
|
|
40
|
+
limit
|
|
41
|
+
}) => state => {
|
|
42
|
+
const hash = generateProductRelationsHash({
|
|
43
|
+
productId,
|
|
44
|
+
type,
|
|
45
|
+
limit
|
|
46
|
+
});
|
|
47
|
+
return getProductRelationsByHash(hash)(state);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
22
51
|
* Returns products data for product id.
|
|
23
52
|
*
|
|
24
53
|
* @param {Object} params Params, see `.getProductRelations`
|
|
25
54
|
* @returns {Array}
|
|
26
55
|
* @deprecated Use `makeGetRelatedProducts` from `@shopgate/engage/products` instead.
|
|
27
|
-
*/
|
|
56
|
+
*/
|
|
57
|
+
export const getRelatedProducts = params => createSelector(getProductRelations(params), getProducts, (relations = [], productsById) => relations.filter(id => productsById[id] && productsById[id].productData).map(id => productsById[id].productData));
|
|
@@ -1,29 +1,105 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "core-js/modules/es.regexp.flags.js";
|
|
2
|
+
import { createSelector } from 'reselect';
|
|
3
|
+
import { getProducts, getProductById, getProductVariants, hasBaseProductVariants, isVariantSelected, getSelectedVariant, getVariantProductId } from "./product";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Retrieves the metadata from the product data within the variants.
|
|
3
7
|
* @param {Object} state The current application state.
|
|
4
8
|
* @param {Object} props The component props.
|
|
5
9
|
* @return {Object|null}
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
*/
|
|
11
|
+
export const getSelectedVariantMetadata = createSelector(getProductVariants, getSelectedVariant, getVariantProductId, (variants, variant, variantId) => {
|
|
12
|
+
if (!variants && !variant) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
// Prefer variant data, if available
|
|
16
|
+
if (variants && variantId !== null) {
|
|
17
|
+
// Get the product data of the selected product from the variants.
|
|
18
|
+
const {
|
|
19
|
+
metadata
|
|
20
|
+
} = variants.products.find(({
|
|
21
|
+
id
|
|
22
|
+
}) => id === variantId) || {};
|
|
23
|
+
if (metadata) {
|
|
24
|
+
return metadata;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Check if variant data is available in product list
|
|
29
|
+
// istanbul ignore else
|
|
30
|
+
if (variant) {
|
|
31
|
+
return variant.metadata;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* This statement should never be reached since getProductVariants will not return data when the
|
|
36
|
+
* variant product entity can't be found to determine a baseProductId.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
// istanbul ignore next
|
|
40
|
+
return null;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/**
|
|
15
44
|
* Matches all products relatives which are already fetched and stored in redux.
|
|
16
45
|
* If this ever would be too slow, the calculation should happen in the reducer.
|
|
17
46
|
* @param {Object} state Current state.
|
|
18
47
|
* @returns {Object}
|
|
19
|
-
*/
|
|
20
|
-
|
|
48
|
+
*/
|
|
49
|
+
export const getKnownProductRelatives = createSelector([getProducts], products => {
|
|
50
|
+
const relativesByBaseProductId = {};
|
|
51
|
+
Object.keys(products).forEach(id => {
|
|
52
|
+
if (!products[id].productData) {
|
|
53
|
+
// It's possible that product has no data yet. Skip it then.
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const {
|
|
57
|
+
productData
|
|
58
|
+
} = products[id];
|
|
59
|
+
let parentId = productData.id;
|
|
60
|
+
if (productData.baseProductId) {
|
|
61
|
+
parentId = productData.baseProductId;
|
|
62
|
+
}
|
|
63
|
+
if (!relativesByBaseProductId[parentId]) {
|
|
64
|
+
relativesByBaseProductId[parentId] = [];
|
|
65
|
+
}
|
|
66
|
+
relativesByBaseProductId[parentId].push(productData.id);
|
|
67
|
+
if (parentId !== productData.id && !relativesByBaseProductId[parentId].includes(parentId)) {
|
|
68
|
+
relativesByBaseProductId[parentId].push(parentId);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return relativesByBaseProductId;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
21
75
|
* Returns relatives which are already fetched into a client app for given product id.
|
|
22
76
|
* @param {Object} state Current state.
|
|
23
77
|
* @param {string} productId Product id.
|
|
24
78
|
* @returns {Array}
|
|
25
|
-
*/
|
|
26
|
-
|
|
79
|
+
*/
|
|
80
|
+
export const getKnownRelatives = createSelector(getProductById, getKnownProductRelatives, (product, knownRelations) => {
|
|
81
|
+
if (!product) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
const {
|
|
85
|
+
productData
|
|
86
|
+
} = product;
|
|
87
|
+
let parentId = productData.id;
|
|
88
|
+
// Product is parent.
|
|
89
|
+
if (productData.flags.hasVariants) {
|
|
90
|
+
parentId = productData.id;
|
|
91
|
+
} else if (productData.baseProductId) {
|
|
92
|
+
parentId = productData.baseProductId;
|
|
93
|
+
}
|
|
94
|
+
return knownRelations[parentId] || [];
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
/**
|
|
27
98
|
* Selector mappings for PWA < 6.0
|
|
28
99
|
* @deprecated
|
|
29
|
-
*/
|
|
100
|
+
*/
|
|
101
|
+
export const getCurrentProductVariantId = getVariantProductId;
|
|
102
|
+
export const hasCurrentProductVariants = hasBaseProductVariants;
|
|
103
|
+
export const isProductChildrenSelected = isVariantSelected;
|
|
104
|
+
export const getVariantsByProductId = getProductVariants;
|
|
105
|
+
export const getCurrentBaseProductVariants = getProductVariants;
|