@shopgate/pwa-common-commerce
Version:
Commerce library for the Shopgate Connect PWA.
9 lines • 1.95 kB
JavaScript
import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{PROCESS_SEQUENTIAL}from'@shopgate/pwa-core/constants/ProcessTypes';import{mutable}from'@shopgate/pwa-common/helpers/redux';import{SHOPGATE_CART_DELETE_PRODUCTS}from"../constants/Pipelines";import createPipelineErrorList from"../helpers/createPipelineErrorList";import{ECART}from"../constants/PipelineErrors";import deleteProducts from"../action-creators/deleteProductsFromCart";import successDeleteProductsFromCart from"../action-creators/successDeleteProductsFromCart";import errorDeleteProductsFromCart from"../action-creators/errorDeleteProductsFromCart";import{messagesHaveErrors,createErrorMessageList}from"../helpers";/**
* Deletes products from the cart.
* @param {Array} cartItemIds The IDs of the items to remove from the cart.
* @return {Function} A redux thunk.
*/function deleteProductsFromCart(cartItemIds){return function(dispatch){dispatch(deleteProducts(cartItemIds));var request=new PipelineRequest(SHOPGATE_CART_DELETE_PRODUCTS).setInput({cartItemIds:cartItemIds}).setResponseProcessed(PROCESS_SEQUENTIAL).setErrorBlacklist(ECART).dispatch();request.then(function(result){/**
* @deprecated: The property "messages" is not supposed to be part of the pipeline response.
* Specification demands errors to be returned as response object with an "error" property.
* This code snippet needs to be removed after fixing the `@shopgate/legacy-cart` extension.
*/if(result.messages&&messagesHaveErrors(result.messages)){dispatch(errorDeleteProductsFromCart(cartItemIds,createErrorMessageList(SHOPGATE_CART_DELETE_PRODUCTS,result.messages)));}dispatch(successDeleteProductsFromCart());})["catch"](function(error){dispatch(errorDeleteProductsFromCart(cartItemIds,createPipelineErrorList(SHOPGATE_CART_DELETE_PRODUCTS,error)));});return request;};}/** @mixes {MutableFunction} */export default mutable(deleteProductsFromCart);