Hi, I’m in need of some clarification on whether it’s possible to manage a product’s default variant price, barcode, and SKU using the ProductSet mutator.
I have successfully added a product without this information, but I’m struggling to add one with the mentioned fields without having to add a variant.
Working example (adds custom variant named “Default”):
$variables = [
'input' => [
'title' => $title,
'descriptionHtml' => $descriptionHtml,
'metafields' => [
[
"key" => "general_information",
"value" => "test 99",
"type" => "string",
"namespace" => "custom_fields"
],
[
"key" => "directions",
"value" => "test 99",
"type" => "string",
"namespace" => "custom_fields"
],
[
"key" => "ingredients",
"value" => "test 3",
"type" => "string",
"namespace" => "custom_fields"
],
[
"key" => "warnings",
"value" => "test 4",
"type" => "string",
"namespace" => "custom_fields"
]
],
'tags' => explode(',', $tags),
'vendor' => $vendor,
'productType' => $productType,
'status' => strtoupper($status),
// Minimal productOptions to satisfy Shopify's requirements
'productOptions' => [
[
'name' => 'Default', // Placeholder name for the product option
'position' => 1, // Option position
'values' => [
[
'name' => 'Default' // Placeholder value
]
]
]
],
'variants' => [
[
'price' => $price, // Assign the price
'sku' => $sku, // Assign the SKU
'barcode' => $barcode, // Assign the barcode
'inventoryPolicy' => $ignoreStockLevels === 'continue' ? 'CONTINUE' : 'DENY',
// Minimal optionValues to match productOptions
'optionValues' => [
[
'optionName' => 'Default', // Matches the productOptions name
'name' => 'Default' // Matches the productOptions value
]
]
]
]
],
'synchronous' => true
];
Example which does not work (Attempting to add field data without explicit / creation of a custom variant):
$variables = [
'input' => [
'title' => $title,
'descriptionHtml' => $descriptionHtml,
'metafields' => [
[
"key" => "general_information",
"value" => "test 99",
"type" => "string",
"namespace" => "custom_fields"
],
[
"key" => "directions",
"value" => "test 99",
"type" => "string",
"namespace" => "custom_fields"
],
[
"key" => "ingredients",
"value" => "test 3",
"type" => "string",
"namespace" => "custom_fields"
],
[
"key" => "warnings",
"value" => "test 4",
"type" => "string",
"namespace" => "custom_fields"
]
],
'tags' => explode(',', $tags),
'vendor' => $vendor,
'productType' => $productType,
'status' => strtoupper($status),
'variants' => [
[
'price' => $price, // Assign the price
'sku' => $sku, // Assign the SKU
'barcode' => $barcode, // Assign the barcode
'inventoryPolicy' => $ignoreStockLevels === 'continue' ? 'CONTINUE' : 'DENY'
]
]
],
'synchronous' => true
];
Throws Error: Variable $input of type ProductSetInput! was provided invalid value for variants.0.optionValues (Expected value to not be null)
I believe that either this development feature is still needed or it simply doesn’t exist, requiring us to use a different mutator. However, the documentation states that the mutators can both add and modify products. Therefore, it’s reasonable to assume that updating SKU, barcode, and price—which are essential fields for commerce—should be possible. Any ideas?
Thank-you!