Step 7. Apply a coupon
GraphQL checkout tutorial
Use applyCouponToCart to apply a discount coupon to the specified cart_id
.
{ CART_ID }
is the unique shopping cart ID from Step 2. Create empty cart.
{ COUPON_CODE }
is an existing Magento coupon code. It cannot be generated with GraphQL.
Request:
For logged-in customers, send the customer’s authorization token in the Authorization
parameter of the header. See Authorization tokens for more information.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
mutation {
applyCouponToCart(
input: {
cart_id: "{ CART_ID }"
coupon_code: "{ COUPON_CODE }"
}
) {
cart {
applied_coupons {
code
}
}
}
}
Response:
1
2
3
4
5
6
7
8
9
10
11
{
"data": {
"applyCouponToCart": {
"cart": {
"applied_coupons": {
"code": "{ COUPON_CODE }"
}
}
}
}
}
Use removeCouponFromCart to remove a discount coupon from the shopping cart.
Request:
For logged-in customers, send the customer’s authorization token in the Authorization
parameter of the header. See Authorization tokens for more information.
1
2
3
4
5
6
7
8
9
mutation {
removeCouponFromCart(input: { cart_id: "{ CART_ID }" }) {
cart {
applied_coupons {
code
}
}
}
}
Response:
1
2
3
4
5
6
7
8
9
10
11
{
"data": {
"removeCouponFromCart": {
"cart": {
"applied_coupons": {
"applied_coupon": null
}
}
}
}
}
Verify this step
-
Sign in as a customer to the website using the email
john.doe@example.com
and passwordb1b2b3l@w+
. -
Go to Checkout.
-
The discount is displayed in the Order Summary block.