@shopgate/pwa-common-commerce 7.30.0-alpha.6 → 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
|
@@ -1,16 +1,60 @@
|
|
|
1
|
-
import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';
|
|
1
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
2
|
+
import { PROCESS_LAST } from '@shopgate/pwa-core/constants/ProcessTypes';
|
|
3
|
+
import { mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
4
|
+
import { PIPELINES } from '@shopgate/pwa-common/constants/Configuration';
|
|
5
|
+
import configuration from '@shopgate/pwa-common/collections/Configuration';
|
|
6
|
+
import { SHOPGATE_CART_GET_CART } from "../constants/Pipelines";
|
|
7
|
+
import receiveCart from "../action-creators/receiveCart";
|
|
8
|
+
import requestCart from "../action-creators/requestCart";
|
|
9
|
+
import errorCart from "../action-creators/errorCart";
|
|
10
|
+
import { getIsFetching } from "../selectors/index";
|
|
11
|
+
|
|
12
|
+
/**
|
|
2
13
|
* Get the current cart of the user. The promise resolves with "undefined" when the fetch was
|
|
3
14
|
* blocked by a dependency.
|
|
4
15
|
* @return {Function} A redux thunk.
|
|
5
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
function fetchCart() {
|
|
18
|
+
return (dispatch, getState) => {
|
|
19
|
+
const {
|
|
20
|
+
[SHOPGATE_CART_GET_CART]: pipeline = SHOPGATE_CART_GET_CART
|
|
21
|
+
} = configuration.get(PIPELINES, {});
|
|
22
|
+
const request = new PipelineRequest(pipeline).setResponseProcessed(PROCESS_LAST);
|
|
23
|
+
|
|
24
|
+
/**
|
|
6
25
|
* To avoid unnecessarily dispatched getCart requests, the request is only sent when
|
|
7
26
|
* no cart modifying requests are currently running.
|
|
8
27
|
* If any of the dependencies change the cart, they need to fetch the new data afterwards.
|
|
9
28
|
* The getCart action is not a dependency to itself, so sending out a getCart while another one
|
|
10
29
|
* is running is a valid case, because this pipeline is set up to process the last result only!
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
30
|
+
*/
|
|
31
|
+
if (request.hasRunningDependencies()) {
|
|
32
|
+
return Promise.resolve(null);
|
|
33
|
+
}
|
|
34
|
+
dispatch(requestCart());
|
|
35
|
+
const promise = request.dispatch();
|
|
36
|
+
promise.then(response => {
|
|
37
|
+
/**
|
|
38
|
+
* Dispatch "receiveCart" only when the cart is still
|
|
39
|
+
* fetching (in case of stacked fetch calls)
|
|
40
|
+
*/
|
|
41
|
+
if (getIsFetching(getState())) {
|
|
42
|
+
dispatch(receiveCart(response));
|
|
43
|
+
}
|
|
44
|
+
}).catch(error => {
|
|
45
|
+
if (error) {
|
|
46
|
+
// Post only one error in a group of possibly multiple requests being rejected at once
|
|
47
|
+
if (!getIsFetching(getState())) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Check if we have an error (no error means an outdated request has been rejected).
|
|
52
|
+
dispatch(errorCart());
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return promise;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @mixes {MutableFunction} */
|
|
60
|
+
export default mutable(fetchCart);
|
|
@@ -1,9 +1,47 @@
|
|
|
1
|
-
import
|
|
1
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
2
|
+
import { PROCESS_SEQUENTIAL } from '@shopgate/pwa-core/constants/ProcessTypes';
|
|
3
|
+
import { mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
4
|
+
import configuration from '@shopgate/pwa-common/collections/Configuration';
|
|
5
|
+
import { PIPELINES } from '@shopgate/pwa-common/constants/Configuration';
|
|
6
|
+
import { SHOPGATE_CART_UPDATE_PRODUCTS } from "../constants/Pipelines";
|
|
7
|
+
import createPipelineErrorList from "../helpers/createPipelineErrorList";
|
|
8
|
+
import { ECART } from "../constants/PipelineErrors";
|
|
9
|
+
import updateProducts from "../action-creators/updateProductsInCart";
|
|
10
|
+
import successUpdateProductsInCart from "../action-creators/successUpdateProductsInCart";
|
|
11
|
+
import errorUpdateProductsInCart from "../action-creators/errorUpdateProductsInCart";
|
|
12
|
+
import { messagesHaveErrors, createErrorMessageList } from "../helpers";
|
|
13
|
+
|
|
14
|
+
/**
|
|
2
15
|
* Updates a product in the cart.
|
|
3
16
|
* @param {Array} updateData The data for the updateProductsInCart request.
|
|
4
17
|
* @return {Function} A redux thunk.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
*/
|
|
19
|
+
function updateProductsInCart(updateData) {
|
|
20
|
+
return async dispatch => {
|
|
21
|
+
const {
|
|
22
|
+
[SHOPGATE_CART_UPDATE_PRODUCTS]: pipeline = SHOPGATE_CART_UPDATE_PRODUCTS
|
|
23
|
+
} = configuration.get(PIPELINES, {});
|
|
24
|
+
dispatch(updateProducts(updateData));
|
|
25
|
+
const request = new PipelineRequest(pipeline).setInput({
|
|
26
|
+
cartItems: updateData
|
|
27
|
+
}).setResponseProcessed(PROCESS_SEQUENTIAL).setErrorBlacklist(ECART).dispatch();
|
|
28
|
+
request.then(result => {
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated: The property "messages" is not supposed to be part of the pipeline response.
|
|
31
|
+
* Specification demands errors to be returned as response object with an "error" property.
|
|
32
|
+
* This code snippet needs to be removed after fixing the `@shopgate/legacy-cart` extension.
|
|
33
|
+
*/
|
|
34
|
+
if (result.messages && messagesHaveErrors(result.messages)) {
|
|
35
|
+
dispatch(errorUpdateProductsInCart(updateData, createErrorMessageList(SHOPGATE_CART_UPDATE_PRODUCTS, result.messages)));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
dispatch(successUpdateProductsInCart());
|
|
39
|
+
}).catch(error => {
|
|
40
|
+
dispatch(errorUpdateProductsInCart(updateData, createPipelineErrorList(SHOPGATE_CART_UPDATE_PRODUCTS, error)));
|
|
41
|
+
});
|
|
42
|
+
return request;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @mixes {MutableFunction} */
|
|
47
|
+
export default mutable(updateProductsInCart);
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
// Modification of the cart failed with details and some predefined detail error codes
|
|
2
|
-
export
|
|
2
|
+
export const ECART = 'ECART';
|
|
3
|
+
export const ECART_ENOTFOUND = 'ENOTFOUND';
|
|
4
|
+
export const ECART_EINSUFFICIENTSTOCK = 'EINSUFFICIENTSTOCK';
|
|
5
|
+
export const ECART_EMULTIPLELOCATIONS = 'EMULTIPLELOCATIONS';
|
|
6
|
+
export const ECART_EINVALIDCOUPON = 'EINVALIDCOUPON';
|
|
7
|
+
export const ECART_ECOUPONEXPIRED = 'ECOUPONEXPIRED';
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const SHOPGATE_CART_ADD_COUPONS = 'shopgate.cart.addCoupons';
|
|
2
|
+
export const SHOPGATE_CART_ADD_PRODUCTS = 'shopgate.cart.addProducts';
|
|
3
|
+
export const SHOPGATE_CART_DELETE_COUPONS = 'shopgate.cart.deleteCoupons';
|
|
4
|
+
export const SHOPGATE_CART_DELETE_PRODUCTS = 'shopgate.cart.deleteProducts';
|
|
5
|
+
export const SHOPGATE_CART_GET_CART = 'shopgate.cart.getCart';
|
|
6
|
+
export const SHOPGATE_CART_UPDATE_PRODUCTS = 'shopgate.cart.updateProducts';
|
|
@@ -1 +1,85 @@
|
|
|
1
|
-
|
|
1
|
+
const CART = 'cart';
|
|
2
|
+
const NAV_MENU = 'nav-menu';
|
|
3
|
+
const ITEM_LIST = 'item-list';
|
|
4
|
+
const ITEM = 'item';
|
|
5
|
+
const PAYMENT_BAR = 'payment-bar';
|
|
6
|
+
const TOTALS = 'totals';
|
|
7
|
+
const SUB_TOTAL = 'sub-total';
|
|
8
|
+
const GRAND_TOTAL = 'grand-total';
|
|
9
|
+
const SHIPPING = 'shipping';
|
|
10
|
+
const DISCOUNTS = 'discounts';
|
|
11
|
+
const TAX = 'tax';
|
|
12
|
+
const COUPON_FIELD = 'coupon-field';
|
|
13
|
+
const CHECKOUT_BUTTON = 'checkout-button';
|
|
14
|
+
const NAME = 'name';
|
|
15
|
+
const CONTEXT_MENU = 'context-menu';
|
|
16
|
+
const REMOVE = 'remove';
|
|
17
|
+
const IMAGE = 'image';
|
|
18
|
+
const QUANTITY_PICKER = 'quantity-picker';
|
|
19
|
+
const LINK = 'link';
|
|
20
|
+
const PROPERTIES = 'properties';
|
|
21
|
+
const PRICE = 'price';
|
|
22
|
+
const PRICE_STRIKED = 'price-striked';
|
|
23
|
+
const COUPON_CODE = 'coupon-code';
|
|
24
|
+
const EMPTY = 'empty';
|
|
25
|
+
const BEFORE = 'before';
|
|
26
|
+
const AFTER = 'after';
|
|
27
|
+
export const CART_COUPON_FIELD_BEFORE = `${CART}.${COUPON_FIELD}.${BEFORE}`;
|
|
28
|
+
export const CART_COUPON_FIELD = `${CART}.${COUPON_FIELD}`;
|
|
29
|
+
export const CART_COUPON_FIELD_AFTER = `${CART}.${COUPON_FIELD}.${AFTER}`;
|
|
30
|
+
export const CART_ITEM_LIST_BEFORE = `${CART}.${ITEM_LIST}.${BEFORE}`;
|
|
31
|
+
export const CART_ITEM_LIST = `${CART}.${ITEM_LIST}`;
|
|
32
|
+
export const CART_ITEM_LIST_AFTER = `${CART}.${ITEM_LIST}.${AFTER}`;
|
|
33
|
+
export const CART_ITEM_BEFORE = `${CART}.${ITEM}.${BEFORE}`;
|
|
34
|
+
export const CART_ITEM = `${CART}.${ITEM}`;
|
|
35
|
+
export const CART_ITEM_AFTER = `${CART}.${ITEM}.${AFTER}`;
|
|
36
|
+
export const CART_ITEM_NAME_BEFORE = `${CART}.${ITEM}.${NAME}.${BEFORE}`;
|
|
37
|
+
export const CART_ITEM_NAME = `${CART}.${ITEM}.${NAME}`;
|
|
38
|
+
export const CART_ITEM_NAME_AFTER = `${CART}.${ITEM}.${NAME}.${AFTER}`;
|
|
39
|
+
export const CART_ITEM_CONTEXT_MENU = `${CART}.${ITEM}.${CONTEXT_MENU}`;
|
|
40
|
+
export const CART_ITEM_CONTEXT_MENU_ITEM_REMOVE = `${CART}.${ITEM}.${CONTEXT_MENU}.${ITEM}.${REMOVE}`;
|
|
41
|
+
export const CART_ITEM_IMAGE_BEFORE = `${CART}.${ITEM}.${IMAGE}.${BEFORE}`;
|
|
42
|
+
export const CART_ITEM_IMAGE = `${CART}.${ITEM}.${IMAGE}`;
|
|
43
|
+
export const CART_ITEM_IMAGE_AFTER = `${CART}.${ITEM}.${IMAGE}.${AFTER}`;
|
|
44
|
+
export const CART_ITEM_LINK = `${CART}.${ITEM}.${LINK}`;
|
|
45
|
+
export const CART_ITEM_PROPERTIES = `${CART}.${ITEM}.${PROPERTIES}`;
|
|
46
|
+
export const CART_ITEM_QUANTITY_PICKER = `${CART}.${ITEM}.${QUANTITY_PICKER}`;
|
|
47
|
+
export const CART_ITEM_PRICE_BEFORE = `${CART}.${ITEM}.${PRICE}.${BEFORE}`;
|
|
48
|
+
export const CART_ITEM_PRICE = `${CART}.${ITEM}.${PRICE}`;
|
|
49
|
+
export const CART_ITEM_PRICE_AFTER = `${CART}.${ITEM}.${PRICE}.${AFTER}`;
|
|
50
|
+
export const CART_ITEM_PRICE_STRIKED_BEFORE = `${CART}.${ITEM}.${PRICE_STRIKED}.${BEFORE}`;
|
|
51
|
+
export const CART_ITEM_PRICE_STRIKED = `${CART}.${ITEM}.${PRICE_STRIKED}`;
|
|
52
|
+
export const CART_ITEM_PRICE_STRIKED_AFTER = `${CART}.${ITEM}.${PRICE_STRIKED}.${AFTER}`;
|
|
53
|
+
export const CART_ITEM_COUPON_CODE_BEFORE = `${CART}.${ITEM}.${COUPON_CODE}.${BEFORE}`;
|
|
54
|
+
export const CART_ITEM_COUPON_CODE = `${CART}.${ITEM}.${COUPON_CODE}`;
|
|
55
|
+
export const CART_ITEM_COUPON_CODE_AFTER = `${CART}.${ITEM}.${COUPON_CODE}.${AFTER}`;
|
|
56
|
+
export const CART_EMPTY_BEFORE = `${CART}.${EMPTY}.${BEFORE}`;
|
|
57
|
+
export const CART_EMPTY = `${CART}.${EMPTY}`;
|
|
58
|
+
export const CART_EMPTY_AFTER = `${CART}.${EMPTY}.${AFTER}`;
|
|
59
|
+
export const CART_PAYMENT_BAR_BEFORE = `${CART}.${PAYMENT_BAR}.${BEFORE}`;
|
|
60
|
+
export const CART_PAYMENT_BAR = `${CART}.${PAYMENT_BAR}`;
|
|
61
|
+
export const CART_PAYMENT_BAR_AFTER = `${CART}.${PAYMENT_BAR}.${AFTER}`;
|
|
62
|
+
export const CART_PAYMENT_BAR_TOTALS_BEFORE = `${CART}.${PAYMENT_BAR}.${TOTALS}.${BEFORE}`;
|
|
63
|
+
export const CART_PAYMENT_BAR_TOTALS = `${CART}.${PAYMENT_BAR}.${TOTALS}`;
|
|
64
|
+
export const CART_PAYMENT_BAR_TOTALS_AFTER = `${CART}.${PAYMENT_BAR}.${TOTALS}.${AFTER}`;
|
|
65
|
+
export const CART_PAYMENT_BAR_TOTALS_SUB_TOTAL_BEFORE = `${CART}.${PAYMENT_BAR}.${TOTALS}.${SUB_TOTAL}.${BEFORE}`;
|
|
66
|
+
export const CART_PAYMENT_BAR_TOTALS_SUB_TOTAL = `${CART}.${PAYMENT_BAR}.${TOTALS}.${SUB_TOTAL}`;
|
|
67
|
+
export const CART_PAYMENT_BAR_TOTALS_SUB_TOTAL_AFTER = `${CART}.${PAYMENT_BAR}.${TOTALS}.${SUB_TOTAL}.${AFTER}`;
|
|
68
|
+
export const CART_PAYMENT_BAR_TOTALS_GRAND_TOTAL_BEFORE = `${CART}.${PAYMENT_BAR}.${TOTALS}.${GRAND_TOTAL}.${BEFORE}`;
|
|
69
|
+
export const CART_PAYMENT_BAR_TOTALS_GRAND_TOTAL = `${CART}.${PAYMENT_BAR}.${TOTALS}.${GRAND_TOTAL}`;
|
|
70
|
+
export const CART_PAYMENT_BAR_TOTALS_GRAND_TOTAL_AFTER = `${CART}.${PAYMENT_BAR}.${TOTALS}.${GRAND_TOTAL}.${AFTER}`;
|
|
71
|
+
export const CART_PAYMENT_BAR_TOTALS_SHIPPING_BEFORE = `${CART}.${PAYMENT_BAR}.${TOTALS}.${SHIPPING}.${BEFORE}`;
|
|
72
|
+
export const CART_PAYMENT_BAR_TOTALS_SHIPPING = `${CART}.${PAYMENT_BAR}.${TOTALS}.${SHIPPING}`;
|
|
73
|
+
export const CART_PAYMENT_BAR_TOTALS_SHIPPING_AFTER = `${CART}.${PAYMENT_BAR}.${TOTALS}.${SHIPPING}.${AFTER}`;
|
|
74
|
+
export const CART_PAYMENT_BAR_TOTALS_DISCOUNTS_BEFORE = `${CART}.${PAYMENT_BAR}.${TOTALS}.${DISCOUNTS}.${BEFORE}`;
|
|
75
|
+
export const CART_PAYMENT_BAR_TOTALS_DISCOUNTS = `${CART}.${PAYMENT_BAR}.${TOTALS}.${DISCOUNTS}`;
|
|
76
|
+
export const CART_PAYMENT_BAR_TOTALS_DISCOUNTS_AFTER = `${CART}.${PAYMENT_BAR}.${TOTALS}.${DISCOUNTS}.${AFTER}`;
|
|
77
|
+
export const CART_PAYMENT_BAR_TOTALS_TAX_BEFORE = `${CART}.${PAYMENT_BAR}.${TOTALS}.${TAX}.${BEFORE}`;
|
|
78
|
+
export const CART_PAYMENT_BAR_TOTALS_TAX = `${CART}.${PAYMENT_BAR}.${TOTALS}.${TAX}`;
|
|
79
|
+
export const CART_PAYMENT_BAR_TOTALS_TAX_AFTER = `${CART}.${PAYMENT_BAR}.${TOTALS}.${TAX}.${AFTER}`;
|
|
80
|
+
export const NAV_MENU_CART_BEFORE = `${NAV_MENU}.${CART}.${BEFORE}`;
|
|
81
|
+
export const NAV_MENU_CART = `${NAV_MENU}.${CART}`;
|
|
82
|
+
export const NAV_MENU_CART_AFTER = `${NAV_MENU}.${CART}.${AFTER}`;
|
|
83
|
+
export const CART_CHECKOUT_BUTTON = `${CART}.${CHECKOUT_BUTTON}`;
|
|
84
|
+
export const CART_CHECKOUT_BUTTON_BEFORE = `${CART}.${CHECKOUT_BUTTON}.${BEFORE}`;
|
|
85
|
+
export const CART_CHECKOUT_BUTTON_AFTER = `${CART}.${CHECKOUT_BUTTON}.${AFTER}`;
|
package/cart/constants/index.js
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const CART_PATH = '/cart';
|
|
2
|
+
export const DEEPLINK_CART_ADD_PRODUCT_PATTERN = '/cart_add_product/:productId/:couponId';
|
|
3
|
+
export const DEEPLINK_CART_ADD_COUPON_PATTERN = '/cart_add_coupon/:couponId';
|
|
4
|
+
export const CART_ITEM_TYPE_COUPON = 'coupon';
|
|
5
|
+
export const CART_ITEM_TYPE_PRODUCT = 'product';
|
|
6
|
+
export const CART_TOTALS_TYPE_SUB = 'subTotal';
|
|
7
|
+
export const CART_TOTALS_TYPE_GRAND = 'grandTotal';
|
|
8
|
+
export const CART_TOTALS_TYPE_DISCOUNT = 'discount';
|
|
9
|
+
export const CART_TOTALS_TYPE_SHIPPING = 'shipping';
|
|
10
|
+
export const CART_TOTALS_TYPE_TAX = 'tax';
|
|
11
|
+
export const COUPON_TYPE_FIXED = 'fixed';
|
|
12
|
+
export const COUPON_TYPE_PERCENTAGE = 'percentage';
|
|
13
|
+
export const MESSAGE_TYPE_ERROR = 'error';
|
|
14
|
+
export const ADD_PRODUCTS_TO_CART = 'ADD_PRODUCTS_TO_CART';
|
|
15
|
+
export const SUCCESS_ADD_PRODUCTS_TO_CART = 'SUCCESS_ADD_PRODUCTS_TO_CART';
|
|
16
|
+
export const ERROR_ADD_PRODUCTS_TO_CART = 'ERROR_ADD_PRODUCTS_TO_CART';
|
|
17
|
+
export const DELETE_PRODUCTS_FROM_CART = 'DELETE_PRODUCTS_FROM_CART';
|
|
18
|
+
export const ERROR_DELETE_PRODUCTS_FROM_CART = 'ERROR_DELETE_PRODUCTS_FROM_CART';
|
|
19
|
+
export const SUCCESS_DELETE_PRODUCTS_FROM_CART = 'SUCCESS_DELETE_PRODUCTS_FROM_CART';
|
|
20
|
+
export const UPDATE_PRODUCTS_IN_CART = 'UPDATE_PRODUCTS_IN_CART';
|
|
21
|
+
export const SUCCESS_UPDATE_PRODUCTS_IN_CART = 'SUCCESS_UPDATE_PRODUCTS_IN_CART';
|
|
22
|
+
export const ERROR_UPDATE_PRODUCTS_IN_CART = 'ERROR_UPDATE_PRODUCTS_IN_CART';
|
|
23
|
+
export const ADD_COUPONS_TO_CART = 'ADD_COUPONS_TO_CART';
|
|
24
|
+
export const SUCCESS_ADD_COUPONS_TO_CART = 'SUCCESS_ADD_COUPONS_TO_CART';
|
|
25
|
+
export const ERROR_ADD_COUPONS_TO_CART = 'ERROR_ADD_COUPONS_TO_CART';
|
|
26
|
+
export const DELETE_COUPONS_FROM_CART = 'DELETE_COUPONS_FROM_CART';
|
|
27
|
+
export const ERROR_DELETE_COUPONS_FROM_CART = 'ERROR_DELETE_COUPONS_FROM_CART';
|
|
28
|
+
export const SET_CART_PENDING_PRODUCT_COUNT = 'SET_CART_PENDING_PRODUCT_COUNT';
|
|
29
|
+
export const SUCCESS_DELETE_COUPONS_FROM_CART = 'SUCCESS_DELETE_COUPONS_FROM_CART';
|
|
30
|
+
export const SET_COUPON_FIELD_ERROR = 'SET_COUPON_FIELD_ERROR';
|
|
31
|
+
export const SET_COUPON_FIELD_VALUE = 'SET_COUPON_FIELD_VALUE';
|
|
32
|
+
export const REQUEST_CART = 'REQUEST_CART';
|
|
33
|
+
export const RECEIVE_CART = 'RECEIVE_CART';
|
|
34
|
+
export const ERROR_CART = 'ERROR_CART';
|
|
35
|
+
|
|
36
|
+
/**
|
|
2
37
|
* Event that is called when addToCart failed because not all variants where selected yet.
|
|
3
38
|
* @type {string}
|
|
4
|
-
*/
|
|
39
|
+
*/
|
|
40
|
+
export const EVENT_ADD_TO_CART_MISSING_VARIANT = 'EVENT_ADD_TO_CART_MISSING_VARIANT';
|
|
41
|
+
export const SET_FULFILLMENT_SLOT = 'SET_FULFILLMENT_SLOT';
|
package/cart/helpers/config.js
CHANGED
|
@@ -1,4 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
import appConfig from '@shopgate/pwa-common/helpers/config';
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Retrieves the shipping config based on the legacy configuration and the new Engage config.
|
|
3
5
|
* @returns {Object} The merged shipping configuration.
|
|
4
|
-
*/
|
|
6
|
+
*/
|
|
7
|
+
export function getCartConfig() {
|
|
8
|
+
const {
|
|
9
|
+
cartShippingHideAnonymousLegacy = null,
|
|
10
|
+
cartShippingTextAnonymousLegacy = null,
|
|
11
|
+
cartTaxText = null,
|
|
12
|
+
cart = {}
|
|
13
|
+
} = appConfig;
|
|
14
|
+
const {
|
|
15
|
+
shipping = {},
|
|
16
|
+
tax = {}
|
|
17
|
+
} = cart;
|
|
18
|
+
let hideAnonymous;
|
|
19
|
+
let textForAnonymousUsers;
|
|
20
|
+
({
|
|
21
|
+
hideAnonymous = null,
|
|
22
|
+
textForAnonymousUsers = null
|
|
23
|
+
} = shipping);
|
|
24
|
+
if (hideAnonymous === null) {
|
|
25
|
+
hideAnonymous = cartShippingHideAnonymousLegacy;
|
|
26
|
+
}
|
|
27
|
+
if (textForAnonymousUsers === null) {
|
|
28
|
+
textForAnonymousUsers = cartShippingTextAnonymousLegacy;
|
|
29
|
+
}
|
|
30
|
+
let text;
|
|
31
|
+
({
|
|
32
|
+
text = null
|
|
33
|
+
} = tax);
|
|
34
|
+
if (text === null) {
|
|
35
|
+
text = cartTaxText;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
...cart,
|
|
39
|
+
shipping: {
|
|
40
|
+
...shipping,
|
|
41
|
+
hideAnonymous,
|
|
42
|
+
textForAnonymousUsers
|
|
43
|
+
},
|
|
44
|
+
tax: {
|
|
45
|
+
...tax,
|
|
46
|
+
text
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { ECART } from "../constants/PipelineErrors";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* @typedef {Object} PipelineError
|
|
3
5
|
* @property {string} code
|
|
4
6
|
* @property {string} message
|
|
@@ -16,6 +18,30 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
|
|
|
16
18
|
* @param {string} pipelineName The name of the pipeline in which the error occurred.
|
|
17
19
|
* @param {PipelineError} error The error to be sanitize.
|
|
18
20
|
* @return {PipelineErrorElement[]}
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
*/
|
|
22
|
+
export default (pipelineName, error) => {
|
|
23
|
+
const defaultPipelineError = {
|
|
24
|
+
entityId: '',
|
|
25
|
+
code: error.code || '',
|
|
26
|
+
pipeline: pipelineName || '',
|
|
27
|
+
message: error.message || '',
|
|
28
|
+
messageParams: {},
|
|
29
|
+
translated: true,
|
|
30
|
+
handled: error.handled || false
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Not all error codes can contain an array of sub-errors with additional errors
|
|
34
|
+
if (error.code !== ECART) {
|
|
35
|
+
return [defaultPipelineError];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Ensure all properties actually exist
|
|
39
|
+
const {
|
|
40
|
+
errors = []
|
|
41
|
+
} = error;
|
|
42
|
+
return errors.map(e => ({
|
|
43
|
+
...defaultPipelineError,
|
|
44
|
+
...e,
|
|
45
|
+
code: `${error.code} :: ${e.code}`
|
|
46
|
+
}));
|
|
47
|
+
};
|
|
@@ -1,8 +1,41 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getFulfillmentSchedulingEnabled } from '@shopgate/engage/core/selectors';
|
|
2
|
+
import { getPreferredLocation } from '@shopgate/engage/locations';
|
|
3
|
+
import { forceOpenFulfillmentSlotDialog } from '@shopgate/engage/locations/components/FulfillmentSlotSwitcher/FulfillmentSlotProvider';
|
|
4
|
+
import { ROPIS, BOPIS } from '@shopgate/engage/locations/constants';
|
|
5
|
+
import { getActiveFulfillmentSlot, getActiveFulfillmentSlotLocationCode } from '@shopgate/engage/cart/cart.selectors';
|
|
6
|
+
|
|
7
|
+
/**
|
|
2
8
|
*
|
|
3
9
|
* @param {Object} state The current state
|
|
4
10
|
* @param {Array} products An array of products
|
|
5
11
|
* @returns {Array}
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
*/
|
|
13
|
+
export const handleFulfillmentSlots = async (state, products) => {
|
|
14
|
+
const needsScheduling = products.some(product => [ROPIS, BOPIS].includes(product?.fulfillment?.method));
|
|
15
|
+
const fulfillmentScheduling = getFulfillmentSchedulingEnabled(state);
|
|
16
|
+
if (!needsScheduling || !fulfillmentScheduling) {
|
|
17
|
+
return products;
|
|
18
|
+
}
|
|
19
|
+
let activeFulfillmentSlot = getActiveFulfillmentSlot(state);
|
|
20
|
+
const activeSlotLocationCode = getActiveFulfillmentSlotLocationCode(state);
|
|
21
|
+
const preferredLocationCode = getPreferredLocation(state)?.code;
|
|
22
|
+
|
|
23
|
+
// Make sure that a fulfillment slot has been chosen first!
|
|
24
|
+
if (!activeFulfillmentSlot || activeSlotLocationCode !== preferredLocationCode) {
|
|
25
|
+
activeFulfillmentSlot = await forceOpenFulfillmentSlotDialog('test');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Enrich slot id to fulfillment settings of all line items.
|
|
29
|
+
const result = products.map(product => {
|
|
30
|
+
const isRope = [ROPIS, BOPIS].includes(product?.fulfillment?.method);
|
|
31
|
+
return {
|
|
32
|
+
...product,
|
|
33
|
+
fulfillment: product.fulfillment ? {
|
|
34
|
+
...product.fulfillment,
|
|
35
|
+
slotId: isRope ? activeFulfillmentSlot.id : undefined,
|
|
36
|
+
location: isRope ? product.fulfillment?.location : undefined
|
|
37
|
+
} : undefined
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
return result;
|
|
41
|
+
};
|
package/cart/helpers/index.js
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import { MESSAGE_TYPE_ERROR } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Checks if the messages array of a pipeline response contains error messages.
|
|
3
5
|
* @param {Array} [messages=[]] The messages.
|
|
4
6
|
* @return {boolean}
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
export const messagesHaveErrors = (messages = []) => messages.some(({
|
|
9
|
+
type
|
|
10
|
+
}) => type === MESSAGE_TYPE_ERROR);
|
|
11
|
+
|
|
12
|
+
/**
|
|
6
13
|
* Creates an error message list which can be processes by the error system.
|
|
7
14
|
* @param {string} pipeline The related pipeline.
|
|
8
15
|
* @param {Array} messages The messages.
|
|
9
16
|
* @return {Array}
|
|
10
|
-
*/
|
|
17
|
+
*/
|
|
18
|
+
export const createErrorMessageList = (pipeline, messages) => messages.map(message => ({
|
|
19
|
+
...message,
|
|
20
|
+
context: pipeline
|
|
21
|
+
}));
|
package/cart/helpers/quantity.js
CHANGED
|
@@ -4,7 +4,26 @@
|
|
|
4
4
|
* @param {Object} product The product object.
|
|
5
5
|
* @param {Array} cartItems Existing cart items to check for.
|
|
6
6
|
* @returns {number}
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
*/
|
|
8
|
+
export const getDisplayedProductQuantity = ({
|
|
9
|
+
productId,
|
|
10
|
+
product = {},
|
|
11
|
+
fulfillment,
|
|
12
|
+
quantity
|
|
13
|
+
}, cartItems = []) => {
|
|
14
|
+
// Products with custom units like (kg, lbs, ..)
|
|
15
|
+
// are counted as 1 per line item.
|
|
16
|
+
if (product.unit && product.hasCatchWeight) {
|
|
17
|
+
// If product is already existing in cart we only count them once.
|
|
18
|
+
const existingCartItem = cartItems.find(cartItem => {
|
|
19
|
+
const sameProduct = productId === cartItem.product.id;
|
|
20
|
+
const sameFulfillmentMethod = fulfillment?.type === cartItem.fulfillment?.type && fulfillment?.location?.code === cartItem.fulfillment?.location?.code;
|
|
21
|
+
return sameProduct && sameFulfillmentMethod;
|
|
22
|
+
});
|
|
23
|
+
if (!existingCartItem) {
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
return quantity;
|
|
29
|
+
};
|
package/cart/helpers/shipping.js
CHANGED
|
@@ -1,7 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* Check if shipping line should be shown
|
|
3
3
|
* @param {Object} cartConfig shippingConfig
|
|
4
4
|
* @param {boolean} isUserLoggedIn isUserLoggedIn
|
|
5
5
|
* @param {Object} shippingCost shippingCost
|
|
6
6
|
* @returns {Object|null}
|
|
7
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
export function getShippingLine(cartConfig, isUserLoggedIn = false, shippingCost = null) {
|
|
9
|
+
if (cartConfig.hideShipping) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const shippingConfig = cartConfig.shipping;
|
|
13
|
+
if (!isUserLoggedIn) {
|
|
14
|
+
if (shippingConfig.hideAnonymous) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (shippingConfig.textForAnonymousUsers) {
|
|
18
|
+
return {
|
|
19
|
+
label: shippingConfig.textForAnonymousUsers
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (shippingCost === null) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (shippingCost.amount === null) {
|
|
27
|
+
if (shippingConfig.textForNoShipping) {
|
|
28
|
+
return {
|
|
29
|
+
label: shippingConfig.textForNoShipping
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (shippingCost.amount === 0) {
|
|
35
|
+
if (shippingConfig.hideFreeShipping) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
if (shippingConfig.textForFreeShipping) {
|
|
39
|
+
return {
|
|
40
|
+
label: shippingCost.label || 'titles.shipping',
|
|
41
|
+
amount: shippingConfig.textForFreeShipping,
|
|
42
|
+
...(shippingConfig.hint && {
|
|
43
|
+
hint: shippingConfig.hint
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
label: shippingCost.label || 'titles.shipping',
|
|
49
|
+
amount: 'shipping.free_short',
|
|
50
|
+
...(shippingConfig.hint && {
|
|
51
|
+
hint: shippingConfig.hint
|
|
52
|
+
})
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
label: shippingCost.label || 'titles.shipping',
|
|
57
|
+
amount: shippingCost.amount,
|
|
58
|
+
...(shippingConfig.hint && {
|
|
59
|
+
hint: shippingConfig.hint
|
|
60
|
+
})
|
|
61
|
+
};
|
|
62
|
+
}
|
package/cart/helpers/tax.js
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* Check if shipping line should be shown
|
|
3
3
|
* @param {Object} cartConfig shippingConfig
|
|
4
4
|
* @param {Object} tax tax
|
|
5
5
|
* @returns {Object|null}
|
|
6
|
-
*/
|
|
6
|
+
*/
|
|
7
|
+
export function getTaxLine(cartConfig, tax = null) {
|
|
8
|
+
if (tax === null || !tax.amount) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (cartConfig.hideTax) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const taxConfig = cartConfig.tax;
|
|
15
|
+
if (taxConfig.text) {
|
|
16
|
+
return {
|
|
17
|
+
amount: taxConfig.text,
|
|
18
|
+
...(taxConfig.hint && {
|
|
19
|
+
hint: taxConfig.hint
|
|
20
|
+
})
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
label: tax.label,
|
|
25
|
+
amount: tax.amount,
|
|
26
|
+
...(taxConfig.hint && {
|
|
27
|
+
hint: taxConfig.hint
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
}
|