Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
receiveCartContents during checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Jan 25, 2023
1 parent c2cb66b commit 125b4c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion assets/js/base/context/hooks/cart/use-store-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const defaultCartData: StoreCart = {
cartHasCalculatedShipping: false,
paymentRequirements: EMPTY_PAYMENT_REQUIREMENTS,
receiveCart: () => undefined,
receiveCartContents: () => undefined,
extensions: EMPTY_EXTENSIONS,
};

Expand Down Expand Up @@ -175,6 +176,7 @@ export const useStoreCart = (
typeof previewCart?.receiveCart === 'function'
? previewCart.receiveCart
: () => undefined,
receiveCartContents: () => undefined,
};
}

Expand All @@ -186,7 +188,7 @@ export const useStoreCart = (
! store.hasFinishedResolution( 'getCartData' );

const isLoadingRates = store.isCustomerDataUpdating();
const { receiveCart } = dispatch( storeKey );
const { receiveCart, receiveCartContents } = dispatch( storeKey );
const billingAddress = decodeValues( cartData.billingAddress );
const shippingAddress = cartData.needsShipping
? decodeValues( cartData.shippingAddress )
Expand Down Expand Up @@ -233,6 +235,7 @@ export const useStoreCart = (
cartHasCalculatedShipping: cartData.hasCalculatedShipping,
paymentRequirements: cartData.paymentRequirements,
receiveCart,
receiveCartContents,
};
},
[ shouldSelect ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ const CheckoutProcessor = () => {
select( CART_STORE_KEY ).getCustomerData()
);

const { cartNeedsPayment, cartNeedsShipping, receiveCart } = useStoreCart();
const { cartNeedsPayment, cartNeedsShipping, receiveCartContents } =
useStoreCart();

const {
activePaymentMethod,
Expand Down Expand Up @@ -275,7 +276,8 @@ const CheckoutProcessor = () => {
)
.then( ( response: CheckoutResponseError ) => {
if ( response.data?.cart ) {
receiveCart( response.data.cart );
// We don't want to receive the address here because it will overwrite fields.
receiveCartContents( response.data.cart );
}
processErrorResponse( response );
__internalProcessCheckoutResponse( response );
Expand Down Expand Up @@ -304,7 +306,7 @@ const CheckoutProcessor = () => {
shouldCreateAccount,
extensionData,
cartNeedsShipping,
receiveCart,
receiveCartContents,
__internalSetHasError,
__internalProcessCheckoutResponse,
] );
Expand Down

0 comments on commit 125b4c0

Please sign in to comment.