This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
StoreAPI: Clear all wc notice types in the cart validation context #5983
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Size Change: 0 B Total Size: 863 kB ℹ️ View Unchanged
|
Aljullu
requested review from
a team and
tarunvijwani
and removed request for
a team
March 9, 2022 09:27
mikejolley
approved these changes
Mar 10, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before the
woocommerce_store_api_cart_errors
was introduced in this PR, the system would run thewoocommerce_check_cart_items
at the Checkout route while processing atget_route_post_response()
.This way, we could be sure to grab all legacy error notices coming from the wc_add_notice and stop the checkout process, if necessary; ditch all the others (notice types: success, notice).
After the cart validation refactor, the newly introduced
CartContoller::validate_cart()
is running thewoocommerce_check_cart_items
in order to group into thecart.errors
JS state, all errors coming from the wc_add_notice; this further enchances the 3PD experience as it could create a plug-n-play situation in existing logic.Where's the bug?
When the cart validator runs the
woocommerce_check_cart_items
and handles the session notices, it doesn't flush them unless there is at least oneerror
type in them.Therefore, when working with operations that change the JS cart state (e.g., modifying cart quantities), a new notice is added in the session every time.
The next page refresh will cause the PHP controller to deliver all stacked notices on the page. This screencast demonstrates this issue: https://d.pr/v/9WDttl
It's funny how it slipped during refactoring the validation system. I always had a
wc_add_notice('error', 'error')
in my code for testing, so the system would delete all notices, thus hiding this issue from me.Moreover, this issue couldn't be replicated in a similar situation at the payments API, where the code re-calls the
wc_clear_notices
to ensure that no other errors were added while inprocess_payment
.Steps to replicate:
functions.php
Solution:
I suggest following the current path to solving this: Drop them all and keep only the errors.
cc @mikejolley
Accessibility
prefers-reduced-motion
Testing
Automated Tests
Changelog
None