@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
|
@@ -1,48 +1,325 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'rxjs/add/operator/debounceTime';
|
|
2
|
+
import 'rxjs/add/observable/of';
|
|
3
|
+
import { Observable } from 'rxjs/Observable';
|
|
4
|
+
import event from '@shopgate/pwa-core/classes/Event';
|
|
5
|
+
import pipelineDependencies from '@shopgate/pwa-core/classes/PipelineDependencies';
|
|
6
|
+
import { redirects } from '@shopgate/pwa-common/collections';
|
|
7
|
+
import { userDidUpdate$ } from '@shopgate/pwa-common/streams/user';
|
|
8
|
+
import { appWillStart$, appDidStart$ } from '@shopgate/pwa-common/streams/app';
|
|
9
|
+
import { parseObjectToQueryString } from '@shopgate/pwa-common/helpers/router';
|
|
10
|
+
import fetchRegisterUrl from '@shopgate/pwa-common/actions/user/fetchRegisterUrl';
|
|
11
|
+
import { LoadingProvider } from '@shopgate/pwa-common/providers';
|
|
12
|
+
import { fetchProductsById, getProductRoute, hasProductVariety, getProduct } from '@shopgate/pwa-common-commerce/product';
|
|
13
|
+
import { historyReplace } from '@shopgate/pwa-common/actions/router';
|
|
14
|
+
import { checkoutSucceeded$ } from '@shopgate/pwa-common-commerce/checkout';
|
|
15
|
+
import { DIRECT_SHIP, ROPIS, BOPIS, getPreferredLocation, getPreferredFulfillmentMethod } from '@shopgate/engage/locations';
|
|
16
|
+
import { makeGetEnabledFulfillmentMethods } from '@shopgate/engage/core/config';
|
|
17
|
+
import { errorBehavior } from '@shopgate/engage/core';
|
|
18
|
+
import { hasNewServices } from '@shopgate/engage/core/helpers';
|
|
19
|
+
import * as pipelines from "../constants/Pipelines";
|
|
20
|
+
import addCouponsToCart from "../actions/addCouponsToCart";
|
|
21
|
+
import addProductsToCart from "../actions/addProductsToCart";
|
|
22
|
+
import updateProductsInCart from "../actions/updateProductsInCart";
|
|
23
|
+
import fetchCart from "../actions/fetchCart";
|
|
24
|
+
import { cartDidEnter$, cartRequesting$, cartReceived$, productsAdded$, productsModified$, productsUpdated$, productsDeleted$, couponsAdded$, couponsUpdated$, couponsDeleted$, routeWithCouponWillEnter$, remoteCartDidUpdate$, cartUpdateFailed$, routeAddProductNavigate$, setFulfillmentSlot$, cartWillEnterIdle$ } from "../streams";
|
|
25
|
+
import setCartProductPendingCount from "../action-creators/setCartProductPendingCount";
|
|
26
|
+
import { CART_PATH, DEEPLINK_CART_ADD_COUPON_PATTERN, DEEPLINK_CART_ADD_PRODUCT_PATTERN, CART_ITEM_TYPE_PRODUCT } from "../constants";
|
|
27
|
+
import { getCartProducts } from "../selectors";
|
|
28
|
+
|
|
29
|
+
/**
|
|
2
30
|
* Cart subscriptions.
|
|
3
31
|
* @param {Function} subscribe The subscribe function.
|
|
4
|
-
*/
|
|
32
|
+
*/
|
|
33
|
+
export default function cart(subscribe) {
|
|
34
|
+
/**
|
|
5
35
|
* Gets triggered when ever the local cart is out of
|
|
6
36
|
* sync with the remote cart from the server.
|
|
7
|
-
*/
|
|
37
|
+
*/
|
|
38
|
+
const cartNeedsSync$ = userDidUpdate$.merge(remoteCartDidUpdate$, checkoutSucceeded$, cartWillEnterIdle$);
|
|
39
|
+
|
|
40
|
+
/**
|
|
8
41
|
* Gets triggered when the app is started or the cart route is entered.
|
|
9
|
-
*/
|
|
42
|
+
*/
|
|
43
|
+
const cartDidEnterOrAppDidStart$ = cartDidEnter$.merge(appDidStart$);
|
|
44
|
+
const cartBusy$ = cartRequesting$.merge(couponsAdded$, couponsDeleted$, productsAdded$, productsModified$, productsDeleted$);
|
|
45
|
+
const cartIdle$ = cartReceived$.merge(couponsUpdated$, productsUpdated$);
|
|
46
|
+
|
|
47
|
+
/**
|
|
10
48
|
* Gets triggered when the app will start.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
|
|
49
|
+
*/
|
|
50
|
+
subscribe(appWillStart$, () => {
|
|
51
|
+
// Use the redirect system to handle coupons from deep links.
|
|
52
|
+
redirects.set(DEEPLINK_CART_ADD_COUPON_PATTERN, ({
|
|
53
|
+
dispatch,
|
|
54
|
+
action
|
|
55
|
+
}) => {
|
|
56
|
+
const [,, coupon] = action.params.pathname.split('/');
|
|
57
|
+
if (coupon) {
|
|
58
|
+
dispatch(addCouponsToCart([coupon.split('?')[0]], false));
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
});
|
|
62
|
+
// This will be handled in 2 deferred subscriptions
|
|
63
|
+
redirects.set(DEEPLINK_CART_ADD_PRODUCT_PATTERN, () => null);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/**
|
|
14
67
|
* Gets triggered when the app starts.
|
|
15
|
-
*/
|
|
16
|
-
|
|
68
|
+
*/
|
|
69
|
+
subscribe(appDidStart$, ({
|
|
70
|
+
dispatch
|
|
71
|
+
}) => {
|
|
72
|
+
pipelineDependencies.set(pipelines.SHOPGATE_CART_GET_CART, [pipelines.SHOPGATE_CART_ADD_PRODUCTS, pipelines.SHOPGATE_CART_UPDATE_PRODUCTS, pipelines.SHOPGATE_CART_DELETE_PRODUCTS, pipelines.SHOPGATE_CART_ADD_COUPONS, pipelines.SHOPGATE_CART_DELETE_COUPONS]);
|
|
73
|
+
|
|
74
|
+
// Push (deeplink) with coupon concurrent to get cart on app start
|
|
75
|
+
pipelineDependencies.set(pipelines.SHOPGATE_CART_ADD_COUPONS, [pipelines.SHOPGATE_CART_ADD_PRODUCTS, pipelines.SHOPGATE_CART_GET_CART]);
|
|
76
|
+
pipelineDependencies.set(pipelines.SHOPGATE_CART_DELETE_COUPONS, [pipelines.SHOPGATE_CART_ADD_PRODUCTS, pipelines.SHOPGATE_CART_GET_CART]);
|
|
77
|
+
|
|
78
|
+
/**
|
|
17
79
|
* Reload the cart whenever the WebView becomes visible.
|
|
18
80
|
* This is needed, for example, when the cart is modified from another inAppBrowser tab like a
|
|
19
81
|
* web-checkout and the user closes the said tab before reaching the success page.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
82
|
+
*/
|
|
83
|
+
event.addCallback('viewWillAppear', () => {
|
|
84
|
+
dispatch(fetchCart());
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Reset the productPendingCount on app start to avoid a wrong value in the cart badge.
|
|
88
|
+
dispatch(setCartProductPendingCount(0));
|
|
89
|
+
});
|
|
90
|
+
subscribe(cartNeedsSync$, ({
|
|
91
|
+
dispatch
|
|
92
|
+
}) => {
|
|
93
|
+
dispatch(fetchCart());
|
|
94
|
+
});
|
|
95
|
+
subscribe(cartBusy$, () => {
|
|
96
|
+
LoadingProvider.setLoading(CART_PATH);
|
|
97
|
+
});
|
|
98
|
+
subscribe(setFulfillmentSlot$, ({
|
|
99
|
+
dispatch,
|
|
100
|
+
getState,
|
|
101
|
+
action
|
|
102
|
+
}) => {
|
|
103
|
+
// When the fulfillment slot is set we need to update all line items.
|
|
104
|
+
let products = getCartProducts(getState());
|
|
105
|
+
if (!products.length || !action?.fulfillmentSlot?.id) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
products = products.filter(product => [ROPIS, BOPIS].includes(product?.fulfillment?.method)).map(product => ({
|
|
109
|
+
cartItemId: product.id,
|
|
110
|
+
fulfillment: {
|
|
111
|
+
slotId: action.fulfillmentSlot.id
|
|
112
|
+
}
|
|
113
|
+
}));
|
|
114
|
+
if (!products.length) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Update the slot id for ROPE products.
|
|
119
|
+
dispatch(updateProductsInCart(products));
|
|
120
|
+
});
|
|
121
|
+
subscribe(cartIdle$, ({
|
|
122
|
+
dispatch,
|
|
123
|
+
getState
|
|
124
|
+
}) => {
|
|
125
|
+
/** Fetch missing products of a cart */
|
|
126
|
+
const productIds = getCartProducts(getState()).map(cartItem => cartItem.product.id);
|
|
127
|
+
if (productIds.length) {
|
|
128
|
+
dispatch(fetchProductsById(productIds));
|
|
129
|
+
}
|
|
130
|
+
LoadingProvider.resetLoading(CART_PATH);
|
|
131
|
+
});
|
|
132
|
+
subscribe(cartDidEnterOrAppDidStart$, ({
|
|
133
|
+
dispatch
|
|
134
|
+
}) => {
|
|
135
|
+
dispatch(fetchRegisterUrl()).catch(e => e);
|
|
136
|
+
});
|
|
137
|
+
subscribe(cartUpdateFailed$, ({
|
|
138
|
+
dispatch,
|
|
139
|
+
action
|
|
140
|
+
}) => {
|
|
141
|
+
/**
|
|
24
142
|
* @type {PipelineErrorElement[]} errors
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
143
|
+
*/
|
|
144
|
+
const {
|
|
145
|
+
errors = [],
|
|
146
|
+
couponsIds = []
|
|
147
|
+
} = action;
|
|
148
|
+
if (Array.isArray(errors) && errors.length) {
|
|
149
|
+
// Supports only one error, because none of the pipelines is ever called with multiple items.
|
|
150
|
+
// Multiple errors would cause the this to overlay multiple modals on top of each other.
|
|
151
|
+
const {
|
|
152
|
+
message,
|
|
153
|
+
handled,
|
|
154
|
+
code,
|
|
155
|
+
additionalParams,
|
|
156
|
+
translated,
|
|
157
|
+
context
|
|
158
|
+
} = errors[0];
|
|
159
|
+
|
|
160
|
+
// Some errors are already handled automatically before
|
|
161
|
+
if (handled) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
errorBehavior.modal()({
|
|
165
|
+
dispatch,
|
|
166
|
+
error: {
|
|
167
|
+
code,
|
|
168
|
+
context,
|
|
169
|
+
meta: {
|
|
170
|
+
message,
|
|
171
|
+
additionalParams,
|
|
172
|
+
translated,
|
|
173
|
+
...(Array.isArray(couponsIds) && couponsIds.length > 0 ? {
|
|
174
|
+
input: {
|
|
175
|
+
couponsIds
|
|
176
|
+
}
|
|
177
|
+
} : null)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
/**
|
|
29
185
|
* Gets triggered when a route with a coupon within its GET parameters will enter.
|
|
30
|
-
*/
|
|
186
|
+
*/
|
|
187
|
+
subscribe(routeWithCouponWillEnter$, ({
|
|
188
|
+
dispatch,
|
|
189
|
+
action
|
|
190
|
+
}) => {
|
|
191
|
+
const {
|
|
192
|
+
coupon
|
|
193
|
+
} = action.route.query;
|
|
194
|
+
if (coupon) {
|
|
195
|
+
dispatch(addCouponsToCart([coupon], false));
|
|
196
|
+
const {
|
|
197
|
+
query,
|
|
198
|
+
pathname
|
|
199
|
+
} = action.route;
|
|
200
|
+
const {
|
|
201
|
+
coupon: c,
|
|
202
|
+
...rest
|
|
203
|
+
} = query;
|
|
204
|
+
dispatch(historyReplace({
|
|
205
|
+
pathname: `${pathname}${parseObjectToQueryString(rest)}`
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
const getFulfillmentMethods = makeGetEnabledFulfillmentMethods();
|
|
210
|
+
|
|
211
|
+
/**
|
|
31
212
|
* Deeplink to add product to cart, eg /cart_add_product/123s
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
213
|
+
*/
|
|
214
|
+
subscribe(routeAddProductNavigate$, async ({
|
|
215
|
+
dispatch,
|
|
216
|
+
action,
|
|
217
|
+
getState
|
|
218
|
+
}) => {
|
|
219
|
+
const state = getState();
|
|
220
|
+
let redirectToPDP = false;
|
|
221
|
+
let fulfillment = null;
|
|
222
|
+
if (hasProductVariety(state, action)) {
|
|
223
|
+
// Redirect to PDP when the product has variants
|
|
224
|
+
redirectToPDP = true;
|
|
225
|
+
} else if (hasNewServices()) {
|
|
226
|
+
const product = getProduct(state, action);
|
|
227
|
+
const preferredLocation = getPreferredLocation(state);
|
|
228
|
+
const preferredFulfillmentMethod = getPreferredFulfillmentMethod(state);
|
|
229
|
+
const shopFulfillmentMethods = getFulfillmentMethods(state);
|
|
230
|
+
if (preferredFulfillmentMethod !== DIRECT_SHIP) {
|
|
231
|
+
let activeLocation = null;
|
|
232
|
+
if (preferredLocation) {
|
|
233
|
+
activeLocation = preferredLocation;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Get fulfillment method that is both active for location and product.
|
|
237
|
+
let activeFulfillmentMethod = preferredFulfillmentMethod;
|
|
238
|
+
const availableFulfillmentMethods = shopFulfillmentMethods?.filter(s => (product?.fulfillmentMethods || []).includes(s)) || [];
|
|
239
|
+
if (activeLocation && !activeFulfillmentMethod && availableFulfillmentMethods.length === 1) {
|
|
240
|
+
[activeFulfillmentMethod] = availableFulfillmentMethods;
|
|
241
|
+
}
|
|
242
|
+
if (!product?.fulfillmentMethods.includes(activeFulfillmentMethod) || false) {
|
|
243
|
+
activeFulfillmentMethod = null;
|
|
244
|
+
}
|
|
245
|
+
if (!activeFulfillmentMethod || !activeLocation) {
|
|
246
|
+
redirectToPDP = true;
|
|
247
|
+
} else {
|
|
248
|
+
fulfillment = {
|
|
249
|
+
method: preferredFulfillmentMethod,
|
|
250
|
+
location: {
|
|
251
|
+
code: preferredLocation.code,
|
|
252
|
+
name: preferredLocation.name || ''
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// NO product or variety
|
|
260
|
+
if (redirectToPDP) {
|
|
261
|
+
// Redirect to item page to select options/variant
|
|
262
|
+
dispatch(historyReplace({
|
|
263
|
+
pathname: getProductRoute(action.productId)
|
|
264
|
+
}));
|
|
265
|
+
} else {
|
|
266
|
+
dispatch(addProductsToCart([{
|
|
267
|
+
productId: action.productId,
|
|
268
|
+
quantity: 1,
|
|
269
|
+
...(fulfillment ? {
|
|
270
|
+
fulfillment
|
|
271
|
+
} : {})
|
|
272
|
+
}]));
|
|
273
|
+
dispatch(historyReplace({
|
|
274
|
+
pathname: CART_PATH
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
/**
|
|
37
280
|
* Deffer coupon adding to a cart, until we have the product from the push message inside cart.
|
|
38
281
|
*
|
|
39
282
|
* Logic was implemented for PWA 6 in ticket no PWA-1809.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
283
|
+
*/
|
|
284
|
+
const addCouponDeferred$ = routeAddProductNavigate$
|
|
285
|
+
// Only if coupon is given
|
|
286
|
+
.filter(({
|
|
287
|
+
action: {
|
|
288
|
+
couponCode = ''
|
|
289
|
+
}
|
|
290
|
+
}) => !!couponCode).filter(() => !hasNewServices()).withLatestFrom(cartReceived$).switchMap(([navigate, cartReceived]) => {
|
|
291
|
+
if (cartReceived.action.cart.cartItems.find(i => i.type === CART_ITEM_TYPE_PRODUCT)) {
|
|
292
|
+
// We have items in cart, add coupon immediately
|
|
293
|
+
return Observable.of(navigate);
|
|
294
|
+
}
|
|
295
|
+
// Wait until first product in cart to add a coupon
|
|
296
|
+
return cartReceived$.filter(cartReceivedNext => cartReceivedNext.action.cart.cartItems.find(i => i.type === CART_ITEM_TYPE_PRODUCT)).first();
|
|
297
|
+
}, ([navigate]) => navigate);
|
|
298
|
+
|
|
299
|
+
/**
|
|
44
300
|
* With the new services, the coupon is added immediately.
|
|
45
|
-
*/
|
|
46
|
-
|
|
301
|
+
*/
|
|
302
|
+
const addCouponImmediately$ = routeAddProductNavigate$
|
|
303
|
+
// Only if coupon is given
|
|
304
|
+
.filter(({
|
|
305
|
+
action: {
|
|
306
|
+
couponCode = ''
|
|
307
|
+
}
|
|
308
|
+
}) => !!couponCode).filter(() => hasNewServices());
|
|
309
|
+
const addCoupon$ = addCouponDeferred$.merge(addCouponImmediately$);
|
|
310
|
+
|
|
311
|
+
/**
|
|
47
312
|
* Deeplink to add product and coupon to cart, eg /cart_add_product/123/COUPON
|
|
48
|
-
*/
|
|
313
|
+
*/
|
|
314
|
+
subscribe(addCoupon$, async ({
|
|
315
|
+
dispatch,
|
|
316
|
+
action
|
|
317
|
+
}) => {
|
|
318
|
+
const {
|
|
319
|
+
couponCode
|
|
320
|
+
} = action;
|
|
321
|
+
if (couponCode) {
|
|
322
|
+
dispatch(addCouponsToCart([couponCode], false));
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import{ERROR_CATEGORY}from"../constants"
|
|
1
|
+
import { ERROR_CATEGORY } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the ERROR_CATEGORY action.
|
|
3
5
|
* @param {string} categoryId The ID of the received category.
|
|
4
6
|
* @param {string} errorCode The error code.
|
|
5
7
|
* @return {Object} The ERROR_CATEGORY action.
|
|
6
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
const errorCategory = (categoryId, errorCode) => ({
|
|
10
|
+
type: ERROR_CATEGORY,
|
|
11
|
+
categoryId,
|
|
12
|
+
errorCode
|
|
13
|
+
});
|
|
14
|
+
export default errorCategory;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import{ERROR_CATEGORY_CHILDREN}from"../constants"
|
|
1
|
+
import { ERROR_CATEGORY_CHILDREN } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the ERROR_CATEGORY_CHILDREN action.
|
|
3
5
|
* @param {string} categoryId The ID of the category to receive children for.
|
|
4
6
|
* @return {Object} The ERROR_CATEGORY_CHILDREN action.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const errorCategoryChildren = categoryId => ({
|
|
9
|
+
type: ERROR_CATEGORY_CHILDREN,
|
|
10
|
+
categoryId
|
|
11
|
+
});
|
|
12
|
+
export default errorCategoryChildren;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import{ERROR_ROOT_CATEGORIES}from"../constants"
|
|
1
|
+
import { ERROR_ROOT_CATEGORIES } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the ERROR_ROOT_CATEGORIES action.
|
|
3
5
|
* @return {Object} The ERROR_ROOT_CATEGORIES action.
|
|
4
|
-
*/
|
|
6
|
+
*/
|
|
7
|
+
const errorRootCategories = () => ({
|
|
8
|
+
type: ERROR_ROOT_CATEGORIES
|
|
9
|
+
});
|
|
10
|
+
export default errorRootCategories;
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import{RECEIVE_CATEGORY}from"../constants"
|
|
1
|
+
import { RECEIVE_CATEGORY } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the RECEIVE_CATEGORY action.
|
|
3
5
|
* @param {string} categoryId The ID of the received category.
|
|
4
6
|
* @param {Object} categoryData The data of the received category.
|
|
5
7
|
* @param {Array} categoryChildren The children of received category.
|
|
6
8
|
* @return {Object} The RECEIVE_CATEGORY action.
|
|
7
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const receiveCategory = (categoryId, categoryData, categoryChildren) => ({
|
|
11
|
+
type: RECEIVE_CATEGORY,
|
|
12
|
+
categoryId,
|
|
13
|
+
categoryData,
|
|
14
|
+
categoryChildren,
|
|
15
|
+
products: []
|
|
16
|
+
});
|
|
17
|
+
export default receiveCategory;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import{RECEIVE_CATEGORY_CHILDREN}from"../constants"
|
|
1
|
+
import { RECEIVE_CATEGORY_CHILDREN } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the RECEIVE_CATEGORY_CHILDREN action.
|
|
3
5
|
* @param {string} categoryId The ID of the category to receive children for.
|
|
4
6
|
* @param {Array} categoryChildren The requested category children.
|
|
5
7
|
* @return {Object} The RECEIVE_CATEGORY_CHILDREN action.
|
|
6
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
const receiveCategoryChildren = (categoryId, categoryChildren) => ({
|
|
10
|
+
type: RECEIVE_CATEGORY_CHILDREN,
|
|
11
|
+
categoryId,
|
|
12
|
+
categoryChildren
|
|
13
|
+
});
|
|
14
|
+
export default receiveCategoryChildren;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import{RECEIVE_ROOT_CATEGORIES}from"../constants"
|
|
1
|
+
import { RECEIVE_ROOT_CATEGORIES } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the RECEIVE_ROOT_CATEGORIES action.
|
|
3
5
|
* @param {Array} categories The received root categories.
|
|
4
6
|
* @return {Object} The RECEIVE_ROOT_CATEGORIES action.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const receiveRootCategories = categories => ({
|
|
9
|
+
type: RECEIVE_ROOT_CATEGORIES,
|
|
10
|
+
categories
|
|
11
|
+
});
|
|
12
|
+
export default receiveRootCategories;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import{REQUEST_CATEGORY}from"../constants"
|
|
1
|
+
import { REQUEST_CATEGORY } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the REQUEST_CATEGORY action.
|
|
3
5
|
* @param {string} categoryId The ID of the category to be requested.
|
|
4
6
|
* @return {Object} The REQUEST_CATEGORY action.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const requestCategory = categoryId => ({
|
|
9
|
+
type: REQUEST_CATEGORY,
|
|
10
|
+
categoryId
|
|
11
|
+
});
|
|
12
|
+
export default requestCategory;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import{REQUEST_CATEGORY_CHILDREN}from"../constants"
|
|
1
|
+
import { REQUEST_CATEGORY_CHILDREN } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the REQUEST_CATEGORY_CHILDREN action.
|
|
3
5
|
* @param {string} categoryId The ID of the category to request children for.
|
|
4
6
|
* @return {Object} The REQUEST_CATEGORY_CHILDREN action.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const requestCategoryChildren = categoryId => ({
|
|
9
|
+
type: REQUEST_CATEGORY_CHILDREN,
|
|
10
|
+
categoryId
|
|
11
|
+
});
|
|
12
|
+
export default requestCategoryChildren;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import{REQUEST_ROOT_CATEGORIES}from"../constants"
|
|
1
|
+
import { REQUEST_ROOT_CATEGORIES } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the REQUEST_ROOT_CATEGORIES action.
|
|
3
5
|
* @return {Object} The REQUEST_ROOT_CATEGORIES action.
|
|
4
|
-
*/
|
|
6
|
+
*/
|
|
7
|
+
const requestRootCategories = () => ({
|
|
8
|
+
type: REQUEST_ROOT_CATEGORIES
|
|
9
|
+
});
|
|
10
|
+
export default requestRootCategories;
|
|
@@ -1,11 +1,53 @@
|
|
|
1
|
-
import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';
|
|
1
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
2
|
+
import { shouldFetchData, mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
3
|
+
import { errorBehavior } from '@shopgate/engage/core';
|
|
4
|
+
import { SHOPGATE_CATALOG_GET_CATEGORY } from "../constants/Pipelines";
|
|
5
|
+
import fetchCategoryChildren from "./fetchCategoryChildren";
|
|
6
|
+
import requestCategory from "../action-creators/requestCategory";
|
|
7
|
+
import receiveCategory from "../action-creators/receiveCategory";
|
|
8
|
+
import errorCategory from "../action-creators/errorCategory";
|
|
9
|
+
import { getCategory } from "../selectors";
|
|
10
|
+
|
|
11
|
+
/**
|
|
2
12
|
* Fetches the data for a given category ID (including child categories).
|
|
3
13
|
* @param {string} categoryId The category ID.
|
|
4
14
|
* @return {Function} The dispatched action.
|
|
5
|
-
*/
|
|
6
|
-
|
|
15
|
+
*/
|
|
16
|
+
function fetchCategory(categoryId) {
|
|
17
|
+
return (dispatch, getState) => {
|
|
18
|
+
const category = getCategory(getState(), {
|
|
19
|
+
categoryId
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Check if we need to fetch data
|
|
23
|
+
if (!shouldFetchData(category)) {
|
|
24
|
+
/**
|
|
7
25
|
* Child categories are maybe missing.
|
|
8
26
|
* So we need to check it (check happens inside fetchCategoryChildren).
|
|
9
27
|
* This is the case if we got categories from getRootCategory
|
|
10
|
-
*/
|
|
11
|
-
|
|
28
|
+
*/
|
|
29
|
+
if (category.childrenCount) {
|
|
30
|
+
dispatch(fetchCategoryChildren(categoryId));
|
|
31
|
+
}
|
|
32
|
+
return Promise.resolve(category);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// No data at all. So we have to fetch the category with children included
|
|
36
|
+
dispatch(requestCategory(categoryId));
|
|
37
|
+
const request = new PipelineRequest(SHOPGATE_CATALOG_GET_CATEGORY).setInput({
|
|
38
|
+
categoryId,
|
|
39
|
+
includeChildren: true
|
|
40
|
+
}).setResponseBehavior({
|
|
41
|
+
error: errorBehavior.modal()
|
|
42
|
+
}).dispatch();
|
|
43
|
+
request.then(result => {
|
|
44
|
+
dispatch(receiveCategory(categoryId, result, result.children || []));
|
|
45
|
+
}).catch(error => {
|
|
46
|
+
dispatch(errorCategory(categoryId, error.code));
|
|
47
|
+
});
|
|
48
|
+
return request;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @mixes {MutableFunction} */
|
|
53
|
+
export default mutable(fetchCategory);
|
|
@@ -1,5 +1,33 @@
|
|
|
1
|
-
import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';
|
|
1
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
2
|
+
import { shouldFetchData, mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
3
|
+
import { SHOPGATE_CATALOG_GET_CATEGORY_CHILDREN } from "../constants/Pipelines";
|
|
4
|
+
import requestCategoryChildren from "../action-creators/requestCategoryChildren";
|
|
5
|
+
import receiveCategoryChildren from "../action-creators/receiveCategoryChildren";
|
|
6
|
+
import errorCategoryChildren from "../action-creators/errorCategoryChildren";
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* Retrieves category children for a certain category by ID.
|
|
3
10
|
* @param {string} categoryId The ID of the category to request children for.
|
|
4
11
|
* @return {Function} The dispatched action.
|
|
5
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
function fetchCategoryChildren(categoryId) {
|
|
14
|
+
return (dispatch, getState) => {
|
|
15
|
+
const category = getState().category.childrenByCategoryId[categoryId];
|
|
16
|
+
if (!shouldFetchData(category, 'children')) {
|
|
17
|
+
return Promise.resolve(null);
|
|
18
|
+
}
|
|
19
|
+
dispatch(requestCategoryChildren(categoryId));
|
|
20
|
+
const request = new PipelineRequest(SHOPGATE_CATALOG_GET_CATEGORY_CHILDREN).setInput({
|
|
21
|
+
categoryId
|
|
22
|
+
}).dispatch();
|
|
23
|
+
request.then(result => {
|
|
24
|
+
dispatch(receiveCategoryChildren(categoryId, result.categories));
|
|
25
|
+
}).catch(() => {
|
|
26
|
+
dispatch(errorCategoryChildren(categoryId));
|
|
27
|
+
});
|
|
28
|
+
return request;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @mixes {MutableFunction} */
|
|
33
|
+
export default mutable(fetchCategoryChildren);
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import{mutable}from'@shopgate/pwa-common/helpers/redux';
|
|
1
|
+
import { mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
2
|
+
import fetchRootCategories from "./fetchRootCategories";
|
|
3
|
+
import fetchCategory from "./fetchCategory";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Retrieves a category from the server when a categoryId is given. Otherwise it will fetch the
|
|
3
7
|
* root categories.
|
|
4
8
|
* @param {string} categoryId The category ID.
|
|
5
9
|
* @return {Function} The dispatched action.
|
|
6
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
function fetchCategoryOrRootCategories(categoryId) {
|
|
12
|
+
return dispatch => {
|
|
13
|
+
if (!categoryId) {
|
|
14
|
+
dispatch(fetchRootCategories());
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
dispatch(fetchCategory(categoryId));
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export default mutable(fetchCategoryOrRootCategories);
|