CartRulesQuery
Description
Returns all cart rules configured in the system. Cart rules define conditions and actions that can be applied to shopping carts, such as discounts, free shipping, or other promotions.
Endpoint
query allCartRules {
allCartRules {
# Return fields
}
}
Arguments
This query does not accept any arguments.
Return Values
The query returns an array of CartRule objects with the following fields:
| Field | Type | Description |
|---|---|---|
| id | Int! | The unique identifier for the cart rule. |
| name | String! | The name of the cart rule. |
| description | String | A description of the cart rule, explaining its purpose or conditions. |
| discountAmount | Float | The amount of discount provided by the rule, if applicable. |
| isActive | Boolean! | Indicates whether the rule is currently active and can be applied to carts. |
| conditions | String | A string representation of the conditions that must be met for the rule to apply. |
Usage Example
query {
allCartRules {
id
name
description
discountAmount
isActive
conditions
}
}
Example Response
{
"data": {
"allCartRules": [
{
"id": 1,
"name": "Free Shipping Over $100",
"description": "Orders over $100 get free shipping",
"discountAmount": 0,
"isActive": true,
"conditions": "subtotal > 100"
},
{
"id": 2,
"name": "10% Off All Orders",
"description": "10% discount on all orders",
"discountAmount": 10,
"isActive": true,
"conditions": null
}
]
}
}
Notes
- This query returns all cart rules configured in the system, regardless of whether they are active or not.
- The
isActivefield can be used to determine if a rule is currently in effect. - The
conditionsfield provides a string representation of the conditions that must be met for the rule to apply. The format of this string depends on the implementation of the cart rule system. - Cart rules are typically configured by store administrators and are not meant to be modified through the GraphQL API.
- This query is useful for displaying available promotions to customers or for understanding what rules might be applied to a cart.