diff --git a/plugins/woocommerce-blocks/assets/js/data/cart/actions.ts b/plugins/woocommerce-blocks/assets/js/data/cart/actions.ts index d0fc4bdc84a..bedb8c68dd8 100644 --- a/plugins/woocommerce-blocks/assets/js/data/cart/actions.ts +++ b/plugins/woocommerce-blocks/assets/js/data/cart/actions.ts @@ -15,7 +15,6 @@ import { BillingAddress, ShippingAddress } from '@woocommerce/settings'; import { triggerAddedToCartEvent, triggerAddingToCartEvent, - camelCaseKeys, } from '@woocommerce/base-utils'; /** @@ -57,27 +56,6 @@ export const setErrorData = ( }; }; -/** - * Returns an action object used in updating the store with the provided cart. - * - * This omits the customer addresses so that only updates to cart items and totals are received. This is useful when - * currently editing address information to prevent it being overwritten from the server. - * - * This is a generic response action. - * - * @param {CartResponse} response - */ -export const receiveCartContents = ( - response: CartResponse -): { type: string; response: Partial< Cart > } => { - const cart = camelCaseKeys( response ) as unknown as Cart; - const { shippingAddress, billingAddress, ...cartWithoutAddress } = cart; - return { - type: types.SET_CART_DATA, - response: cartWithoutAddress, - }; -}; - /** * Returns an action object used to track when a coupon is applying. * @@ -503,7 +481,6 @@ type Actions = | typeof itemIsPendingDelete | typeof itemIsPendingQuantity | typeof receiveApplyingCoupon - | typeof receiveCartContents | typeof receiveCartItem | typeof receiveRemovingCoupon | typeof removeCoupon diff --git a/plugins/woocommerce-blocks/assets/js/data/cart/notify-errors.ts b/plugins/woocommerce-blocks/assets/js/data/cart/notify-errors.ts index cc775ace349..f4b9ec6d826 100644 --- a/plugins/woocommerce-blocks/assets/js/data/cart/notify-errors.ts +++ b/plugins/woocommerce-blocks/assets/js/data/cart/notify-errors.ts @@ -25,7 +25,6 @@ export const notifyCartErrors = ( createNotice( 'error', decodeEntities( error.message ), { id: error.code, context: 'wc/cart', - isDismissible: false, } ); } } ); diff --git a/plugins/woocommerce-blocks/assets/js/data/cart/push-changes.ts b/plugins/woocommerce-blocks/assets/js/data/cart/push-changes.ts index 67b51a5ed08..acd2b125ea0 100644 --- a/plugins/woocommerce-blocks/assets/js/data/cart/push-changes.ts +++ b/plugins/woocommerce-blocks/assets/js/data/cart/push-changes.ts @@ -1,7 +1,7 @@ /** * External dependencies */ -import { removeAllNotices, debounce, pick } from '@woocommerce/base-utils'; +import { debounce, pick } from '@woocommerce/base-utils'; import { CartBillingAddress, CartShippingAddress, @@ -157,7 +157,6 @@ const updateCustomerData = (): void => { localState.dirtyProps.billingAddress = []; localState.dirtyProps.shippingAddress = []; localState.doingPush = false; - removeAllNotices(); } ) .catch( ( response ) => { localState.doingPush = false; diff --git a/plugins/woocommerce-blocks/assets/js/data/cart/thunks.ts b/plugins/woocommerce-blocks/assets/js/data/cart/thunks.ts index 105206cd507..2beea043949 100644 --- a/plugins/woocommerce-blocks/assets/js/data/cart/thunks.ts +++ b/plugins/woocommerce-blocks/assets/js/data/cart/thunks.ts @@ -23,7 +23,7 @@ import { CartDispatchFromMap, CartSelectFromMap } from './index'; * @param {CartResponse} response */ export const receiveCart = - ( response: CartResponse ) => + ( response: Partial< CartResponse > ) => ( { dispatch, select, @@ -43,6 +43,22 @@ export const receiveCart = dispatch.setCartData( newCart ); }; +/** + * Updates the store with the provided cart but omits the customer addresses. + * + * This is useful when currently editing address information to prevent it being overwritten from the server. + * + * @param {CartResponse} response + */ +export const receiveCartContents = + ( response: Partial< CartResponse > ) => + ( { dispatch }: { dispatch: CartDispatchFromMap } ) => { + // eslint-disable-next-line @typescript-eslint/naming-convention + const { shipping_address, billing_address, ...cartWithoutAddress } = + response; + dispatch.receiveCart( cartWithoutAddress ); + }; + /** * A thunk used in updating the store with cart errors retrieved from a request. */ @@ -58,4 +74,7 @@ export const receiveError = } }; -export type Thunks = typeof receiveCart | typeof receiveError; +export type Thunks = + | typeof receiveCart + | typeof receiveCartContents + | typeof receiveError; diff --git a/plugins/woocommerce/changelog/fix-44906-coupon-removal-notices b/plugins/woocommerce/changelog/fix-44906-coupon-removal-notices new file mode 100644 index 00000000000..95343bbb156 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-44906-coupon-removal-notices @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Ensure coupon errors are visible on block checkout when invalid coupons are removed. diff --git a/plugins/woocommerce/includes/class-wc-coupon.php b/plugins/woocommerce/includes/class-wc-coupon.php index f1148391978..01e4ac8a489 100644 --- a/plugins/woocommerce/includes/class-wc-coupon.php +++ b/plugins/woocommerce/includes/class-wc-coupon.php @@ -13,7 +13,7 @@ use Automattic\WooCommerce\Utilities\StringUtil; defined( 'ABSPATH' ) || exit; -require_once dirname( __FILE__ ) . '/legacy/class-wc-legacy-coupon.php'; +require_once __DIR__ . '/legacy/class-wc-legacy-coupon.php'; /** * Coupon class. @@ -1066,7 +1066,7 @@ class WC_Coupon extends WC_Legacy_Coupon { $err = __( 'Sorry, this coupon is not applicable to your cart contents.', 'woocommerce' ); break; case self::E_WC_COUPON_USAGE_LIMIT_COUPON_STUCK: - if ( is_user_logged_in() && wc_get_page_id( 'myaccount' ) > 0 ) { + if ( is_user_logged_in() && wc_get_page_id( 'myaccount' ) > 0 && ! WC()->is_store_api_request() ) { /* translators: %s: myaccount page link. */ $err = sprintf( __( 'Coupon usage limit has been reached. If you were using this coupon just now but your order was not complete, you can retry or cancel the order by going to the my account page.', 'woocommerce' ), wc_get_endpoint_url( 'orders', '', wc_get_page_permalink( 'myaccount' ) ) ); } else {