G'day,
I need to update a product ( tags, productType, ... ) and all its variants with the same ( price, compareToPrice ).
Obviously, I can update the product and then loop through the (max 6) variants. This works ok, but ...
Is it possible to do this in one? If so, where/how do I specify the 'ProductVariantInput' and 'IDs' in the example below.
mutation {
productUpdate(input: {id: "gid://shopify/Product/193......83", tags: ["Jacket, warm"], productType: "on-sale"}) {
product {
id
tags
productType
variants(first: 6) {
edges {
node {
id
price
compareAtPrice
}
}
}
}
}
}
Solved! Go to the solution
This is an accepted solution.
I have figured it out now. This is a solution, just in case someone else wants to know.
The string for the mutation is generated within the Java program.
The number of blocks var0: ... var1: ... is determined by the number of variants of the product.
mutation {
prod: productUpdate(input: {id: "gid://shopify/Product/193......99", tags: ["Knitwear, New Arrivals, Sale, Shorts"], productType: "Sale-Item"})
{
product {
tags
productType
}
}
var0: productVariantUpdate(input: {id: "gid://shopify/ProductVariant/176.....219", price: 69.00, compareAtPrice: 89.95})
{
productVariant {
price
compareAtPrice
}
}
var1: productVariantUpdate(input: {id: "gid://shopify/ProductVariant/1762....987", price: 69.00, compareAtPrice: 89.95})
{
productVariant {
price
compareAtPrice
}
}
}
Hi Peter, this was very helpful.
Do you know if there is a way to dynamically do something similar...
Perhaps the number of variants you will have to update changes from mutation to mutation.
I'm having two issues:
1. Not sure you can have a gql query that is created on demand.
2. Not sure how to pass in an array of inputs.
Thanks!
User | Count |
---|---|
26 | |
20 | |
11 | |
10 | |
10 |