Open Isuru-Nanayakkara opened 9 months ago
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()
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?