File tree Expand file tree Collapse file tree 9 files changed +365
-0
lines changed
guides/v2.3/graphql/tutorials Expand file tree Collapse file tree 9 files changed +365
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ layout : tutorial
3
+ group : graphql
4
+ title : Step 3. Add product to cart
5
+ subtitle : GraphQl checkout tutorial
6
+ return_to :
7
+ title : GraphQl checkout tutorial
8
+ url : graphql/tutorials/index.html
9
+ menu_order : 3
10
+ contributor_name : Atwix
11
+ contributor_link : https://www.atwix.com/
12
+ ---
13
+
14
+ ** Request**
15
+ ``` text
16
+ mutation addSimpleProductsToCart(
17
+ $cart_id: String!
18
+ $qty: Float!
19
+ $sku: String!
20
+ ) {
21
+ addSimpleProductsToCart(
22
+ input: {
23
+ cart_id: $cart_id
24
+ cartItems: {
25
+ customizable_options: []
26
+ data: {
27
+ qty: $qty
28
+ sku: $sku
29
+ }
30
+ }
31
+ }
32
+ ) {
33
+ cart {
34
+ items {
35
+ id
36
+ product {
37
+ sku
38
+ stock_status
39
+ }
40
+ qty
41
+ }
42
+ }
43
+ }
44
+ }
45
+ ```
46
+
47
+ ** Response**
48
+ ``` json
49
+ ```
Original file line number Diff line number Diff line change
1
+ ---
2
+ layout : tutorial
3
+ group : graphql
4
+ title : Step 5. Set billing address
5
+ subtitle : GraphQl checkout tutorial
6
+ return_to :
7
+ title : GraphQl checkout tutorial
8
+ url : graphql/tutorials/index.html
9
+ menu_order : 5
10
+ contributor_name : Atwix
11
+ contributor_link : https://www.atwix.com/
12
+ ---
13
+
14
+ ** Request**
15
+ ``` text
16
+ ```
17
+
18
+ ** Response**
19
+ ``` json
20
+ ```
Original file line number Diff line number Diff line change
1
+ ---
2
+ layout : tutorial
3
+ group : graphql
4
+ title : Step 1. Define customer
5
+ subtitle : GraphQl checkout tutorial
6
+ return_to :
7
+ title : GraphQl checkout tutorial
8
+ url : graphql/tutorials/index.html
9
+ menu_order : 1
10
+ contributor_name : Atwix
11
+ contributor_link : https://www.atwix.com/
12
+ ---
13
+
14
+ Customers can make purchases in two ways:
15
+ - As a logged-in user
16
+ - As a guest user who does not create an account
17
+
18
+ If you want to place order as guest then skip this step.
19
+
20
+ If you want to place order as a new customer then you should use ` createCustomer ` mutation to register new customer in the store.
21
+
22
+ ** Request**
23
+ ``` text
24
+ mutation {
25
+ createCustomer(
26
+ input: {
27
+ firstname: "Bob"
28
+ lastname: "Loblaw"
29
+
30
+ password: "b0bl0bl@w"
31
+ is_subscribed: true
32
+ }
33
+ ) {
34
+ customer {
35
+ id
36
+ firstname
37
+ lastname
38
+ email
39
+ is_subscribed
40
+ }
41
+ }
42
+ }
43
+ ```
44
+
45
+ ** Response**
46
+ ``` json
47
+ {
48
+ "data" : {
49
+ "createCustomer" : {
50
+ "customer" : {
51
+ "id" : 5 ,
52
+ "firstname" : " Bob" ,
53
+ "lastname" : " Loblaw" ,
54
+
55
+ "is_subscribed" : true
56
+ }
57
+ }
58
+ }
59
+ }
60
+ ```
61
+
62
+ Check this [ "Customer endpoint"] ({{ page.baseurl }}/graphql/reference/customer.html#create-a-customer) page to get the additional information.
63
+
64
+ If you want to place order as a new customer or a registered customer then you should get customer's authorization token. Use ` generateCustomerToken ` mutation for that.
65
+ ** Request**
66
+ ``` text
67
+ mutation {
68
+ generateCustomerToken(email: "[email protected] ", password: "b0bl0bl@w") {
69
+ token
70
+ }
71
+ }
72
+ ```
73
+
74
+ ** Response**
75
+ ``` json
76
+ {
77
+ "data" : {
78
+ "generateCustomerToken" : {
79
+ "token" : " hoyz7k697ubv5hcpq92yrtx39i7x10um"
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ See [ "Get customer authorization token"] ({{ page.baseurl }}/graphql/get-customer-authorization-token.html) topic to get more details.
Original file line number Diff line number Diff line change
1
+ ---
2
+ layout : tutorial
3
+ group : graphql
4
+ title : Step 7. Set payment method
5
+ subtitle : GraphQl checkout tutorial
6
+ return_to :
7
+ title : GraphQl checkout tutorial
8
+ url : graphql/tutorials/index.html
9
+ menu_order : 7
10
+ contributor_name : Atwix
11
+ contributor_link : https://www.atwix.com/
12
+ ---
13
+
14
+ Use the following query to get all available payment methods for your order.
15
+
16
+ ** Request**
17
+ ``` text
18
+ {
19
+ cart(cart_id: "$maskedQuoteId") {
20
+ available_payment_methods {
21
+ code
22
+ title
23
+ }
24
+ }
25
+ }
26
+ ```
27
+
28
+ ** Response**
29
+ ``` json
30
+ ```
Original file line number Diff line number Diff line change
1
+ ---
2
+ layout : tutorial
3
+ group : graphql
4
+ title : Step 8. Place order
5
+ subtitle : GraphQl checkout tutorial
6
+ return_to :
7
+ title : GraphQl checkout tutorial
8
+ url : graphql/tutorials/index.html
9
+ menu_order : 8
10
+ contributor_name : Atwix
11
+ contributor_link : https://www.atwix.com/
12
+ ---
13
+
14
+ ** Request**
15
+ ``` text
16
+ mutation placeOrder(
17
+ $cart_id: String!
18
+ ) {
19
+ placeOrder(
20
+ input: {
21
+ cart_id: $cart_id
22
+ }
23
+ ) {
24
+ order {
25
+ order_id
26
+ }
27
+ }
28
+ }
29
+ ```
30
+
31
+ ** Response**
32
+ ``` json
33
+ ```
Original file line number Diff line number Diff line change
1
+ ---
2
+ layout : tutorial
3
+ group : graphql
4
+ title : Step 4. Set shipping address
5
+ subtitle : GraphQl checkout tutorial
6
+ return_to :
7
+ title : GraphQl checkout tutorial
8
+ url : graphql/tutorials/index.html
9
+ menu_order : 4
10
+ contributor_name : Atwix
11
+ contributor_link : https://www.atwix.com/
12
+ ---
13
+
14
+ ** Request**
15
+ ``` text
16
+ ```
17
+
18
+ ** Response**
19
+ ``` json
20
+ ```
Original file line number Diff line number Diff line change
1
+ ---
2
+ layout : tutorial
3
+ group : graphql
4
+ title : Step 6. Set shipping method
5
+ subtitle : GraphQl checkout tutorial
6
+ return_to :
7
+ title : GraphQl checkout tutorial
8
+ url : graphql/tutorials/index.html
9
+ menu_order : 6
10
+ contributor_name : Atwix
11
+ contributor_link : https://www.atwix.com/
12
+ ---
13
+
14
+ Use ` cart ` query to retrieve available shipping methods for your quote.
15
+ ** Request**
16
+ ``` text
17
+ query {
18
+ cart (cart_id: "{$maskedQuoteId}") {
19
+ shipping_addresses {
20
+ available_shipping_methods {
21
+ amount
22
+ base_amount
23
+ carrier_code
24
+ carrier_title
25
+ error_message
26
+ method_code
27
+ method_title
28
+ price_excl_tax
29
+ price_incl_tax
30
+ }
31
+ }
32
+ }
33
+ }
34
+ ```
35
+
36
+ ** Response**
37
+ ``` json
38
+
39
+ ```
40
+
41
+ Use ` setShippingMethodsOnCart ` mutation query to define a shipping method for your order.
42
+
43
+ ** Request**
44
+ The following mutation query assigns UPS "Ground" method.
45
+ ``` text
46
+ mutation {
47
+ setShippingMethodsOnCart(input: {
48
+ cart_id: "$maskedQuoteId"
49
+ shipping_methods: [
50
+ {
51
+ cart_address_id: $shippingAddressId
52
+ carrier_code: "ups"
53
+ method_code: "GND"
54
+ }
55
+ ]
56
+ }) {
57
+ cart {
58
+ shipping_addresses {
59
+ selected_shipping_method {
60
+ carrier_code
61
+ method_code
62
+ label
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+ ** Response**
71
+ ``` json
72
+
73
+ ```
Original file line number Diff line number Diff line change
1
+ ---
2
+ layout : tutorial
3
+ group : graphql
4
+ title : Step 2. Create empty cart
5
+ subtitle : GraphQl checkout tutorial
6
+ return_to :
7
+ title : GraphQl checkout tutorial
8
+ url : graphql/tutorials/index.html
9
+ menu_order : 2
10
+ contributor_name : Atwix
11
+ contributor_link : https://www.atwix.com/
12
+ ---
13
+
14
+ ** Request**
15
+ This mutation query creates an empty cart:
16
+ ``` text
17
+ mutation {
18
+ createEmptyCart
19
+ }
20
+ ```
21
+
22
+ ** Response**
23
+ ``` json
24
+ {
25
+ "data" : {
26
+ "createEmptyCart" : " gqjcFzgL8hNxxdrqLDEkMP487nOWBXOv"
27
+ }
28
+ }
29
+ ```
30
+
31
+ If you create a shopping cart for the registered customer then you should send customer's authorization token in the ` Authorization ` parameter of the header:
32
+
33
+ ![ GraphiQL Authorization Bearer] ({{ page.baseurl }}/graphql/images/graphql-authorization.png)
Original file line number Diff line number Diff line change
1
+ ---
2
+ group : graphql
3
+ title : GraphQl checkout tutorial
4
+ contributor_name : Atwix
5
+ contributor_link : https://www.atwix.com/
6
+ ---
7
+
8
+ This tutorial provides information how you can place order through GraphQl. Customers can make purchases in two ways:
9
+ - As a logged-in user
10
+ - As a guest user who does not create an account
11
+
12
+ Basically checkout process in GraphQl consists of the next steps:
13
+ - define customer (create customer or use registered customer account or place order as guest)
14
+ - create empty cart
15
+ - add a product to cart
16
+ - set shipping address
17
+ - set billing address
18
+ - set shipping method
19
+ - set payment method
20
+ - place order
21
+
22
+ //setQuoteEmail
You can’t perform that action at this time.
0 commit comments