Skip to content

How to set only variant or options for product variant through API #943

Closed Answered by duncanmcclean
rolinbos asked this question in Help
Discussion options

You must be logged in to vote

Hey 👋

You can update both the options & variables like this, using the productVariants method:

$product->productVariants([
  'variants' => [
    ['name' => 'Colour', 'values' => ['Red', 'Green', 'Blue']],
    ['name' => 'Size', 'values' => ['Small', 'Medium']]
  ],
  'options' => [
    [
      'key' => 'Red_Small',
      'variant' => 'Red, Small',
      'price' => 1599,
    ],
    [
      'key' => 'Red_Medium',
      'variant' => 'Red, Medium',
      'price' => 2950,
    ],
    // Green_Small
    // Green_Medium
    // Blue_Small
    // Blue_Medium
  ],
]);

If you want to update only the variants or options while keeping the existing values, you still need to include both in your update. …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rolinbos
Comment options

Answer selected by rolinbos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants