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 namesku: Updated unique variant identifierprice: Updated selling price with currencycompareAtPrice: Updated original/MSRP pricecost: Updated cost price for profit calculationsquantity: Updated stock quantitytrackQuantity: Whether to track inventory for this variantselectedOptions: Array of option-value pairs this variant representsexternalId: External system identifiercartLimitsEnabled: Whether cart limits are activeminPerCart/maxPerCart: Minimum and maximum cart quantitiespackageDetails: Weight and dimensions for shipping
Response Structure​
The mutation returns a StockUpdateActionResponse containing:
data: Updated stock item with complete variant informationerrors: 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 variantsku- Unique variant SKU codeexternalId- External system identifiercreatedAt/updatedAt- Timestamps
Pricing Information​
price- Current selling price with currencycompareAtPrice- Original/MSRP price for discount displaycost- Cost price for profit calculations
Inventory Management​
quantity- Available stock quantitytrackQuantity- Whether inventory tracking is enabledisAvailable- Current availability statusreservations- Active inventory reservations
Configuration​
selectedOptions- Option-value pairs this variant representscartLimitsEnabled- Whether purchase limits are activeminPerCart/maxPerCart- Purchase quantity limitspackageDetails- 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:
- Product Update: Update variants through the main product update mutation
- Inventory Actions: Separate mutations for inventory-specific updates
- Batch Operations: Bulk variant update operations
- Stock Actions: Dedicated stock management mutations (like
updateProductVariantsPackageDetails)
Related Operations​
updateProduct- Update the parent product and all variantscreateProduct- Create products with initial variantsupdateProductVariantsPackageDetails- Update package details specificallyadjustInventory- Adjust inventory quantitiesreserveInventory- Create inventory reservations
GraphQL Endpoint​
https://graphql.wuilt.com
Operation: UpdateProductVariant​
Try It Out​
Query​
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.