@shopgate/pwa-common-commerce 7.30.0-alpha.7 → 7.30.0-alpha.8
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 +701 -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 +3 -3
- 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
package/cart/index.js
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
// ACTIONS
|
|
2
|
-
export{default as addCouponsToCart
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
2
|
+
export { default as addCouponsToCart } from "./actions/addCouponsToCart";
|
|
3
|
+
export { default as addProductsToCart } from "./actions/addProductsToCart";
|
|
4
|
+
export { default as deleteCouponsFromCart } from "./actions/deleteCouponsFromCart";
|
|
5
|
+
export { default as deleteProductsFromCart } from "./actions/deleteProductsFromCart";
|
|
6
|
+
export { default as fetchCart } from "./actions/fetchCart";
|
|
7
|
+
export { default as updateProductsInCart } from "./actions/updateProductsInCart";
|
|
8
|
+
|
|
9
|
+
// CONSTANTS
|
|
10
|
+
export * from "./constants/index";
|
|
11
|
+
export * from "./constants/PipelineErrors";
|
|
12
|
+
export * from "./constants/Pipelines";
|
|
13
|
+
export * from "./constants/Portals";
|
|
14
|
+
|
|
15
|
+
// HELPERS
|
|
16
|
+
export * from "./helpers";
|
|
17
|
+
export * from "./helpers/config";
|
|
18
|
+
export { default as createPipelineErrorList } from "./helpers/createPipelineErrorList";
|
|
19
|
+
export * from "./helpers/shipping";
|
|
20
|
+
export * from "./helpers/tax";
|
|
21
|
+
|
|
22
|
+
// SELECTORS
|
|
23
|
+
export * from "./selectors";
|
|
24
|
+
|
|
25
|
+
// STREAMS
|
|
26
|
+
export * from "./streams";
|
package/cart/mock.js
CHANGED
|
@@ -1 +1,130 @@
|
|
|
1
|
-
|
|
1
|
+
const emptyState = {
|
|
2
|
+
cart: {
|
|
3
|
+
items: [],
|
|
4
|
+
totals: [{
|
|
5
|
+
label: null,
|
|
6
|
+
amount: 0,
|
|
7
|
+
type: 'subTotal'
|
|
8
|
+
}, {
|
|
9
|
+
label: null,
|
|
10
|
+
amount: 0,
|
|
11
|
+
type: 'grandTotal'
|
|
12
|
+
}],
|
|
13
|
+
productPendingCount: 0,
|
|
14
|
+
flags: {
|
|
15
|
+
orderable: true,
|
|
16
|
+
taxIncluded: false,
|
|
17
|
+
coupons: true
|
|
18
|
+
},
|
|
19
|
+
isFetching: false,
|
|
20
|
+
expires: 0,
|
|
21
|
+
isOrderable: true,
|
|
22
|
+
isTaxIncluded: false,
|
|
23
|
+
currency: 'USD',
|
|
24
|
+
messages: [],
|
|
25
|
+
text: {
|
|
26
|
+
legalText: 'By placing your order you agree to our <b><u>Privacy Policy</u></b> and our <b><u>Terms and Conditions</u></b>.',
|
|
27
|
+
legalInfo: ''
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
view: {
|
|
31
|
+
isLoading: false
|
|
32
|
+
},
|
|
33
|
+
client: {
|
|
34
|
+
device: {
|
|
35
|
+
locale: 'de',
|
|
36
|
+
model: 'Redmi Note 4',
|
|
37
|
+
os: {
|
|
38
|
+
apiLevel: '23',
|
|
39
|
+
platform: 'android',
|
|
40
|
+
ver: '6.0'
|
|
41
|
+
},
|
|
42
|
+
type: 'phone'
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
router: {
|
|
46
|
+
routing: false,
|
|
47
|
+
stack: [{
|
|
48
|
+
id: '82588781-089a-46bc-8174-7cebfae12d95',
|
|
49
|
+
params: {},
|
|
50
|
+
pathname: '/',
|
|
51
|
+
pattern: '/',
|
|
52
|
+
query: {},
|
|
53
|
+
state: {}
|
|
54
|
+
}, {
|
|
55
|
+
id: '834a9c2f-c94d-441d-aba5-446a7895d724',
|
|
56
|
+
params: {},
|
|
57
|
+
pathname: '/cart',
|
|
58
|
+
pattern: '/cart',
|
|
59
|
+
query: {},
|
|
60
|
+
state: {
|
|
61
|
+
title: 'Shopping cart'
|
|
62
|
+
}
|
|
63
|
+
}]
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const products = [{
|
|
67
|
+
id: '123',
|
|
68
|
+
quantity: 1,
|
|
69
|
+
type: 'product',
|
|
70
|
+
product: {
|
|
71
|
+
id: 'test_product',
|
|
72
|
+
name: 'Test Product',
|
|
73
|
+
featuredImageBaseUrl: 'https://img-cdn.shopgate.com/30794/1/d11b2e01b66f7a505fbd98b6ed7463c092aeaebae11ee8bec20ffc13344297fa',
|
|
74
|
+
featuredImageUrl: 'https://img-cdn.shopgate.com/30794/1/d11b2e01b66f7a505fbd98b6ed7463c092aeaebae11ee8bec20ffc13344297fa',
|
|
75
|
+
price: {
|
|
76
|
+
unit: 20,
|
|
77
|
+
default: 20,
|
|
78
|
+
special: null
|
|
79
|
+
},
|
|
80
|
+
properties: [{
|
|
81
|
+
label: 'Weight',
|
|
82
|
+
value: '15kg'
|
|
83
|
+
}],
|
|
84
|
+
appliedDiscounts: []
|
|
85
|
+
},
|
|
86
|
+
coupon: null,
|
|
87
|
+
messages: []
|
|
88
|
+
}];
|
|
89
|
+
const coupon = {
|
|
90
|
+
id: '234',
|
|
91
|
+
quantity: 1,
|
|
92
|
+
type: 'coupon',
|
|
93
|
+
coupon: {
|
|
94
|
+
code: 'FOREVER',
|
|
95
|
+
description: null,
|
|
96
|
+
label: 'Coupon',
|
|
97
|
+
savedPrice: {
|
|
98
|
+
value: 5,
|
|
99
|
+
type: 'fixed'
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
messages: [],
|
|
103
|
+
product: null
|
|
104
|
+
};
|
|
105
|
+
const cartState = {
|
|
106
|
+
...emptyState,
|
|
107
|
+
...{
|
|
108
|
+
cart: {
|
|
109
|
+
...emptyState.cart,
|
|
110
|
+
items: products
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const couponState = {
|
|
115
|
+
...emptyState,
|
|
116
|
+
...{
|
|
117
|
+
cart: {
|
|
118
|
+
...emptyState.cart,
|
|
119
|
+
items: [...products, {
|
|
120
|
+
...coupon
|
|
121
|
+
}]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const uiState = {
|
|
126
|
+
ui: {
|
|
127
|
+
general: {}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
export { uiState, emptyState, cartState, couponState };
|
|
@@ -1,6 +1,34 @@
|
|
|
1
|
-
import{produce}from'immer';
|
|
1
|
+
import { produce } from 'immer';
|
|
2
|
+
import { SET_COUPON_FIELD_VALUE, SET_COUPON_FIELD_ERROR } from "../constants";
|
|
3
|
+
const defaultState = {
|
|
4
|
+
error: '',
|
|
5
|
+
value: ''
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* The reducer for all checkout related state.
|
|
3
10
|
* @param {Object} state The application state.
|
|
4
11
|
* @param {Object} action The redux action.
|
|
5
12
|
* @returns {Object}
|
|
6
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
export default (state = defaultState, action) => {
|
|
15
|
+
/* eslint-disable no-param-reassign */
|
|
16
|
+
const producer = produce(draft => {
|
|
17
|
+
switch (action.type) {
|
|
18
|
+
case SET_COUPON_FIELD_VALUE:
|
|
19
|
+
{
|
|
20
|
+
draft.value = action.value;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case SET_COUPON_FIELD_ERROR:
|
|
24
|
+
{
|
|
25
|
+
draft.error = action.message;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
default:
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
/* eslint-enable no-param-reassign */
|
|
33
|
+
return producer(state);
|
|
34
|
+
};
|
package/cart/reducers/data.js
CHANGED
|
@@ -1,11 +1,103 @@
|
|
|
1
|
-
|
|
1
|
+
import "core-js/modules/es.regexp.flags.js";
|
|
2
|
+
import remove from 'lodash/remove';
|
|
3
|
+
import { ADD_PRODUCTS_TO_CART, DELETE_PRODUCTS_FROM_CART, UPDATE_PRODUCTS_IN_CART, ERROR_ADD_PRODUCTS_TO_CART, REQUEST_CART, RECEIVE_CART, ERROR_CART, SET_CART_PENDING_PRODUCT_COUNT, SET_FULFILLMENT_SLOT } from "../constants";
|
|
4
|
+
const defaultState = {
|
|
5
|
+
items: [],
|
|
6
|
+
totals: [],
|
|
7
|
+
productPendingCount: 0,
|
|
8
|
+
flags: {},
|
|
9
|
+
activeFulfillmentSlot: null
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
2
13
|
* Stores all the cart items.
|
|
3
14
|
* The cart will be cached in localStorage as defined in './library/store/configureStore.js'.
|
|
4
15
|
* @param {Object} [state] The current state.
|
|
5
16
|
* @param {Object} action The action object.
|
|
6
17
|
* @return {Object} The new state.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
18
|
+
*/
|
|
19
|
+
export default (state = defaultState, action) => {
|
|
20
|
+
switch (action.type) {
|
|
21
|
+
case ADD_PRODUCTS_TO_CART:
|
|
22
|
+
case ERROR_ADD_PRODUCTS_TO_CART:
|
|
23
|
+
{
|
|
24
|
+
return state;
|
|
25
|
+
}
|
|
26
|
+
case DELETE_PRODUCTS_FROM_CART:
|
|
27
|
+
{
|
|
28
|
+
return {
|
|
29
|
+
...state,
|
|
30
|
+
items: remove(state.items, item => !action.cartItemIds.includes(item.id))
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
case UPDATE_PRODUCTS_IN_CART:
|
|
34
|
+
{
|
|
35
|
+
return {
|
|
36
|
+
...state,
|
|
37
|
+
items: state.items.map(item => {
|
|
38
|
+
const {
|
|
39
|
+
updateData
|
|
40
|
+
} = action;
|
|
41
|
+
// Search the stored cart item, which shall be updated
|
|
42
|
+
const match = updateData.find(update => item.id === update.cartItemId);
|
|
43
|
+
|
|
44
|
+
// Apply the updated quantity to the cart item in the store.
|
|
45
|
+
return {
|
|
46
|
+
...item,
|
|
47
|
+
...(typeof match !== 'undefined' && typeof match.quantity !== 'undefined' && {
|
|
48
|
+
quantity: match.quantity
|
|
49
|
+
}),
|
|
50
|
+
...(typeof match !== 'undefined' && typeof match.substitutionAllowed !== 'undefined' && {
|
|
51
|
+
substitutionAllowed: match.substitutionAllowed
|
|
52
|
+
})
|
|
53
|
+
};
|
|
54
|
+
})
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
case REQUEST_CART:
|
|
58
|
+
{
|
|
59
|
+
return {
|
|
60
|
+
...state,
|
|
61
|
+
isFetching: true,
|
|
62
|
+
expires: 0
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
case RECEIVE_CART:
|
|
66
|
+
{
|
|
67
|
+
const {
|
|
68
|
+
cartItems,
|
|
69
|
+
...cart
|
|
70
|
+
} = action.cart;
|
|
71
|
+
return {
|
|
72
|
+
...state,
|
|
73
|
+
...cart,
|
|
74
|
+
// Map cart flags to properties on root level to establish compatibility with getCart
|
|
75
|
+
// pipelines that don't return "isOrderable" and "isTaxIncluded" flags
|
|
76
|
+
isOrderable: cart?.flags?.orderable ?? true,
|
|
77
|
+
isTaxIncluded: cart?.flags?.taxIncluded ?? true,
|
|
78
|
+
expires: 0,
|
|
79
|
+
items: cartItems,
|
|
80
|
+
isFetching: false,
|
|
81
|
+
productPendingCount: 0
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
case ERROR_CART:
|
|
85
|
+
return {
|
|
86
|
+
...state,
|
|
87
|
+
isFetching: false,
|
|
88
|
+
expires: 0
|
|
89
|
+
};
|
|
90
|
+
case SET_CART_PENDING_PRODUCT_COUNT:
|
|
91
|
+
return {
|
|
92
|
+
...state,
|
|
93
|
+
productPendingCount: Math.max(0, action.count)
|
|
94
|
+
};
|
|
95
|
+
case SET_FULFILLMENT_SLOT:
|
|
96
|
+
return {
|
|
97
|
+
...state,
|
|
98
|
+
activeFulfillmentSlot: action.fulfillmentSlot
|
|
99
|
+
};
|
|
100
|
+
default:
|
|
101
|
+
return state;
|
|
102
|
+
}
|
|
103
|
+
};
|
package/cart/reducers/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import{combineReducers}from'redux';
|
|
1
|
+
import { combineReducers } from 'redux';
|
|
2
|
+
import data from "./data";
|
|
3
|
+
import couponField from "./couponField";
|
|
4
|
+
export default combineReducers({
|
|
5
|
+
data,
|
|
6
|
+
couponField
|
|
7
|
+
});
|
package/cart/selectors/index.js
CHANGED
|
@@ -1,105 +1,255 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "core-js/modules/es.array.reduce.js";
|
|
2
|
+
import "core-js/modules/es.regexp.flags.js";
|
|
3
|
+
import { createSelector } from 'reselect';
|
|
4
|
+
import { getBaseProductMetadata } from "../../product/selectors/product";
|
|
5
|
+
import { getSelectedVariantMetadata } from "../../product/selectors/variants";
|
|
6
|
+
import { getRawProductOptions, hasProductOptions, areProductOptionsSet } from "../../product/selectors/options";
|
|
7
|
+
import { CART_ITEM_TYPE_PRODUCT, CART_ITEM_TYPE_COUPON, CART_TOTALS_TYPE_SUB, CART_TOTALS_TYPE_GRAND, CART_TOTALS_TYPE_DISCOUNT, CART_TOTALS_TYPE_SHIPPING, CART_TOTALS_TYPE_TAX } from "../constants";
|
|
8
|
+
import { getDisplayedProductQuantity } from "../helpers/quantity";
|
|
9
|
+
|
|
10
|
+
/**
|
|
2
11
|
* Selects the coupon field data from the store.
|
|
3
12
|
* @param {Object} state The current state.
|
|
4
13
|
* @return {Object}
|
|
5
|
-
*/
|
|
14
|
+
*/
|
|
15
|
+
const getCouponField = state => state.cart.couponField;
|
|
16
|
+
|
|
17
|
+
/**
|
|
6
18
|
* Selects the cart data from the store.
|
|
7
19
|
* @param {Object} state The current state.
|
|
8
20
|
* @return {Object}
|
|
9
|
-
*/
|
|
21
|
+
*/
|
|
22
|
+
export const getCart = state => state.cart.data;
|
|
23
|
+
|
|
24
|
+
/**
|
|
10
25
|
* Selects the cartItems from the current cart in the state.
|
|
11
26
|
* @param {Object} state The current state.
|
|
12
27
|
* @return {Array} The cartItems.
|
|
13
|
-
*/
|
|
28
|
+
*/
|
|
29
|
+
const cartItemsSelector = state => state.cart.data.items;
|
|
30
|
+
|
|
31
|
+
/**
|
|
14
32
|
* Selects the total amounts stack from the cart data.
|
|
15
33
|
* @param {Object} state The current application state.
|
|
16
34
|
* @return {Object} The total amount stack.
|
|
17
|
-
*/
|
|
35
|
+
*/
|
|
36
|
+
const getTotals = createSelector(getCart, cart => cart.totals);
|
|
37
|
+
|
|
38
|
+
/**
|
|
18
39
|
* Selects all items from the cart.
|
|
19
40
|
* @param {Object} state The current state.
|
|
20
41
|
* @return {Array} The cart items.
|
|
21
|
-
*/
|
|
42
|
+
*/
|
|
43
|
+
export const getCartItems = createSelector(cartItemsSelector, cartItems => cartItems);
|
|
44
|
+
|
|
45
|
+
/**
|
|
22
46
|
* Selects the cartItem of the given Id.
|
|
23
47
|
* @param {Object} state The current state.
|
|
24
48
|
* @param {string} params.cartItemId Id of the cartItem.
|
|
25
49
|
* @return {Array} The cart items.
|
|
26
|
-
*/
|
|
50
|
+
*/
|
|
51
|
+
export const getCartItemById = createSelector((state, {
|
|
52
|
+
cartItemId
|
|
53
|
+
}) => cartItemId, getCartItems, (cartItemId, cartItems) => cartItems.find(({
|
|
54
|
+
id
|
|
55
|
+
}) => id === cartItemId) || null);
|
|
56
|
+
|
|
57
|
+
/**
|
|
27
58
|
* Selects the products from the cart.
|
|
28
59
|
* @param {Object} state The current state.
|
|
29
60
|
* @return {Object[]} The cart products.
|
|
30
|
-
*/
|
|
61
|
+
*/
|
|
62
|
+
export const getCartProducts = createSelector(cartItemsSelector, cartItems => cartItems.filter(item => item.type === CART_ITEM_TYPE_PRODUCT));
|
|
63
|
+
|
|
64
|
+
/**
|
|
31
65
|
* Selects the coupons from the cart.
|
|
32
66
|
* @param {Object} state The current state.
|
|
33
67
|
* @return {Array} The cart coupons.
|
|
34
|
-
*/
|
|
68
|
+
*/
|
|
69
|
+
export const getCartCoupons = createSelector(cartItemsSelector, cartItems => cartItems.filter(item => item.type === CART_ITEM_TYPE_COUPON));
|
|
70
|
+
|
|
71
|
+
/**
|
|
35
72
|
* Calculates the current number of product in the cart.
|
|
36
73
|
* @param {Object} state The current state.
|
|
37
74
|
* @return {number} The current number of products within the cart.
|
|
38
|
-
*/
|
|
39
|
-
|
|
75
|
+
*/
|
|
76
|
+
export const getCartProductCount = createSelector(cartItemsSelector, cartItems => cartItems?.reduce((count, cartItem) => {
|
|
77
|
+
// We don't count coupons etc.
|
|
78
|
+
if (cartItem.type !== CART_ITEM_TYPE_PRODUCT) {
|
|
79
|
+
return count;
|
|
80
|
+
}
|
|
81
|
+
return count + getDisplayedProductQuantity(cartItem);
|
|
82
|
+
}, 0) || 0);
|
|
83
|
+
|
|
84
|
+
/**
|
|
40
85
|
* Selects the pending product count from the cart.
|
|
41
86
|
* @param {Object} state The current application state.
|
|
42
87
|
* @return {number}
|
|
43
|
-
*/
|
|
88
|
+
*/
|
|
89
|
+
export const getProductPendingCount = createSelector(getCart, cart => cart.productPendingCount);
|
|
90
|
+
|
|
91
|
+
/**
|
|
44
92
|
* Selects the total, theoretical, number of products in the cart.
|
|
45
93
|
* @param {Object} state The current application state.
|
|
46
94
|
* @return {number}
|
|
47
|
-
*/
|
|
95
|
+
*/
|
|
96
|
+
export const getCartProductDisplayCount = createSelector(getCartProductCount, getProductPendingCount, (productCount, pendingCount) => productCount + pendingCount);
|
|
97
|
+
|
|
98
|
+
/**
|
|
48
99
|
* Selects the orderable status from the cart data.
|
|
49
100
|
* @param {Object} state The current application state.
|
|
50
101
|
* @return {boolean}
|
|
51
|
-
*/
|
|
102
|
+
*/
|
|
103
|
+
export const getOrderableStatus = createSelector(getCart, cart => cart.isOrderable);
|
|
104
|
+
|
|
105
|
+
/**
|
|
52
106
|
* Selects the currency from the cart data.
|
|
53
107
|
* @param {Object} state The current application state.
|
|
54
108
|
* @return {string}
|
|
55
|
-
*/
|
|
109
|
+
*/
|
|
110
|
+
export const getCurrency = createSelector(getCart, cart => cart.currency);
|
|
111
|
+
|
|
112
|
+
/**
|
|
56
113
|
* Selects the sub total.
|
|
57
114
|
* @param {Object} state The current application state.
|
|
58
115
|
* @return {string}
|
|
59
|
-
*/
|
|
116
|
+
*/
|
|
117
|
+
export const getSubTotal = createSelector(getTotals, totals => {
|
|
118
|
+
const {
|
|
119
|
+
amount = 0
|
|
120
|
+
} = totals.find(total => total.type === CART_TOTALS_TYPE_SUB) || {};
|
|
121
|
+
return amount;
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
/**
|
|
60
125
|
* Selects the grand total.
|
|
61
126
|
* @param {Object} state The current application state.
|
|
62
127
|
* @returns {number}
|
|
63
|
-
*/
|
|
128
|
+
*/
|
|
129
|
+
export const getGrandTotal = createSelector(getTotals, totals => {
|
|
130
|
+
const {
|
|
131
|
+
amount = 0
|
|
132
|
+
} = totals.find(total => total.type === CART_TOTALS_TYPE_GRAND) || {};
|
|
133
|
+
return amount;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
/**
|
|
64
137
|
* Selects the grand total data.
|
|
65
138
|
* @param {Object} state The current application state.
|
|
66
139
|
* @returns {number}
|
|
67
|
-
*/
|
|
140
|
+
*/
|
|
141
|
+
export const getGrandTotalData = createSelector(getTotals, totals => {
|
|
142
|
+
const totalData = totals.find(total => total.type === CART_TOTALS_TYPE_GRAND) || null;
|
|
143
|
+
return totalData;
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
/**
|
|
68
147
|
* Selects the shipping costs.
|
|
69
148
|
* @returns {Object|null}
|
|
70
|
-
*/
|
|
149
|
+
*/
|
|
150
|
+
export const getShippingCost = createSelector(getTotals, totals => totals.find(total => total.type === CART_TOTALS_TYPE_SHIPPING) || null);
|
|
151
|
+
|
|
152
|
+
/**
|
|
71
153
|
* Selects the summed up shipping costs of the cart.
|
|
72
154
|
* @returns {number}
|
|
73
|
-
*/
|
|
155
|
+
*/
|
|
156
|
+
export const getShippingCosts = createSelector(getShippingCost, shippingCost => {
|
|
157
|
+
if (!shippingCost) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
const {
|
|
161
|
+
amount = 0
|
|
162
|
+
} = shippingCost;
|
|
163
|
+
return amount;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
/**
|
|
74
167
|
* Selects the tax value of the cart.
|
|
75
168
|
* @returns {Object}
|
|
76
|
-
*/
|
|
169
|
+
*/
|
|
170
|
+
export const getTax = createSelector(getTotals, totals => totals.find(total => total.type === CART_TOTALS_TYPE_TAX) || null);
|
|
171
|
+
|
|
172
|
+
/**
|
|
77
173
|
* Selects applied discounts from the total amounts stack.
|
|
78
174
|
* @param {Object} state The current application state.
|
|
79
175
|
* @return {Object[]|null}
|
|
80
|
-
*/
|
|
176
|
+
*/
|
|
177
|
+
export const getDiscounts = createSelector(getTotals, totals => {
|
|
178
|
+
const discounts = totals.filter(total => total.type === CART_TOTALS_TYPE_DISCOUNT);
|
|
179
|
+
return discounts.length ? discounts : null;
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
/**
|
|
81
183
|
* Selects the discounts value of the cart.
|
|
82
184
|
* @returns {number}
|
|
83
|
-
*/
|
|
185
|
+
*/
|
|
186
|
+
export const getDiscountsAmount = createSelector(getDiscounts, discounts => {
|
|
187
|
+
if (!discounts) {
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
return discounts.reduce((acc, d) => acc + d.amount, 0);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/**
|
|
84
194
|
* Selects the received messages from the cart.
|
|
85
195
|
* @param {Object} state The current application state.
|
|
86
196
|
* @return {Array}
|
|
87
|
-
*/
|
|
197
|
+
*/
|
|
198
|
+
export const getCartMessages = createSelector(getCart, cart => cart.messages);
|
|
199
|
+
|
|
200
|
+
/**
|
|
88
201
|
* Selects the cart flags from the cart data.
|
|
89
202
|
* @return {Object}
|
|
90
|
-
*/
|
|
203
|
+
*/
|
|
204
|
+
export const getFlags = createSelector(getCart, ({
|
|
205
|
+
flags
|
|
206
|
+
}) => flags || {});
|
|
207
|
+
|
|
208
|
+
/**
|
|
91
209
|
* Builds the data for the 'options' property of addProductsToCart pipeline request payload.
|
|
92
210
|
* @param {Object} state The application state.
|
|
93
211
|
* @returns {Object|null} The data if it was determinable, otherwise NULL.
|
|
94
|
-
*/
|
|
95
|
-
|
|
96
|
-
|
|
212
|
+
*/
|
|
213
|
+
export const getAddToCartOptions = createSelector(hasProductOptions, areProductOptionsSet, getRawProductOptions, (state, props) => props.options, (hasOptions, areOptionsSet, options, currentOptions) => {
|
|
214
|
+
// Check if options are ready to be added to a pipeline request.
|
|
215
|
+
if (!hasOptions || !areOptionsSet) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Create the data structure.
|
|
220
|
+
return Object.keys(currentOptions).map(id => {
|
|
221
|
+
const value = currentOptions[id];
|
|
222
|
+
const {
|
|
223
|
+
type
|
|
224
|
+
} = options.find(option => option.id === id);
|
|
225
|
+
return {
|
|
226
|
+
type,
|
|
227
|
+
id,
|
|
228
|
+
value
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
/**
|
|
97
234
|
* Builds the data for the 'metadata' property of addProductsToCart pipeline request payload.
|
|
98
235
|
* @returns {Object|null} The data if it was determinable, otherwise NULL.
|
|
99
|
-
*/
|
|
236
|
+
*/
|
|
237
|
+
export const getAddToCartMetadata = createSelector(getSelectedVariantMetadata, getBaseProductMetadata, (variantMetadata, baseProductMetadata) => variantMetadata || baseProductMetadata || null);
|
|
238
|
+
|
|
239
|
+
/**
|
|
100
240
|
* Checks if the cart supports redemption of coupons.
|
|
101
241
|
* @return {boolean}
|
|
102
|
-
*/
|
|
242
|
+
*/
|
|
243
|
+
export const hasCouponSupport = createSelector(getFlags, ({
|
|
244
|
+
coupons
|
|
245
|
+
}) => typeof coupons === 'boolean' ? coupons : true);
|
|
246
|
+
|
|
247
|
+
/**
|
|
103
248
|
* Checks if the cart is fetching
|
|
104
249
|
* @return {boolean}
|
|
105
|
-
*/
|
|
250
|
+
*/
|
|
251
|
+
export const getIsFetching = createSelector(getCart, ({
|
|
252
|
+
isFetching
|
|
253
|
+
}) => isFetching || false);
|
|
254
|
+
export const getCouponFieldError = createSelector(getCouponField, data => data?.error || '');
|
|
255
|
+
export const getCouponFieldValue = createSelector(getCouponField, data => data?.value || '');
|