Skip to main content

calculateVariantPrice

Requires permission products:pricing:read.

Returns the unit price of a variant for a quantity, taken from the best matching quantity tier in the base currency, or from the variant's base price when no tier matches. The result also carries the original price and the discount against it. Needs the pricing read permission.

Errors: a failed call returns a GraphQL errors entry, not a field on the result, and data may be null or partial. Read the entry's extensions.code and message; every shape and code is in the Error reference.

Example:

query CalculateVariantPrice($quantity: Int!, $variantId: ID!) {
calculateVariantPrice(quantity: $quantity, variantId: $variantId) {
tierName
discount
isValid
originalPrice
price
}
}

Variables:

{
"quantity": 0,
"variantId": "id"
}

Response:

{
"data": {
"calculateVariantPrice": {
"tierName": "string",
"discount": 0,
"isValid": true,
"originalPrice": 0,
"price": 0
}
}
}
calculateVariantPrice(
customerTier: String
quantity: Int!
variantId: ID!
): CalculatedPrice!

Arguments​

calculateVariantPrice.customerTier ● String scalar​

The customer tier to price for. When given, only tiers that list this customer tier apply.

calculateVariantPrice.quantity ● Int! non-null scalar​

The quantity to price. Tiers apply by their minimum and maximum quantity.

calculateVariantPrice.variantId ● ID! non-null scalar​

The ID of the variant.

Type​

CalculatedPrice object​

The price worked out for a quantity, after any tier applies.