data-src=../../../../includes/paas-only.md
addVirtualProductsToCart mutation
data-variant=warning
data-slots=text
A virtual product represents a saleable item that is not physical, such as a membership, service, warranty, or subscription. Virtual products do not need to be shipped or downloaded, nor do they require stock management.
The addVirtualProductsToCart mutation allows you to add multiple virtual products to the cart at the same time, but you cannot add other product types with this mutation. To add a virtual product to a cart, you must provide the cart ID, the SKU, and the quantity. You can also optionally provide customizable options.
Syntax
mutation: {addVirtualProductsToCart(input: AddVirtualProductsToCartInput): {AddVirtualProductsToCartOutput}}
Reference
The addVirtualProductsToCart reference provides detailed information about the types and fields defined in this mutation.
Example usage
The Luma sample data does not include any virtual products. The following example requires that you create a virtual product with the sku value of Membership-Gold with a price of $49.99.
Request:
mutation {
addVirtualProductsToCart(
input: {
cart_id: "IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG",
cart_items: [
{
data: {
quantity: 1
sku: "Membership-Gold"
}
}
]
}
) {
cart {
itemsV2 {
items {
product {
name
}
quantity
}
total_count
page_info {
page_size
current_page
total_pages
}
}
prices {
grand_total {
value
currency
}
}
}
}
}
Response:
{
"data": {
"addVirtualProductsToCart": {
"cart": {
"itemsV2": {
"items": [
{
"product": {
"name": "Gold Membership"
},
"quantity": 1
}
],
"total_count": 1,
"page_info": {
"page_size": 20,
"current_page": 1,
"total_pages": 1
}
},
"prices": {
"grand_total": {
"value": 49.99,
"currency": "USD"
}
}
}
}
}
}
Errors
Could not find a cart with ID "XXX"cart_id value does not exist in the quote_id_mask table.Could not find a product with SKU "YYY"data.sku argument does not exist.Required parameter "cart_id" is missingcart_id argument was omitted or contains an empty value.Required parameter "cart_items" is missingcart_items argument was omitted or contains an empty value.The current user cannot perform operations on cart XXXThe product's required option(s) weren't entered. Make sure the options are entered and try again.