-
I am a bit lost with the new At first I tried the following approach:
This works somewhat, but the problem is that the mutation sent by My second approach was to create the cart and then try to query it with
In this attempt, What's the best practice for this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I have now followed this solution to set a fragment in the cart handler which queries the whole cart on cart mutation: https://shopify.dev/docs/custom-storefronts/hydrogen/cart/customize-cart-handler#customize-the-return-cart-fields I'm just not sure if that is the best way. Does this also query all fields when a single line in the cart is updated? I just want to do this on cart creation. |
Beta Was this translation helpful? Give feedback.
-
@magnattic I recommend not creating a cart until it is needed. For example |
Beta Was this translation helpful? Give feedback.
@magnattic I recommend not creating a cart until it is needed. For example
cart.createLines(...)
optimistically creates a cart if one doesn't already exist. If someone visits your site, and they never interact with the cart, there's no reason to create one. This change should make it easier to query the cart right after it is created though: #1865