How to update product price with graphql on shopify if there is no product variant
Solution:
A product has many variants. Between one, and one hundred. End of story. If you have a product ID, you can get the variant IDs. End of story. If you have a variant ID, you can get the variant details. With those, you will find that a variant has an inventory_item_id. Or inventoryItemId. You get the picture? With that, you can get the item! The item has a price. You can use a mutation to set the price. That is how it is done.
If you say you have a product without a variant, that is false. Impossible.
Answer
Solution:
Sounds like you're confusing the number of options with variants.
The Product object (https://shopify.dev/docs/api/admin-graphql/2023-01/objects/Product#field-product-hasonlydefaultvariant) also has atotalVariants
count andhasOnlyDefaultVariant
fields
Answer
Solution:
Ok, The confusing part was, when you have a product the uri has a product id, if you create a variant, there is a variant id in the uri as well. But i didn't realize that the existance of a default variant id as i never came across of this in the gui, so i never tried to run a variant query on a product without multiple variants.
So running:
{
product(id: "gid://shopify/Product/123456798"){
variants(first:5 ){
nodes {
id
price
}
}
}
}
Does return the dafault variant id which i can then use for updating.
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.