Skip to content

Commit

Permalink
When a user reorders their cart without interacting with their cart p…
Browse files Browse the repository at this point in the history
…reviously a new cart wouldn't be created.
  • Loading branch information
paales committed Jan 10, 2025
1 parent a2f565f commit 5ca6fb9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-guests-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphcommerce/magento-customer': patch
---

When a user reorders their cart without interacting with their cart previously a new cart wouldn't be created.
4 changes: 3 additions & 1 deletion packages/magento-cart/hooks/useClearCurrentCartId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export function useClearCurrentCartId() {
const { cache } = useApolloClient()

return () => {
cache.evict({ fieldName: 'currentCartId', broadcast: true })
cache.evict({ fieldName: 'currentCartId' })
cache.evict({ fieldName: 'customerCart' })
cache.gc()
cookie(CART_ID_COOKIE, null)
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { useFormGqlMutationCart } from '@graphcommerce/magento-cart'
import { AddProductsToCartSnackbarMessage } from '@graphcommerce/magento-product/components/AddProductsToCart/AddProductsToCartSnackbarMessage'
import { iconChevronRight, IconSvg, LinkOrButton, nonNullable } from '@graphcommerce/next-ui'
import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
import { Trans } from '@lingui/macro'
import { Box } from '@mui/material'
import type { OrderItemsFragment } from '../OrderItems/OrderItems.gql'
import type { ReorderItemsMutation, ReorderItemsMutationVariables } from './ReorderItems.gql'
import { ReorderItemsDocument } from './ReorderItems.gql'

export type ReorderItemsProps = { order: OrderItemsFragment }

export function ReorderItems(props: ReorderItemsProps) {
const { order } = props

const form = useFormGqlMutation(ReorderItemsDocument, {
const form = useFormGqlMutationCart<
ReorderItemsMutation,
ReorderItemsMutationVariables & { cartId: string }
>(ReorderItemsDocument, {
defaultValues: { orderNumber: order.number },
})
const { formState, handleSubmit, error, data: cartData } = form
Expand Down

0 comments on commit 5ca6fb9

Please sign in to comment.