When fetching the checkout (v1), for each checkout.lineItems (where a variant doesn't have an image) I thought to then use client.product.fetch(item.id).then(function(product) to grab the item and get the image (and other things like vendor) from that image.
HOWEVER, the id that's returned for each of the lineItems isn't the id of the product but rather than line id. How would I retrieve the original product to get things like images, vendor etc?
client.checkout.fetch(checkoutID).then(function(checkout) {
buildCart(checkout);
});
function buildCart(checkout) {
$.each(checkout.lineItems, function(index, item) {
// item.id isn't the id of the product therefore the below doesn't work
client.product.fetch(item.id).then(function(product) {
});
});
});
Related: #391
If we could get the product ID from the lineItem... which seems like we should be able to grab that anyway? That would solve a few things.
I think this is poor data design on our part. The variant should contain enough information to render. I'm going to see if there's a way to fix this in the API
Thanks @minasmart – that would be insanely good.
@minasmart Are there any updates on this topic?
@minasmart Seconded, a up date on this would be very useful. Updated to V1 yesterday and am unable to go live until I can get image in anyway from the lineItem.
@richgcook find any solution or update to this? I have the same issue.
@minasmart in addition to getting an image, I'm simply trying to link back to the product from the cart, but all my products have variants so the id I have is the variant id and not the product id. Am I missing something, or is there no way to get the product ID from a cart item that is a variant?
@andyschwob The best I could do until they fix this is have the client add variant images (even if they're not used on the product views... but at least for the cart).
I have to say the API isn't that useful... it's provided some nice functionality but really simple stuff from Shopify is missing.
This PR addresses the issue.
Most helpful comment
I think this is poor data design on our part. The variant should contain enough information to render. I'm going to see if there's a way to fix this in the API