New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the WooPay Direct Checkout flow to the blocks mini cart widget #8795
Conversation
Test the buildOption 1. Jetpack Beta
Option 2. Jurassic Ninja - available for logged-in A12s🚀 Launch a JN site with this branch 🚀 ℹ️ Install this Tampermonkey script to get more options. Build info:
Note: the build is updated when a new commit is pushed to this PR. |
Size Change: +317 B (0%) Total Size: 1.25 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code changes look good and have test well.
There were just a few, minor details I wanted to confirm before merging.
Testing Instructions
- ✅ Test 1: Ensure the direct checkout scripts are enqueued in the right pages.
- ✅ Test 2: Ensure the direct checkout flow works in the mini cart.
- ✅ Test 3: Ensure the direct checkout flow works from classic and blocks checkout.
- ✅
npm run test:js
.
! WooPayDirectCheckout.isWooPayDirectCheckoutEnabled() || | ||
shouldSkipWooPay() | ||
) { | ||
if ( shouldSkipWooPay() ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related to this PR but am I correct in my thinking that we may want to add similar logic (early exit when shouldSkipWooPay()
) to the following functions, below:
addItemCallback()
.debounceSetItemQtyCallback()
.removeItemCallback()
.
Otherwise, we will be prefetching encrypted session data that will not be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
Instead of checking for shouldSkipWooPay
, I added the hooks in the load
window event listener and after isWooPayThirdPartyCookiesEnabled()
in 5ce2d84. LMK what you think.
@lovo-h – I tested this by adding a console.log
to each callback and going to the blocks cart and adding, removing and setting the quantity of an item, however I wasn't able to hit the action hook when adding a new item from the suggestions list after the cart is emptied, am I testing this wrong? What's one way to hit the experimental__woocommerce_blocks-cart-add-item
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of checking for
shouldSkipWooPay
, I added the hooks in theload
window event listener and afterisWooPayThirdPartyCookiesEnabled()
in 5ce2d84. LMK what you think.
I think this approach looks cleaner. Good call.
I wasn't able to hit the action hook when adding a new item from the suggestions list after the cart is emptied, am I testing this wrong? What's one way to hit the
experimental__woocommerce_blocks-cart-add-item
?
Good catch.
I also wasn't able to trigger this callback either. It appears like it was removed in WooCommerce:
If I recall correctly, this hook was added when wcBlocks was an independent plugin from WooCommerce. In wcBlocks, it looks like the experimental__woocommerce_blocks-cart-add-item
hook still exists.
One solution would be to replace the experimental__woocommerce_blocks-cart-add-item
hook with wc-blocks_added_to_cart
:
document.body.addEventListener(
'wc-blocks_added_to_cart',
addItemCallback
);
However, this is an unrelated issue to this PR. So, we can create a separate GH issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created an issue. Feel free to look into this if you have the availability.
…after "WooPayDirectCheckout.init()"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes look good and test well 👍
Testing Instructions
- ✅ Test 1: Ensure the direct checkout scripts are enqueued in the right pages.
- ✅ Test 2: Ensure the direct checkout flow works in the mini cart.
- ✅ Test 3: Ensure the direct checkout flow works from classic and blocks checkout.
- ✅
npm run test:js
.
Fixes 2647-gh-Automattic/woopay
Changes proposed in this Pull Request
woocommerce_blocks_cart_enqueue_data
action, which is used by the blocks mini cart and cart as widgets (src).Note: In this PR we are not adding support for the legacy mini cart
woocommerce_mini_cart()
yet.Testing instructions
Setup
_wcpay_feature_woopay_direct_checkout
is set to1
.npm run build:client
.Test 1: Ensure the direct checkout scripts are enqueued in the right pages
WCPAY_WOOPAY_DIRECT_CHECKOUT
script is enqueued in the page source.WCPAY_WOOPAY_DIRECT_CHECKOUT
script is NOT enqueued in the page source.Test 2: Ensure the direct checkout flow works in the mini cart
Test 3: Ensure the direct checkout flow works from classic and blocks checkout
npm run changelog
to add a changelog file, choosepatch
to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.Post merge