Skip to main content

Update Product Variant

Update Product Variant Mutation

This mutation updates a product variant using the StockActions.updateVariant operation, which provides comprehensive stock and pricing management capabilities.

Use Cases​

  • Pricing Updates: Adjust variant prices, compare-at prices, and costs
  • Inventory Management: Update stock quantities and tracking settings
  • SKU Management: Modify SKU codes for better organization
  • Cart Limits: Adjust minimum and maximum cart quantities
  • Package Details: Update weight and dimensions for shipping
  • Option Updates: Modify variant option selections
  • Availability Control: Enable/disable variant availability

Key Features​

Pricing Management​

  • Regular Price: Update the selling price of the variant
  • Compare-at Price: Set original/MSRP price for discount display
  • Cost Price: Update cost for profit margin calculations
  • Currency Support: Handle multiple currency codes

Inventory Control​

  • Stock Quantity: Update available inventory levels
  • Quantity Tracking: Enable/disable inventory tracking
  • Availability Status: Control variant availability
  • Reservation Management: Handle inventory reservations

Variant Configuration​

  • Title Updates: Modify variant display names
  • SKU Management: Update unique variant identifiers
  • Option Selection: Modify which options this variant represents
  • External ID: Update integration system identifiers

Cart and Shipping​

  • Cart Limits: Set purchase quantity restrictions
  • Package Details: Update weight and dimensions
  • Shipping Calculations: Ensure accurate shipping costs

Input Parameters​

  • $storeId: ID! - The unique identifier of the store
  • $variantId: ID! - The unique identifier of the variant to update
  • $input: UpdateStockItemInput! - Updated variant information including:
    • title: Updated variant display name
    • sku: Updated unique variant identifier
    • price: Updated selling price with currency
    • compareAtPrice: Updated original/MSRP price
    • cost: Updated cost price for profit calculations
    • quantity: Updated stock quantity
    • trackQuantity: Whether to track inventory for this variant
    • selectedOptions: Array of option-value pairs this variant represents
    • externalId: External system identifier
    • cartLimitsEnabled: Whether cart limits are active
    • minPerCart/maxPerCart: Minimum and maximum cart quantities
    • packageDetails: Weight and dimensions for shipping

Response Structure​

The mutation returns a StockUpdateActionResponse containing:

  • data: Updated stock item with complete variant information
  • errors: Array of any errors that occurred during the update
  • Comprehensive stock and pricing information
  • Package details and cart limits

Variant Fields Detail​

Basic Information​

  • id - Unique variant identifier (unchanged)
  • title - Display name for the variant
  • sku - Unique variant SKU code
  • externalId - External system identifier
  • createdAt/updatedAt - Timestamps

Pricing Information​

  • price - Current selling price with currency
  • compareAtPrice - Original/MSRP price for discount display
  • cost - Cost price for profit calculations

Inventory Management​

  • quantity - Available stock quantity
  • trackQuantity - Whether inventory tracking is enabled
  • isAvailable - Current availability status
  • reservations - Active inventory reservations

Configuration​

  • selectedOptions - Option-value pairs this variant represents
  • cartLimitsEnabled - Whether purchase limits are active
  • minPerCart/maxPerCart - Purchase quantity limits
  • packageDetails - Shipping weight and dimensions

Example Response​

{
"data": {
"updateProductVariant": {
"variant": {
"id": "Variant_black_standard_001",
"title": "Black / Standard Edition",
"sku": "PWH-PRO-BLK-STD-V2",
"price": {
"amount": 329.99,
"currencyCode": "USD"
},
"compareAtPrice": {
"amount": 399.99,
"currencyCode": "USD"
},
"cost": {
"amount": 165.00,
"currencyCode": "USD"
},
"quantity": 100,
"trackQuantity": true,
"isAvailable": true,
"selectedOptions": [
{
"option": {
"id": "Option_color_001",
"name": "Color"
},
"value": {
"id": "OptionValue_black_001",
"name": "Black"
}
}
],
"externalId": "EXT_PWH_BLK_STD_001",
"cartLimitsEnabled": true,
"minPerCart": 1,
"maxPerCart": 5,
"packageDetails": {
"weight": 0.85,
"dimensions": {
"length": 21.5,
"width": 19.5,
"height": 9.5
}
},
"updatedAt": "2024-01-15T14:30:00Z"
},
"product": {
"id": "Product_premium_headphones_001",
"title": "Premium Wireless Headphones Pro",
"variants": {
"nodes": [
{
"id": "Variant_black_standard_001",
"title": "Black / Standard Edition",
"sku": "PWH-PRO-BLK-STD-V2",
"price": {
"amount": 329.99,
"currencyCode": "USD"
},
"quantity": 100,
"isAvailable": true
}
]
}
}
}
}
}

Implementation Notes​

Validation Requirements​

  • Product and variant IDs must exist and be accessible
  • SKU must be unique within the store
  • Selected options must match existing product options
  • Price and cost values must be valid numbers
  • Package dimensions must be positive values

Best Practices​

  • Update inventory quantities carefully to avoid overselling
  • Maintain SKU consistency across systems
  • Set appropriate cart limits based on inventory levels
  • Update package details when product specifications change
  • Consider impact on existing orders and reservations

Error Handling​

  • Handle variant not found errors
  • Validate SKU uniqueness conflicts
  • Check option-value consistency with product options
  • Ensure proper permissions for variant updates
  • Handle inventory conflicts with existing reservations

Inventory Considerations​

  • Stock Updates: Consider existing reservations when updating quantities
  • Availability: Variants become unavailable when quantity reaches zero (if tracking)
  • Reservations: Active reservations may prevent certain quantity updates
  • Backorders: Consider backorder policies when setting quantities

Alternative Implementation​

Since this mutation may not be directly available, variant updates might happen through:

  1. Product Update: Update variants through the main product update mutation
  2. Inventory Actions: Separate mutations for inventory-specific updates
  3. Batch Operations: Bulk variant update operations
  4. Stock Actions: Dedicated stock management mutations (like updateProductVariantsPackageDetails)
  • updateProduct - Update the parent product and all variants
  • createProduct - Create products with initial variants
  • updateProductVariantsPackageDetails - Update package details specifically
  • adjustInventory - Adjust inventory quantities
  • reserveInventory - Create inventory reservations

GraphQL Endpoint​

https://graphql.wuilt.com

Operation: UpdateProductVariant​

Try It Out​

Query​

mutation UpdateProductVariant(
$storeId: ID!
$variantId: ID!
$input: UpdateStockItemInput!
) {
adminActions(storeId: $storeId) {
stock {
updateVariant(id: $variantId, input: $input) {
data {
id
sku
trackQuantity
quantity
regularPrice {
amount
currencyCode
__typename
}
salePrice {
amount
currencyCode
__typename
}
cost {
amount
currencyCode
__typename
}
cartLimitsEnabled
minPerCart
maxPerCart
packageDetails {
weight
dimensions {
length
width
height
__typename
}
__typename
}
__typename
}
errors {
message
code
__typename
}
__typename
}
__typename
}
__typename
}
}

Query Variables

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

Note: Make sure to change the storeId with your store ID. For guidance on how to get your store ID, reference the Store ID guide.

Authentication​

To use this query, you will need an API key. Click the "API Key" button in the navigation bar to enter your credentials.