@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,5 +1,12 @@
|
|
|
1
|
-
import{REQUEST_PRODUCT_MEDIA}from"../constants"
|
|
1
|
+
import { REQUEST_PRODUCT_MEDIA } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the REQUEST_PRODUCT_MEDIA action.
|
|
3
5
|
* @param {string} productId The ID of the product for which the options are requested.
|
|
4
6
|
* @return {Object}
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const requestProductMedia = productId => ({
|
|
9
|
+
type: REQUEST_PRODUCT_MEDIA,
|
|
10
|
+
productId
|
|
11
|
+
});
|
|
12
|
+
export default requestProductMedia;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import{REQUEST_PRODUCT_OPTIONS}from"../constants"
|
|
1
|
+
import { REQUEST_PRODUCT_OPTIONS } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the REQUEST_PRODUCT_OPTIONS action.
|
|
3
5
|
* @param {string} productId The ID of the product for which the options are requested.
|
|
4
6
|
* @return {Object} The REQUEST_PRODUCT_OPTIONS action.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const requestProductOptions = productId => ({
|
|
9
|
+
type: REQUEST_PRODUCT_OPTIONS,
|
|
10
|
+
productId
|
|
11
|
+
});
|
|
12
|
+
export default requestProductOptions;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import{REQUEST_PRODUCT_PROPERTIES}from"../constants"
|
|
1
|
+
import { REQUEST_PRODUCT_PROPERTIES } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Creates the dispatched REQUEST_PRODUCT_PROPERTIES action object.
|
|
3
5
|
* @param {string} productId The ID of the product that requests properties.
|
|
4
6
|
* @return {Object} The REQUEST_PRODUCT_PROPERTIES action.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const requestProductProperties = productId => ({
|
|
9
|
+
type: REQUEST_PRODUCT_PROPERTIES,
|
|
10
|
+
productId
|
|
11
|
+
});
|
|
12
|
+
export default requestProductProperties;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import{REQUEST_PRODUCT_RELATIONS}from"../constants"
|
|
1
|
+
import { REQUEST_PRODUCT_RELATIONS } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Request product relations action.
|
|
3
5
|
* @param {Object} params Params.
|
|
4
6
|
* @param {string} params.hash Query hash.
|
|
5
7
|
* @returns {Object}
|
|
6
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
export default ({
|
|
10
|
+
hash
|
|
11
|
+
}) => ({
|
|
12
|
+
type: REQUEST_PRODUCT_RELATIONS,
|
|
13
|
+
hash
|
|
14
|
+
});
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import{REQUEST_PRODUCT_SHIPPING}from"../constants"
|
|
1
|
+
import { REQUEST_PRODUCT_SHIPPING } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the REQUEST_PRODUCT_SHIPPING action.
|
|
3
5
|
* @param {string} productId The ID of the product for which the shipping is requested.
|
|
4
6
|
* @return {Object} The REQUEST_PRODUCT_SHIPPING action.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const requestProductShipping = productId => ({
|
|
9
|
+
type: REQUEST_PRODUCT_SHIPPING,
|
|
10
|
+
productId
|
|
11
|
+
});
|
|
12
|
+
export default requestProductShipping;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import{REQUEST_PRODUCT_VARIANTS}from"../constants"
|
|
1
|
+
import { REQUEST_PRODUCT_VARIANTS } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Dispatches the REQUEST_PRODUCT_VARIANTS action.
|
|
3
5
|
* @param {string} productId The ID of the product for which the variants are requested.
|
|
4
6
|
* @return {Object} The REQUEST_PRODUCT_VARIANTS action.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const requestProductVariants = productId => ({
|
|
9
|
+
type: REQUEST_PRODUCT_VARIANTS,
|
|
10
|
+
productId
|
|
11
|
+
});
|
|
12
|
+
export default requestProductVariants;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { REQUEST_PRODUCTS } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Creates the dispatched REQUEST_PRODUCTS action object.
|
|
3
5
|
* @param {Object} payload The action payload.
|
|
4
6
|
* @param {string} payload.hash The store hash.
|
|
5
7
|
* @param {Object} payload.params The criteria of the products received.
|
|
6
8
|
* @param {string} params The criteria of the products to request.
|
|
7
9
|
* @return {Object} The REQUEST_PRODUCTS action.
|
|
8
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
const requestProducts = payload => ({
|
|
12
|
+
type: REQUEST_PRODUCTS,
|
|
13
|
+
...payload
|
|
14
|
+
});
|
|
15
|
+
export default requestProducts;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import{SET_PRODUCT_ID}from"../constants"
|
|
1
|
+
import { SET_PRODUCT_ID } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Creates the dispatched SET_PRODUCT_ID action object.
|
|
3
5
|
* @param {string|null} productId The product id.
|
|
4
6
|
* @returns {Object} The dispatched action object.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const setProductId = productId => ({
|
|
9
|
+
type: SET_PRODUCT_ID,
|
|
10
|
+
productId
|
|
11
|
+
});
|
|
12
|
+
export default setProductId;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import{SET_PRODUCT_QUANTITY}from"../constants"
|
|
1
|
+
import { SET_PRODUCT_QUANTITY } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Creates the dispatched SET_PRODUCT_QUANTITY action object.
|
|
3
5
|
* @param {number} quantity The product variant id.
|
|
4
6
|
* @returns {Object} The dispatched action object.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const setProductQuantity = quantity => ({
|
|
9
|
+
type: SET_PRODUCT_QUANTITY,
|
|
10
|
+
quantity
|
|
11
|
+
});
|
|
12
|
+
export default setProductQuantity;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import{SET_PRODUCT_VARIANT_ID}from"../constants"
|
|
1
|
+
import { SET_PRODUCT_VARIANT_ID } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Creates the dispatched SET_PRODUCT_VARIANTS_ID action object.
|
|
3
5
|
* @param {string|null} productVariantId The product variant id.
|
|
4
6
|
* @returns {Object} The dispatched action object.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const setProductVariantId = productVariantId => ({
|
|
9
|
+
type: SET_PRODUCT_VARIANT_ID,
|
|
10
|
+
productVariantId
|
|
11
|
+
});
|
|
12
|
+
export default setProductVariantId;
|
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import { historyReplace } from '@shopgate/pwa-common/actions/router';
|
|
2
|
+
import { getCurrentRoute } from '@shopgate/pwa-common/selectors/router';
|
|
3
|
+
import { parseObjectToQueryString } from '@shopgate/pwa-common/helpers/router';
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Updates the sort parameter in the history.
|
|
3
7
|
* @param {string} sort The sort order
|
|
4
8
|
* @returns {Function} A redux thunk.
|
|
5
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const changeSortOrder = sort => (dispatch, getState) => {
|
|
11
|
+
const {
|
|
12
|
+
query,
|
|
13
|
+
state
|
|
14
|
+
} = getCurrentRoute(getState());
|
|
15
|
+
const newQuery = parseObjectToQueryString({
|
|
16
|
+
...query,
|
|
17
|
+
sort
|
|
18
|
+
});
|
|
19
|
+
dispatch(historyReplace({
|
|
20
|
+
pathname: `${window.location.pathname}${newQuery}`,
|
|
21
|
+
state
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
export default changeSortOrder;
|
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
import*as pipelines from"../constants/Pipelines";
|
|
1
|
+
import * as pipelines from "../constants/Pipelines";
|
|
2
|
+
import fetchProducts from "./fetchProducts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* Maybe requests highlight products from server.
|
|
3
6
|
* @param {Object} options The options for the fetchProducts request.
|
|
4
7
|
* @param {Object} options.params The params for the getHighlightProducts pipeline.
|
|
5
8
|
* @param {string} [options.id=null] A unique id for the component that is using this action.
|
|
6
9
|
* @return {Function} The dispatched action.
|
|
7
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
const fetchHighlightProducts = ({
|
|
12
|
+
params,
|
|
13
|
+
id = null
|
|
14
|
+
}) => dispatch => {
|
|
15
|
+
dispatch(fetchProducts({
|
|
16
|
+
pipeline: pipelines.SHOPGATE_CATALOG_GET_HIGHLIGHT_PRODUCTS,
|
|
17
|
+
params,
|
|
18
|
+
id,
|
|
19
|
+
includeSort: true,
|
|
20
|
+
includeFilters: false
|
|
21
|
+
}));
|
|
22
|
+
};
|
|
23
|
+
export default fetchHighlightProducts;
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import*as pipelines from"../constants/Pipelines";
|
|
1
|
+
import * as pipelines from "../constants/Pipelines";
|
|
2
|
+
import fetchProducts from "./fetchProducts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* Retrieves the information for the liveshopping products widget.
|
|
3
6
|
* @return {Function} A redux thunk.
|
|
4
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const fetchLiveshoppingProducts = () => dispatch => {
|
|
9
|
+
dispatch(fetchProducts({
|
|
10
|
+
pipeline: pipelines.SHOPGATE_CATALOG_GET_LIVESHOPPING_PRODUCTS,
|
|
11
|
+
cached: false,
|
|
12
|
+
includeFilters: false,
|
|
13
|
+
includeSort: false
|
|
14
|
+
}));
|
|
15
|
+
};
|
|
16
|
+
export default fetchLiveshoppingProducts;
|
|
@@ -1,9 +1,58 @@
|
|
|
1
|
-
|
|
1
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
2
|
+
import configuration from '@shopgate/pwa-common/collections/Configuration';
|
|
3
|
+
import { DEFAULT_PRODUCTS_FETCH_PARAMS } from '@shopgate/pwa-common/constants/Configuration';
|
|
4
|
+
import { shouldFetchData, mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
5
|
+
import { LoadingProvider } from '@shopgate/pwa-common/providers';
|
|
6
|
+
import { getCurrentPathname } from '@shopgate/pwa-common/selectors/router';
|
|
7
|
+
import { SHOPGATE_CATALOG_GET_PRODUCT } from "../constants/Pipelines";
|
|
8
|
+
import requestProduct from "../action-creators/requestProduct";
|
|
9
|
+
import receiveProduct from "../action-creators/receiveProduct";
|
|
10
|
+
import errorProduct from "../action-creators/errorProduct";
|
|
11
|
+
import receiveProductCached from "../action-creators/receiveProductCached";
|
|
12
|
+
import { getProductById } from "../selectors/product";
|
|
13
|
+
|
|
14
|
+
/**
|
|
2
15
|
* Retrieves a product from the Redux store.
|
|
3
16
|
* @param {string} productId The product ID.
|
|
4
17
|
* @param {boolean} forceFetch Skips shouldFetchData check. Always fetches.
|
|
5
18
|
* @return {Function} A redux thunk.
|
|
6
|
-
*/
|
|
19
|
+
*/
|
|
20
|
+
function fetchProduct(productId, forceFetch = false) {
|
|
21
|
+
return (dispatch, getState) => {
|
|
22
|
+
const state = getState();
|
|
23
|
+
const product = getProductById(state, {
|
|
24
|
+
productId
|
|
25
|
+
});
|
|
26
|
+
if (!forceFetch && !shouldFetchData(product)) {
|
|
27
|
+
if (product.productData) {
|
|
28
|
+
/*
|
|
7
29
|
This timeout is needed here to make sure receivedVisibleProduct$ comes after
|
|
8
30
|
productWillEnter$. Otherwise productIsReady$ is not working correctly.
|
|
9
|
-
*/
|
|
31
|
+
*/
|
|
32
|
+
setTimeout(() => {
|
|
33
|
+
dispatch(receiveProductCached(product.productData));
|
|
34
|
+
}, 0);
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const path = getCurrentPathname(state);
|
|
39
|
+
LoadingProvider.setLoading(path);
|
|
40
|
+
const requestParams = {
|
|
41
|
+
...configuration.get(DEFAULT_PRODUCTS_FETCH_PARAMS),
|
|
42
|
+
productId
|
|
43
|
+
};
|
|
44
|
+
dispatch(requestProduct(productId, forceFetch));
|
|
45
|
+
const request = new PipelineRequest(SHOPGATE_CATALOG_GET_PRODUCT).setInput(requestParams).dispatch();
|
|
46
|
+
request.then(result => {
|
|
47
|
+
LoadingProvider.unsetLoading(path);
|
|
48
|
+
dispatch(receiveProduct(productId, result));
|
|
49
|
+
}).catch(error => {
|
|
50
|
+
LoadingProvider.unsetLoading(path);
|
|
51
|
+
dispatch(errorProduct(productId, error.code));
|
|
52
|
+
});
|
|
53
|
+
return request;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @mixes {MutableFunction} */
|
|
58
|
+
export default mutable(fetchProduct);
|
|
@@ -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 requestProductDescription from "../action-creators/requestProductDescription";
|
|
4
|
+
import { SHOPGATE_CATALOG_GET_PRODUCT_DESCRIPTION } from "../constants/Pipelines";
|
|
5
|
+
import receiveProductDescription from "../action-creators/receiveProductDescription";
|
|
6
|
+
import errorProductDescription from "../action-creators/errorProductDescription";
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* Maybe requests a product description from server.
|
|
3
10
|
* @param {string} productId The product ID.
|
|
4
11
|
* @return {Function} The dispatched action.
|
|
5
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
function fetchProductDescription(productId) {
|
|
14
|
+
return (dispatch, getState) => {
|
|
15
|
+
const description = getState().product.descriptionsByProductId[productId];
|
|
16
|
+
if (!shouldFetchData(description)) {
|
|
17
|
+
return Promise.resolve(null);
|
|
18
|
+
}
|
|
19
|
+
dispatch(requestProductDescription(productId));
|
|
20
|
+
const request = new PipelineRequest(SHOPGATE_CATALOG_GET_PRODUCT_DESCRIPTION).setInput({
|
|
21
|
+
productId
|
|
22
|
+
}).dispatch();
|
|
23
|
+
request.then(result => {
|
|
24
|
+
dispatch(receiveProductDescription(productId, result.description));
|
|
25
|
+
}).catch(error => {
|
|
26
|
+
dispatch(errorProductDescription(productId, error.code));
|
|
27
|
+
});
|
|
28
|
+
return request;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @mixes {MutableFunction} */
|
|
33
|
+
export default mutable(fetchProductDescription);
|
|
@@ -1,5 +1,34 @@
|
|
|
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 requestProductImages from "../action-creators/requestProductImages";
|
|
4
|
+
import { SHOPGATE_CATALOG_GET_PRODUCT_IMAGES } from "../constants/Pipelines";
|
|
5
|
+
import receiveProductImages from "../action-creators/receiveProductImages";
|
|
6
|
+
import errorProductImages from "../action-creators/errorProductImages";
|
|
7
|
+
import { getProductImagesState } from "../selectors/product";
|
|
8
|
+
|
|
9
|
+
/**
|
|
2
10
|
* Maybe requests images for a product from server.
|
|
3
11
|
* @param {string} productId The product ID.
|
|
4
12
|
* @return {Function} The dispatched action.
|
|
5
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
function fetchProductImages(productId) {
|
|
15
|
+
return (dispatch, getState) => {
|
|
16
|
+
const productImages = getProductImagesState(getState())[productId];
|
|
17
|
+
if (!shouldFetchData(productImages)) {
|
|
18
|
+
return Promise.resolve(null);
|
|
19
|
+
}
|
|
20
|
+
dispatch(requestProductImages(productId));
|
|
21
|
+
const request = new PipelineRequest(SHOPGATE_CATALOG_GET_PRODUCT_IMAGES).setInput({
|
|
22
|
+
productId
|
|
23
|
+
}).setVersion(3).dispatch();
|
|
24
|
+
request.then(result => {
|
|
25
|
+
dispatch(receiveProductImages(productId, result.images));
|
|
26
|
+
}).catch(error => {
|
|
27
|
+
dispatch(errorProductImages(productId, error.code));
|
|
28
|
+
});
|
|
29
|
+
return request;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @mixes {MutableFunction} */
|
|
34
|
+
export default mutable(fetchProductImages);
|
|
@@ -1,5 +1,38 @@
|
|
|
1
|
-
import appConfig from'@shopgate/pwa-common/helpers/config';
|
|
1
|
+
import appConfig from '@shopgate/pwa-common/helpers/config';
|
|
2
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
3
|
+
import { shouldFetchData, mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
4
|
+
import { SHOPGATE_CATALOG_GET_PRODUCT_MEDIA } from "../constants/Pipelines";
|
|
5
|
+
import requestProductMedia from "../action-creators/requestProductMedia";
|
|
6
|
+
import receiveProductMedia from "../action-creators/receiveProductMedia";
|
|
7
|
+
import errorProductMedia from "../action-creators/errorProductMedia";
|
|
8
|
+
|
|
9
|
+
/**
|
|
2
10
|
* Retrieves product options from store.
|
|
3
11
|
* @param {string} productId The product ID for which the product options are requested.
|
|
4
12
|
* @return {Function} A Redux Thunk
|
|
5
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
function fetchProductMedia(productId) {
|
|
15
|
+
return (dispatch, getState) => {
|
|
16
|
+
if (!appConfig.beta) {
|
|
17
|
+
return Promise.resolve(null);
|
|
18
|
+
}
|
|
19
|
+
const state = getState();
|
|
20
|
+
const cachedData = state.product.mediaByProductId[productId];
|
|
21
|
+
if (!shouldFetchData(cachedData)) {
|
|
22
|
+
return Promise.resolve(null);
|
|
23
|
+
}
|
|
24
|
+
dispatch(requestProductMedia(productId));
|
|
25
|
+
const request = new PipelineRequest(SHOPGATE_CATALOG_GET_PRODUCT_MEDIA).setInput({
|
|
26
|
+
productId
|
|
27
|
+
}).dispatch();
|
|
28
|
+
request.then(result => {
|
|
29
|
+
dispatch(receiveProductMedia(productId, result.media));
|
|
30
|
+
}).catch(error => {
|
|
31
|
+
dispatch(errorProductMedia(productId, error.code));
|
|
32
|
+
});
|
|
33
|
+
return request;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @mixes {MutableFunction} */
|
|
38
|
+
export default mutable(fetchProductMedia);
|
|
@@ -1,5 +1,34 @@
|
|
|
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 requestProductOptions from "../action-creators/requestProductOptions";
|
|
4
|
+
import { SHOPGATE_CATALOG_GET_PRODUCT_OPTIONS } from "../constants/Pipelines";
|
|
5
|
+
import receiveProductOptions from "../action-creators/receiveProductOptions";
|
|
6
|
+
import errorProductOptions from "../action-creators/errorProductOptions";
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* Retrieves product options from store.
|
|
3
10
|
* @param {string} productId The product ID for which the product options are requested.
|
|
4
11
|
* @return {Function} A Redux Thunk
|
|
5
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
function fetchProductOptions(productId) {
|
|
14
|
+
return (dispatch, getState) => {
|
|
15
|
+
const state = getState();
|
|
16
|
+
const cachedData = state.product.optionsByProductId[productId];
|
|
17
|
+
if (!shouldFetchData(cachedData)) {
|
|
18
|
+
return Promise.resolve(null);
|
|
19
|
+
}
|
|
20
|
+
dispatch(requestProductOptions(productId));
|
|
21
|
+
const request = new PipelineRequest(SHOPGATE_CATALOG_GET_PRODUCT_OPTIONS).setInput({
|
|
22
|
+
productId
|
|
23
|
+
}).dispatch();
|
|
24
|
+
request.then(result => {
|
|
25
|
+
dispatch(receiveProductOptions(productId, result.options));
|
|
26
|
+
}).catch(error => {
|
|
27
|
+
dispatch(errorProductOptions(productId, error.code));
|
|
28
|
+
});
|
|
29
|
+
return request;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @mixes {MutableFunction} */
|
|
34
|
+
export default mutable(fetchProductOptions);
|
|
@@ -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 requestProductProperties from "../action-creators/requestProductProperties";
|
|
4
|
+
import { SHOPGATE_CATALOG_GET_PRODUCT_PROPERTIES } from "../constants/Pipelines";
|
|
5
|
+
import receiveProductProperties from "../action-creators/receiveProductProperties";
|
|
6
|
+
import errorProductProperties from "../action-creators/errorProductProperties";
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* Maybe requests a product description from server.
|
|
3
10
|
* @param {string} productId The product ID.
|
|
4
11
|
* @return {Function} The dispatched action.
|
|
5
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
function fetchProductProperties(productId) {
|
|
14
|
+
return (dispatch, getState) => {
|
|
15
|
+
const properties = getState().product.propertiesByProductId[productId];
|
|
16
|
+
if (!shouldFetchData(properties)) {
|
|
17
|
+
return Promise.resolve(null);
|
|
18
|
+
}
|
|
19
|
+
dispatch(requestProductProperties(productId));
|
|
20
|
+
const request = new PipelineRequest(SHOPGATE_CATALOG_GET_PRODUCT_PROPERTIES).setInput({
|
|
21
|
+
productId
|
|
22
|
+
}).dispatch();
|
|
23
|
+
request.then(result => {
|
|
24
|
+
dispatch(receiveProductProperties(productId, result.properties));
|
|
25
|
+
}).catch(error => {
|
|
26
|
+
dispatch(errorProductProperties(productId, error.code));
|
|
27
|
+
});
|
|
28
|
+
return request;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @mixes {MutableFunction} */
|
|
33
|
+
export default mutable(fetchProductProperties);
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';
|
|
1
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
2
|
+
import { logger } from '@shopgate/pwa-core/helpers';
|
|
3
|
+
import { shouldFetchData, mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
4
|
+
import receiveProductRelations from "../action-creators/receiveProductRelations";
|
|
5
|
+
import requestProductRelations from "../action-creators/requestProductRelations";
|
|
6
|
+
import errorProductRelations from "../action-creators/errorProductRelations";
|
|
7
|
+
import { SHOPGATE_CATALOG_GET_PRODUCT_RELATIONS } from "../constants/Pipelines";
|
|
8
|
+
import { generateProductRelationsHash } from "../helpers";
|
|
9
|
+
import { getProductRelationsState } from "../selectors/relations";
|
|
10
|
+
import { PRODUCT_RELATIONS_DEFAULT_LIMIT } from "../constants";
|
|
11
|
+
|
|
12
|
+
/**
|
|
2
13
|
* Action starts product relation fetching process.
|
|
3
14
|
* Returns early if product relation cache is still valid.
|
|
4
15
|
* @param {Object} params Params.
|
|
@@ -6,4 +17,54 @@ import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{l
|
|
|
6
17
|
* @param {string} params.type Type (see constants).
|
|
7
18
|
* @param {number} params.limit Query limit.
|
|
8
19
|
* @returns {Function}
|
|
9
|
-
*/
|
|
20
|
+
*/
|
|
21
|
+
function fetchProductRelations({
|
|
22
|
+
productId,
|
|
23
|
+
type,
|
|
24
|
+
limit = PRODUCT_RELATIONS_DEFAULT_LIMIT
|
|
25
|
+
}) {
|
|
26
|
+
return (dispatch, getState) => {
|
|
27
|
+
const pipeline = SHOPGATE_CATALOG_GET_PRODUCT_RELATIONS;
|
|
28
|
+
const hash = generateProductRelationsHash({
|
|
29
|
+
productId,
|
|
30
|
+
type,
|
|
31
|
+
limit
|
|
32
|
+
});
|
|
33
|
+
const currentState = getProductRelationsState(getState())[hash];
|
|
34
|
+
if (!shouldFetchData(currentState, 'productIds')) {
|
|
35
|
+
return Promise.resolve(null);
|
|
36
|
+
}
|
|
37
|
+
dispatch(requestProductRelations({
|
|
38
|
+
hash
|
|
39
|
+
}));
|
|
40
|
+
const request = new PipelineRequest(pipeline).setInput({
|
|
41
|
+
productId,
|
|
42
|
+
type,
|
|
43
|
+
limit
|
|
44
|
+
}).dispatch();
|
|
45
|
+
request.then(payload => {
|
|
46
|
+
const {
|
|
47
|
+
relations
|
|
48
|
+
} = payload;
|
|
49
|
+
if (!Array.isArray(relations)) {
|
|
50
|
+
logger.error(new Error(`Invalid ${pipeline} pipeline response`), payload);
|
|
51
|
+
dispatch(errorProductRelations({
|
|
52
|
+
hash
|
|
53
|
+
}));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
dispatch(receiveProductRelations({
|
|
57
|
+
hash,
|
|
58
|
+
payload
|
|
59
|
+
}));
|
|
60
|
+
}).catch(() => {
|
|
61
|
+
dispatch(errorProductRelations({
|
|
62
|
+
hash
|
|
63
|
+
}));
|
|
64
|
+
});
|
|
65
|
+
return request;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @mixes {MutableFunction} */
|
|
70
|
+
export default mutable(fetchProductRelations);
|
|
@@ -1,5 +1,34 @@
|
|
|
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_PRODUCT_SHIPPING } from "../constants/Pipelines";
|
|
4
|
+
import requestProductShipping from "../action-creators/requestProductShipping";
|
|
5
|
+
import receiveProductShipping from "../action-creators/receiveProductShipping";
|
|
6
|
+
import errorProductShipping from "../action-creators/errorProductShipping";
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* Retrieves product shipping from the store.
|
|
3
10
|
* @param {string} productId The product ID for which the product shipping is requested.
|
|
4
11
|
* @return {Function} A Redux Thunk
|
|
5
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
function fetchProductShipping(productId) {
|
|
14
|
+
return (dispatch, getState) => {
|
|
15
|
+
const state = getState();
|
|
16
|
+
const shipping = state.product.shippingByProductId[productId];
|
|
17
|
+
if (!shouldFetchData(shipping)) {
|
|
18
|
+
return Promise.resolve(null);
|
|
19
|
+
}
|
|
20
|
+
dispatch(requestProductShipping(productId));
|
|
21
|
+
const request = new PipelineRequest(SHOPGATE_CATALOG_GET_PRODUCT_SHIPPING).setInput({
|
|
22
|
+
productId
|
|
23
|
+
}).dispatch();
|
|
24
|
+
request.then(result => {
|
|
25
|
+
dispatch(receiveProductShipping(productId, result.shipping));
|
|
26
|
+
}).catch(error => {
|
|
27
|
+
dispatch(errorProductShipping(productId, error.code));
|
|
28
|
+
});
|
|
29
|
+
return request;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @mixes {MutableFunction} */
|
|
34
|
+
export default mutable(fetchProductShipping);
|