Focusing on managing products, variants, and collections through the API.
I try to run this query:
$query = <<<QUERY mutation productVariantsBulkCreate(\$productId: ID!, \$variants: [ProductVariantsBulkInput!]!) { productVariantsBulkCreate(productId: \$productId, variants: \$variants) { productVariants { id inventoryItem { id } } userErrors { field message } } } QUERY; $variables = [ "productId" => $productParentId, "strategy" => "REMOVE_STANDALONE_VARIANT", "variants" => [ "price" => $requestBodyData['price'], "barcode" => $productVariant->ean, "taxable" => true, "inventoryPolicy" => "DENY", "inventoryItem" => [ "sku" => $productVariant->ean, "tracked" => true, "cost" => $productVariant->unit_cost, "measurement" => [ "weight" => [ "unit" => "GRAMS", "value" => $productVariant->weight ] ] ], "inventoryQuantities" => [ [ "availableQuantity" => $requestBodyData['stock'], "locationId" => "gid://shopify/Location/" . ShopifyService::LOCATION ] ], "optionValues" => [ [ "name" => "Red", "optionName" => "Color", ], [ "name" => "Large", "optionName" => "Size", ] ] ] ];
It returns this error: "message":"Option does not exist"
Contacted support but they didn't know the problem.
Solved! Go to the solution
This is an accepted solution.
Hi @LaytonBerth,
I think the Color or Size option does not exist in your product with the id "$productParentId".
Hope you find out how to fix it soon! Have a great day bro!
B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.
B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.
B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.
BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now
This is an accepted solution.
Exactly... Apparently which is very weird in my opinion, I had to first define all the POSSIBLE options I will ever have on the product (createProduct mutation with options field) and then you can use those options you defined in the 'productVariantsBulkCreate' mutation.
What is also very weird is that the strategy REMOVE_STANDALONE_VARIANT is not working and still creates a variant for the first options you defined (for example, small / black).
This is an accepted solution.
Hi @LaytonBerth,
I think the Color or Size option does not exist in your product with the id "$productParentId".
Hope you find out how to fix it soon! Have a great day bro!
B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.
B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.
B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.
BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now
This is an accepted solution.
Exactly... Apparently which is very weird in my opinion, I had to first define all the POSSIBLE options I will ever have on the product (createProduct mutation with options field) and then you can use those options you defined in the 'productVariantsBulkCreate' mutation.
What is also very weird is that the strategy REMOVE_STANDALONE_VARIANT is not working and still creates a variant for the first options you defined (for example, small / black).