-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow calling the cart
.get()
method right after cart mutation meth…
…ods (#1865)
- Loading branch information
Showing
3 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
'@shopify/hydrogen': patch | ||
--- | ||
|
||
Allow calling the cart `.get()` method right after creating a new cart with | ||
one of the mutation methods: `create()`, `addLines()`, `updateDiscountCodes()`, `updateBuyerIdentity()`, `updateNote()`, `updateAttributes()`, `setMetafields()`. | ||
|
||
```ts | ||
import { | ||
createCartHandler, | ||
cartGetIdDefault, | ||
cartSetIdDefault, | ||
} from '@shopify/hydrogen'; | ||
|
||
const cartHandler = createCartHandler({ | ||
storefront, | ||
getCartId: cartGetIdDefault(request.headers), | ||
setCartId: cartSetIdDefault(), | ||
cartQueryFragment: CART_QUERY_FRAGMENT, | ||
cartMutateFragment: CART_MUTATE_FRAGMENT, | ||
}); | ||
|
||
await cartHandler.addLines([{merchandiseId: '...'}]); | ||
// This change fixes a bug where `cart` would be null, even though a | ||
// new cart was created when adding a line item | ||
const cart = await cartHandler.get(); | ||
``` |
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
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