You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
As of Magento 2.3.4, GraphQL provides the following features:
12
12
13
-
* Support for all product types, payment methods, and shipping methods
14
-
* Achieved <.5 sec average response times with 500 concurrent requests
15
-
* Redesigned a feature rich layered navigation
13
+
- Support for all product types, payment methods, and shipping methods
14
+
- Achieved <.5 sec average response times with 500 concurrent requests
15
+
- Redesigned a feature rich layered navigation
16
16
17
17
## Where we're going
18
18
19
19
The `graphql-ce` Community Engineering repository has been archived. Development for Magento 2.3.5 will be limited to bug fixes.
20
20
21
21
For the 2.4.0 and 2.4.1 releases, Magento teams are working toward completing GraphQL coverage for Business to Consumer (B2C) uses cases, with emphasis on the following:
22
22
23
-
* Reorders
24
-
* Inventory Management store pickups
25
-
* Order history for logged in customers
26
-
* Replace product-specific mutations that add products to a cart with a single mutation that can handle all product types
27
-
* Gift wrapping and messages
28
-
* Saved payment methods
23
+
- Reorders
24
+
- Inventory Management store pickups
25
+
- Order history for logged in customers
26
+
- Replace product-specific mutations that add products to a cart with a single mutation that can handle all product types
27
+
- Gift wrapping and messages
28
+
- Saved payment methods
29
29
30
30
We also expect to begin adding coverage for B2B scenarios.
Copy file name to clipboardExpand all lines: src/guides/v2.3/graphql/tutorials/checkout/checkout-add-product-to-cart.md
+22-9Lines changed: 22 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -31,9 +31,11 @@ If you add a product to the shopping cart as a registered customer, be sure to s
31
31
32
32
## Add a simple product into the shopping cart
33
33
34
-
`{ CART_ID }` is the unique shopping cart ID from [Step 2. Create empty cart]({{ page.baseurl }}/graphql/tutorials/checkout/checkout-add-product-to-cart.html).
34
+
The following mutation adds a simple product into the shopping cart.
35
35
36
-
The following mutation adds a **simple product** into shopping cart.
36
+
Replace `{ CART_ID }` with the unique shopping cart ID from [Step 2. Create empty cart]({{ page.baseurl }}/graphql/tutorials/checkout/checkout-add-product-to-cart.html).
37
+
38
+
In this example, we will add the Aim Analog Watch (SKU 24-MG04) from the default Luma catalog to the cart. The SKU identifies the product to be added.
37
39
38
40
**Request:**
39
41
@@ -46,7 +48,7 @@ mutation {
46
48
{
47
49
data: {
48
50
quantity: 1
49
-
sku: "simple-product"
51
+
sku: "24-MG04"
50
52
}
51
53
}
52
54
]
@@ -75,9 +77,9 @@ mutation {
75
77
"cart": {
76
78
"items": [
77
79
{
78
-
"id": "508",
80
+
"id": "5",
79
81
"product": {
80
-
"sku": "simple-product",
82
+
"sku": "24-MG04",
81
83
"stock_status": "IN_STOCK"
82
84
},
83
85
"quantity": 1
@@ -91,7 +93,8 @@ mutation {
91
93
92
94
## Add a virtual product into the shopping cart
93
95
94
-
The following mutation adds a **virtual product** into shopping cart.
96
+
The following mutation adds a virtual product into the shopping cart.
97
+
In this example, we add the Beginner's Yoga video downloadable product (SKU 240-LV04).
95
98
96
99
**Request:**
97
100
@@ -104,7 +107,7 @@ mutation {
104
107
{
105
108
data: {
106
109
quantity: 1
107
-
sku: "virtual-product"
110
+
sku: "240-LV04"
108
111
}
109
112
}
110
113
]
@@ -133,9 +136,17 @@ mutation {
133
136
"cart": {
134
137
"items": [
135
138
{
136
-
"id": "509",
139
+
"id": "5",
137
140
"product": {
138
-
"sku": "virtual-product",
141
+
"sku": "24-MG04",
142
+
"stock_status": "IN_STOCK"
143
+
},
144
+
"quantity": 1
145
+
},
146
+
{
147
+
"id": "6",
148
+
"product": {
149
+
"sku": "240-LV04",
139
150
"stock_status": "IN_STOCK"
140
151
},
141
152
"quantity": 1
@@ -147,6 +158,8 @@ mutation {
147
158
}
148
159
```
149
160
161
+
The response lists all items currently in the cart, including the just-added video download.
162
+
150
163
## Verify this step {#verify-step}
151
164
152
165
1. Sign in as a customer to the website using the email `[email protected]` and password `b1b2b3l@w+`.
You must always set the billing address to place an order.
19
19
20
-
Use the [setBillingAddressOnCart]({{ page.baseurl }}/graphql/mutations/set-billing-address.html) mutation to set a billing address. You can set the billing address in the following ways:
20
+
Use the [setBillingAddressOnCart]({{ page.baseurl }}/graphql/mutations/set-billing-address.html) mutation to set a billing address.
21
21
22
-
* Add a new billing address
23
-
* Add a new billing address and set it as the shipping addresses
24
-
* Use an address from the logged-in customer's address book
22
+
## Add a billing address to the cart
25
23
26
-
## Add a new billing address
24
+
Similar to the shipping address, add a billing address to the cart. `{ CART_ID }` is the unique shopping cart ID from [Step 2. Create empty cart]({{ page.baseurl }}/graphql/tutorials/checkout/checkout-add-product-to-cart.html). The street address is also different, so we can see that different addresses are being created.
27
25
28
-
The following mutation adds a new billing address. `{ CART_ID }` is the unique shopping cart ID from [Step 2. Create empty cart]({{page.baseurl}}/graphql/tutorials/checkout/checkout-add-product-to-cart.html).
26
+
Send the customer's authorization token in the `Authorization` parameter of the header. See [Authorization tokens]({{page.baseurl}}/graphql/authorization-tokens.html) for more information.
29
27
30
28
**Request:**
31
29
32
-
{:.bs-callout .bs-callout-info}
33
-
For logged-in customers, send the customer's authorization token in the `Authorization` parameter of the header. See [Authorization tokens]({{page.baseurl}}/graphql/authorization-tokens.html) for more information.
34
-
35
30
```graphql
36
31
mutation {
37
32
setBillingAddressOnCart(
@@ -42,236 +37,15 @@ mutation {
42
37
firstname: "John"
43
38
lastname: "Doe"
44
39
company: "Company Name"
45
-
street: ["320 N Crescent Dr", "Beverly Hills"]
40
+
street: ["64 Strawberry Dr", "Beverly Hills"]
46
41
city: "Los Angeles"
47
42
region: "CA"
43
+
region_id: 12
48
44
postcode: "90210"
49
45
country_code: "US"
50
46
telephone: "123-456-0000"
51
-
save_in_address_book: false
52
-
}
53
-
}
54
-
}
55
-
) {
56
-
cart {
57
-
billing_address {
58
-
firstname
59
-
lastname
60
-
company
61
-
street
62
-
city
63
-
region{
64
-
code
65
-
label
66
-
}
67
-
postcode
68
-
telephone
69
-
country {
70
-
code
71
-
label
72
-
}
73
-
}
74
-
}
75
-
}
76
-
}
77
-
```
78
-
79
-
**Response:**
80
-
81
-
```json
82
-
{
83
-
"data": {
84
-
"setBillingAddressOnCart": {
85
-
"cart": {
86
-
"billing_address": {
87
-
"firstname": "John",
88
-
"lastname": "Doe",
89
-
"company": "Company Name",
90
-
"street": [
91
-
"320 N Crescent Dr",
92
-
"Beverly Hills"
93
-
],
94
-
"city": "Los Angeles",
95
-
"region": {
96
-
"code": "CA",
97
-
"label": "California"
98
-
},
99
-
"postcode": "90210",
100
-
"telephone": "123-456-0000",
101
-
"country": {
102
-
"code": "US",
103
-
"label": "US"
104
-
}
105
-
}
106
-
}
107
-
}
108
-
}
109
-
}
110
-
```
111
-
112
-
## Add a new address for billing and shipping
113
-
114
-
The following mutation includes the `same_as_shipping` attribute, which allows the same address to be used for billing and shipping.
115
-
116
-
**Request:**
117
-
118
-
```text
119
-
mutation {
120
-
setBillingAddressOnCart(
121
-
input: {
122
-
cart_id: "{ CART_ID }"
123
-
billing_address: {
124
-
address: {
125
-
firstname: "John"
126
-
lastname: "Doe"
127
-
company: "Company Name"
128
-
street: ["320 N Crescent Dr", "Beverly Hills"]
129
-
city: "Los Angeles"
130
-
region: "CA"
131
-
postcode: "90210"
132
-
country_code: "US"
133
-
telephone: "123-456-0000"
134
-
save_in_address_book: false
135
-
}
136
-
same_as_shipping: true
137
-
}
138
-
}
139
-
) {
140
-
cart {
141
-
billing_address {
142
-
firstname
143
-
lastname
144
-
company
145
-
street
146
-
city
147
-
region{
148
-
code
149
-
label
150
-
}
151
-
postcode
152
-
telephone
153
-
country {
154
-
code
155
-
label
156
-
}
157
-
}
158
-
shipping_addresses {
159
-
firstname
160
-
lastname
161
-
company
162
-
street
163
-
city
164
-
postcode
165
-
telephone
166
-
country {
167
-
code
168
-
label
169
-
}
170
-
}
171
-
}
172
-
}
173
-
}
174
-
```
175
-
176
-
**Response:**
177
-
178
-
```json
179
-
{
180
-
"data": {
181
-
"setBillingAddressOnCart": {
182
-
"cart": {
183
-
"billing_address": {
184
-
"firstname": "John",
185
-
"lastname": "Doe",
186
-
"company": "Company Name",
187
-
"street": [
188
-
"320 N Crescent Dr",
189
-
"Beverly Hills"
190
-
],
191
-
"city": "Los Angeles",
192
-
"region": {
193
-
"code": "CA",
194
-
"label": "California"
195
-
},
196
-
"postcode": "90210",
197
-
"telephone": "123-456-0000",
198
-
"country": {
199
-
"code": "US",
200
-
"label": "US"
201
-
}
202
-
},
203
-
"shipping_addresses": [
204
-
{
205
-
"firstname": "John",
206
-
"lastname": "Doe",
207
-
"company": "Company Name",
208
-
"street": [
209
-
"320 N Crescent Dr",
210
-
"Beverly Hills"
211
-
],
212
-
"city": "Los Angeles",
213
-
"postcode": "90210",
214
-
"telephone": "123-456-0000",
215
-
"country": {
216
-
"code": "US",
217
-
"label": "US"
218
-
}
219
-
}
220
-
]
221
-
}
222
-
}
223
-
}
224
-
}
225
-
```
226
-
227
-
## Use an existing customer address
228
-
229
-
First, query the customer to return the list of address IDs.
230
-
231
-
**Request:**
232
-
233
-
```text
234
-
query {
235
-
customer {
236
-
addresses {
237
-
id
238
-
default_billing
239
-
default_shipping
240
-
}
241
-
}
242
-
}
243
-
```
244
-
245
-
**Response:**
246
-
247
-
```text
248
-
"data": {
249
-
"customer": {
250
-
"addresses": [
251
-
{
252
-
"id": 2,
253
-
"default_billing": true,
254
-
"default_shipping": true
47
+
save_in_address_book: true
255
48
}
256
-
]
257
-
}
258
-
}
259
-
}
260
-
```
261
-
262
-
Set `{ CUSTOMER_ADDRESS_ID }` to an `id` returned in the query.
263
-
264
-
`{ CART_ID }` is the unique shopping cart ID from [Step 2. Create empty cart]({{ page.baseurl }}/graphql/tutorials/checkout/checkout-add-product-to-cart.html).
0 commit comments