Skip to content
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

[Bug] BuyNowButton always redirects to checkout when cart is not empty #825

Closed
tiwac100 opened this issue Apr 26, 2023 · 2 comments · Fixed by #827
Closed

[Bug] BuyNowButton always redirects to checkout when cart is not empty #825

tiwac100 opened this issue Apr 26, 2023 · 2 comments · Fixed by #827

Comments

@tiwac100
Copy link
Contributor

What is the location of your example repository?

No response

Which package or tool is having this issue?

hydrogen-react

What version of that package or tool are you using?

2023-04

What version of Remix are you using?

No response

Steps to Reproduce

  1. Add an AddToCartButton and BuyNowButton on a product page.
  2. Add the product to cart using the AddToCartButton

Expected Behavior

The user only gets redirected to checkout when the BuyNowButton is actually clicked.

Actual Behavior

The user gets redirect as soon as an item is in the cart and a BuyNowButton is present on the current page.

@tiwac100
Copy link
Contributor Author

tiwac100 commented Apr 26, 2023

The reason for this is BuyNowButton just checks if a checkoutUrl is present but never verifies it was actually clicked before redirecting:

useEffect(() => {
if (checkoutUrl) {
window.location.href = checkoutUrl;
}
}, [checkoutUrl]);

A simple solution would be to use if(loading && checkoutUrl).

tiwac100 added a commit to tiwac100/hydrogen that referenced this issue Apr 27, 2023
@CSpencerND
Copy link

Yes, Just instantly goes to checkout without having to click the button.

@benjaminsehl benjaminsehl changed the title BuyNowButton always redirects to checkout when cart is not empty [Bug] BuyNowButton always redirects to checkout when cart is not empty May 8, 2023
frehner added a commit that referenced this issue May 17, 2023
* Fix 2023 01 (#807)

* Revert "Support optional segments in `check routes` CLI command (#774)"

This reverts commit 2039a4a.

* update package.lock

* Fix demo store search action url (#802)

* Fixing #825

* Add loading dependency to redirect effect

* Revert "Fix 2023 01 (#807)"

This reverts commit 53e6dbf.

* Revert "Fix demo store search action url (#802)"

This reverts commit a783b42.

* add a changeset

---------

Co-authored-by: Daniel Rios <daniel.riospavia@shopify.com>
Co-authored-by: Ós <zeptok@gmail.com>
Co-authored-by: Anthony Frehner <frehner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants