-
Notifications
You must be signed in to change notification settings - Fork 199
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
How to extract variant objects from cart? #1220
Comments
Okay, posting this question in ChatGPT gave me the following code which actually works! However I'd still like to know if this indeed is the correct way to do this (because you know, ChatGPT's answers need to be taken with a grain of salt) let task = client.mutateGraphWith(mutation) { [self] response, error in
if let response = response?.cartCreate, let cartResponse = response.cart {
let lines = cartResponse.lines.edges.map { $0.node }
for line in lines {
if let productVariant = line.merchandise as? Storefront.ProductVariant {
// Access product variant details
let variantId = productVariant.id
let title = productVariant.title
// Access other properties as needed
}
}
}
}
task.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I'm fetching a cart with the below query.
I'd like to grab the product variant details of line items.
However as you can see above, the line item node has a merchandise field and I don't know how to get variant data out of it.
It appears that the
Merchandise
object is actually a protocol so it has no properties.So how can I get the variant data from this?
The text was updated successfully, but these errors were encountered: