Skip to content

Commit

Permalink
Merge pull request #2184 from graphcommerce-org/fix/cart-recreation-p…
Browse files Browse the repository at this point in the history
…revention

When a customer would return from a payment gateway and it would erroneously query the cart GraphCommerce would immediately create a new empty cart while it shouldn't.
  • Loading branch information
paales authored Jan 30, 2024
2 parents 956f332 + 28b7e6e commit cd37296
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/brown-apricots-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphcommerce/magento-cart": patch
---

When a customer would return from a payment gateway and it would erroneously query the cart GraphCommerce would immediately create a new empty cart while it shouldn't.
2 changes: 1 addition & 1 deletion examples/magento-graphcms/pages/checkout/payment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function PaymentPage() {
}
>
{billingPage.error && <ApolloCartErrorFullPage error={billingPage.error} />}
{!cartExists && <EmptyCart />}
{!billingPage.error && !cartExists && <EmptyCart />}
{cartExists && !billingPage.error && (
<>
<LayoutHeader
Expand Down
5 changes: 5 additions & 0 deletions packages/magento-cart/link/createCartErrorLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export const cartErrorLink = onError(({ graphQLErrors, operation, forward }) =>

if (!cartErr) return undefined

if (globalThis.location?.search) {
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.get('cart_id')) return forward(operation)
}

return fromPromise(client?.mutate({ mutation: CreateEmptyCartDocument }))
.filter((value) => Boolean(value))
.flatMap((cartData) => {
Expand Down

0 comments on commit cd37296

Please sign in to comment.