Skip to content

Commit 9b5d929

Browse files
committed
magento#589: Add a tutorial for the checkout workflow
1 parent 279bf7a commit 9b5d929

11 files changed

+750
-68
lines changed

guides/v2.3/graphql/tutorials/checkout/checkout-add-product-to-cart.md

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,30 @@ contributor_name: Atwix
1111
contributor_link: https://www.atwix.com/
1212
---
1313

14+
GraphQL supports [7 types of product]({{ page.baseurl }}/graphql/reference/product-interface-implementations.html) which can be added into shopping cart:
15+
- bundle product
16+
- configurable product
17+
- downloadable product
18+
- grouped product
19+
- simple product
20+
- virtual product
21+
- gift card product (available for commerce version)
22+
1423
**Request**
24+
The following query adds a simple product into shopping cart.
1525
```text
16-
mutation addSimpleProductsToCart(
17-
$cart_id: String!
18-
$qty: Float!
19-
$sku: String!
20-
) {
26+
mutation {
2127
addSimpleProductsToCart(
2228
input: {
23-
cart_id: $cart_id
24-
cartItems: {
25-
customizable_options: []
26-
data: {
27-
qty: $qty
28-
sku: $sku
29+
cart_id: "{{ CART_ID }}"
30+
cartItems: [
31+
{
32+
data: {
33+
qty: 1
34+
sku: "simple-product"
35+
}
2936
}
30-
}
37+
]
3138
}
3239
) {
3340
cart {
@@ -44,6 +51,32 @@ mutation addSimpleProductsToCart(
4451
}
4552
```
4653

54+
where
55+
`{{ CART_ID }}` - shopping cart unique ID from [Step 2. Create empty cart]({{ page.baseurl }}/graphql/tutorials/checkout/checkout-add-product-to-cart.html).
56+
4757
**Response**
4858
```json
49-
```
59+
{
60+
"data": {
61+
"addSimpleProductsToCart": {
62+
"cart": {
63+
"items": [
64+
{
65+
"id": "508",
66+
"product": {
67+
"sku": "simple-product",
68+
"stock_status": "IN_STOCK"
69+
},
70+
"qty": 1
71+
}
72+
]
73+
}
74+
}
75+
}
76+
}
77+
```
78+
79+
{:.bs-callout .bs-callout-info}
80+
Send customer's authorization token in the `Authorization` parameter of the header if you add product into shopping cart as a registered customer. See ["Get customer authorization token"]({{ page.baseurl }}/graphql/get-customer-authorization-token.html) to get more details.
81+
82+
Use `updateCartItems` mutation query to update shopping cart items and `removeItemFromCart` to remove product from the shopping cart.

0 commit comments

Comments
 (0)