Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 8bc7066

Browse files
authored
Merge pull request #7662 from magento/kh_rewards-mutations
GraphQL: Add mutations for applying/removing reward points
2 parents 4b5f371 + e41547c commit 8bc7066

File tree

3 files changed

+244
-2
lines changed

3 files changed

+244
-2
lines changed

src/_data/toc/graphql.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,17 @@ pages:
147147
- label: addVirtualProductsToCart mutation
148148
url: /graphql/mutations/add-virtual-products.html
149149

150+
- label: applyCouponToCart mutation
151+
url: /graphql/mutations/apply-coupon.html
152+
150153
- label: applyGiftCardToCart mutation
151154
url: /graphql/mutations/apply-giftcard.html
152155
edition: ee-only
153156

154-
- label: applyCouponToCart mutation
155-
url: /graphql/mutations/apply-coupon.html
157+
- label: applyRewardPointsToCart mutation
158+
url: /graphql/mutations/apply-reward-points.html
159+
edition: ee-only
160+
exclude_versions: ["2.3"]
156161

157162
- label: applyStoreCreditToCart mutation
158163
url: /graphql/mutations/apply-store-credit.html
@@ -211,6 +216,11 @@ pages:
211216
- label: removeItemFromCart mutation
212217
url: /graphql/mutations/remove-item.html
213218

219+
- label: removeRewardPointsFromCart mutation
220+
url: /graphql/mutations/remove-reward-points.html
221+
edition: ee-only
222+
exclude_versions: ["2.3"]
223+
214224
- label: removeStoreCreditFromCart mutation
215225
url: /graphql/mutations/remove-store-credit.html
216226
edition: ee-only
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
group: graphql
3+
title: applyRewardPointsToCart mutation
4+
ee_only: True
5+
---
6+
7+
The `applyRewardPointsToCart` mutation applies reward points to the customer's cart. You cannot specify a quantity of reward points. If the reward points balance is less than the cart total, Magento applies the entire reward points balance. Otherwise, Magento applies as many reward points needed to bring the total to 0. Fractional reward points are discarded.
8+
9+
Use the [`removeRewardPointsFromCart` mutation]({{page.baseurl}}/graphql/mutations/remove-reward-points.html) to undo the results of the `applyRewardPointsToCart` mutation.
10+
11+
## Syntax
12+
13+
`mutation: applyRewardPointsToCart(cartId: ID!): ApplyRewardPointsToCartOutput`
14+
15+
## Example usage
16+
17+
The following example applies $5 to the cart. In this example, the exchange rate is defined as 25 reward points equals $5.
18+
19+
**Request:**
20+
21+
```graphql
22+
mutation {
23+
applyRewardPointsToCart(cartId: "8k0Q4MpH2IGahWrTRtqM61YV2MtLPApz")
24+
{
25+
cart {
26+
items {
27+
quantity
28+
product {
29+
sku
30+
name
31+
price_range {
32+
maximum_price {
33+
final_price {
34+
currency
35+
value
36+
}
37+
}
38+
}
39+
}
40+
}
41+
applied_reward_points {
42+
money {
43+
currency
44+
value
45+
}
46+
points
47+
}
48+
prices {
49+
grand_total {
50+
currency
51+
value
52+
}
53+
applied_taxes {
54+
amount {
55+
currency
56+
value
57+
}
58+
}
59+
}
60+
}
61+
}
62+
}
63+
```
64+
65+
**Response:**
66+
67+
```json
68+
{
69+
"data": {
70+
"applyRewardPointsToCart": {
71+
"cart": {
72+
"items": [
73+
{
74+
"quantity": 1,
75+
"product": {
76+
"sku": "WJ04",
77+
"name": "Ingrid Running Jacket",
78+
"price_range": {
79+
"maximum_price": {
80+
"final_price": {
81+
"currency": "USD",
82+
"value": 84
83+
}
84+
}
85+
}
86+
}
87+
}
88+
],
89+
"applied_reward_points": {
90+
"money": {
91+
"currency": "USD",
92+
"value": 5
93+
},
94+
"points": 25
95+
},
96+
"prices": {
97+
"grand_total": {
98+
"currency": "USD",
99+
"value": 90.93
100+
},
101+
"applied_taxes": [
102+
{
103+
"amount": {
104+
"currency": "USD",
105+
"value": 6.93
106+
}
107+
}
108+
]
109+
}
110+
}
111+
}
112+
}
113+
}
114+
```
115+
116+
## Input attributes
117+
118+
The `applyRewardPointsToCart` mutation requires the `cart_id` attribute.
119+
120+
Attribute | Data Type | Description
121+
--- | --- | ---
122+
`cart_id` | String! | The unique ID that identifies the customer's cart
123+
124+
## Output attributes
125+
126+
The `ApplyRewardPointsToCartOutput` object contains the `Cart` object.
127+
128+
Attribute | Data Type | Description
129+
--- | --- | ---
130+
`cart` |[Cart!](#CartObject) | Describes the contents of the specified shopping cart
131+
132+
### Cart object {#CartObject}
133+
134+
{% include graphql/cart-object-24.md %}
135+
136+
[Cart query output]({{page.baseurl}}/graphql/queries/cart.html#cart-output) provides more information about the `Cart` object.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
group: graphql
3+
title: removeRewardPointsFromCart mutation
4+
ee_only: True
5+
---
6+
7+
The `removeRewardPointsFromCart` mutation removes all reward points that were previously applied to the customer's cart with the [`applyRewardPointsToCart` mutation]({{page.baseurl}}/graphql/mutations/apply-reward-points.html).
8+
9+
## Syntax
10+
11+
`mutation: removeRewardPointsFromCart(cartId: ID!): RemoveRewardPointsFromCartOutput`
12+
13+
## Example usage
14+
15+
The following example removes all reward points from the customer's cart. The `applied_rewards_points` object is now null.
16+
17+
**Request:**
18+
19+
```graphql
20+
mutation {
21+
removeRewardPointsFromCart(cartId: "8k0Q4MpH2IGahWrTRtqM61YV2MtLPApz")
22+
{
23+
cart {
24+
applied_reward_points {
25+
money {
26+
currency
27+
value
28+
}
29+
points
30+
}
31+
prices {
32+
applied_taxes {
33+
amount {
34+
currency
35+
value
36+
}
37+
}
38+
grand_total {
39+
currency
40+
value
41+
}
42+
}
43+
}
44+
}
45+
}
46+
```
47+
48+
**Response:**
49+
50+
```json
51+
{
52+
"data": {
53+
"removeRewardPointsFromCart": {
54+
"cart": {
55+
"applied_reward_points": null,
56+
"prices": {
57+
"applied_taxes": [
58+
{
59+
"amount": {
60+
"currency": "USD",
61+
"value": 6.93
62+
}
63+
}
64+
],
65+
"grand_total": {
66+
"currency": "USD",
67+
"value": 90.93
68+
}
69+
}
70+
}
71+
}
72+
}
73+
}
74+
```
75+
76+
## Input attributes
77+
78+
The `removeRewardPointsFromCart` mutation requires the `cart_id` attribute.
79+
80+
Attribute | Data Type | Description
81+
--- | --- | ---
82+
`cart_id` | String! | The unique ID that identifies the customer's cart
83+
84+
## Output attributes
85+
86+
The `RemoveRewardPointsFromCartOutput` object contains the `Cart` object.
87+
88+
Attribute | Data Type | Description
89+
--- | --- | ---
90+
`cart` |[Cart!](#CartObject) | Describes the contents of the specified shopping cart
91+
92+
### Cart object {#CartObject}
93+
94+
{% include graphql/cart-object-24.md %}
95+
96+
[Cart query output]({{page.baseurl}}/graphql/queries/cart.html#cart-output) provides more information about the `Cart` object.

0 commit comments

Comments
 (0)