|
@@ -0,0 +1,306 @@
|
|
1
|
+Basic Implementation of Cart
|
|
2
|
+
|
|
3
|
+1. Create cart using mutation
|
|
4
|
+
|
|
5
|
+mutation CreateCart {
|
|
6
|
+ cartCreate {
|
|
7
|
+ cart {
|
|
8
|
+ id
|
|
9
|
+ createdAt
|
|
10
|
+ updatedAt
|
|
11
|
+ }
|
|
12
|
+ userErrors {
|
|
13
|
+ field
|
|
14
|
+ message
|
|
15
|
+ }
|
|
16
|
+ }
|
|
17
|
+}
|
|
18
|
+
|
|
19
|
+response:
|
|
20
|
+
|
|
21
|
+{
|
|
22
|
+ "data": {
|
|
23
|
+ "cartCreate": {
|
|
24
|
+ "cart": {
|
|
25
|
+ "id": "gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz?key=6979c8734cf8208ce9021ba5947673d7",
|
|
26
|
+ "createdAt": "2024-12-19T06:36:30Z",
|
|
27
|
+ "updatedAt": "2024-12-19T06:36:30Z"
|
|
28
|
+ },
|
|
29
|
+ "userErrors": []
|
|
30
|
+ }
|
|
31
|
+ }
|
|
32
|
+}
|
|
33
|
+
|
|
34
|
+2. Add a line item to the cart
|
|
35
|
+
|
|
36
|
+mutation AddItemToCart($cartId: ID!, $lines: [CartLineInput!]!) {
|
|
37
|
+ cartLinesAdd(cartId: $cartId, lines: $lines) {
|
|
38
|
+ cart {
|
|
39
|
+ id
|
|
40
|
+ lines(first: 10) {
|
|
41
|
+ edges {
|
|
42
|
+ node {
|
|
43
|
+ id
|
|
44
|
+ quantity
|
|
45
|
+ merchandise {
|
|
46
|
+ ... on ProductVariant {
|
|
47
|
+ id
|
|
48
|
+ title
|
|
49
|
+ }
|
|
50
|
+ }
|
|
51
|
+ }
|
|
52
|
+ }
|
|
53
|
+ }
|
|
54
|
+ }
|
|
55
|
+ userErrors {
|
|
56
|
+ field
|
|
57
|
+ message
|
|
58
|
+ }
|
|
59
|
+ }
|
|
60
|
+}
|
|
61
|
+
|
|
62
|
+{
|
|
63
|
+ "cartId": "gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz?key=6979c8734cf8208ce9021ba5947673d7",
|
|
64
|
+ "lines": [
|
|
65
|
+ {
|
|
66
|
+ "quantity": 2,
|
|
67
|
+ "merchandiseId": "gid://shopify/ProductVariant/42372238213203"
|
|
68
|
+ }
|
|
69
|
+ ]
|
|
70
|
+}
|
|
71
|
+
|
|
72
|
+response:
|
|
73
|
+{
|
|
74
|
+ "data": {
|
|
75
|
+ "cartLinesAdd": {
|
|
76
|
+ "cart": {
|
|
77
|
+ "id": "gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz?key=6979c8734cf8208ce9021ba5947673d7",
|
|
78
|
+ "lines": {
|
|
79
|
+ "edges": [
|
|
80
|
+ {
|
|
81
|
+ "node": {
|
|
82
|
+ "id": "gid://shopify/CartLine/1fef0eff-d077-4d50-8c03-36c748d245a3?cart=Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz",
|
|
83
|
+ "quantity": 2,
|
|
84
|
+ "merchandise": {
|
|
85
|
+ "id": "gid://shopify/ProductVariant/42372238213203",
|
|
86
|
+ "title": "M"
|
|
87
|
+ }
|
|
88
|
+ }
|
|
89
|
+ }
|
|
90
|
+ ]
|
|
91
|
+ }
|
|
92
|
+ },
|
|
93
|
+ "userErrors": []
|
|
94
|
+ }
|
|
95
|
+ }
|
|
96
|
+}
|
|
97
|
+
|
|
98
|
+3. Get back the cart
|
|
99
|
+query GetCart($cartId: ID!) {
|
|
100
|
+ cart(id: $cartId) {
|
|
101
|
+ id
|
|
102
|
+ createdAt
|
|
103
|
+ updatedAt
|
|
104
|
+ lines(first: 10) {
|
|
105
|
+ edges {
|
|
106
|
+ node {
|
|
107
|
+ id
|
|
108
|
+ quantity
|
|
109
|
+ merchandise {
|
|
110
|
+ ... on ProductVariant {
|
|
111
|
+ id
|
|
112
|
+ title
|
|
113
|
+ }
|
|
114
|
+ }
|
|
115
|
+ }
|
|
116
|
+ }
|
|
117
|
+ }
|
|
118
|
+ }
|
|
119
|
+}
|
|
120
|
+
|
|
121
|
+{
|
|
122
|
+ "cartId": "gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz?key=6979c8734cf8208ce9021ba5947673d7"
|
|
123
|
+}
|
|
124
|
+
|
|
125
|
+response:
|
|
126
|
+{
|
|
127
|
+ "data": {
|
|
128
|
+ "cart": {
|
|
129
|
+ "id": "gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz?key=6979c8734cf8208ce9021ba5947673d7",
|
|
130
|
+ "createdAt": "2024-12-19T06:36:30Z",
|
|
131
|
+ "updatedAt": "2024-12-19T06:49:00Z",
|
|
132
|
+ "lines": {
|
|
133
|
+ "edges": [
|
|
134
|
+ {
|
|
135
|
+ "node": {
|
|
136
|
+ "id": "gid://shopify/CartLine/1fef0eff-d077-4d50-8c03-36c748d245a3?cart=Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz",
|
|
137
|
+ "quantity": 2,
|
|
138
|
+ "merchandise": {
|
|
139
|
+ "id": "gid://shopify/ProductVariant/42372238213203",
|
|
140
|
+ "title": "M"
|
|
141
|
+ }
|
|
142
|
+ }
|
|
143
|
+ }
|
|
144
|
+ ]
|
|
145
|
+ }
|
|
146
|
+ }
|
|
147
|
+ }
|
|
148
|
+}
|
|
149
|
+
|
|
150
|
+4. Update the item quantiy based on cart line
|
|
151
|
+
|
|
152
|
+mutation {
|
|
153
|
+ cartLinesUpdate(
|
|
154
|
+ cartId: "gid://shopify/Cart/Z2NwLXVzLWV4YW1wbGU6MDEyMzQ1Njc4OTAxMjM0NTY3ODkw?key=examplekey1234567890"
|
|
155
|
+ lines: {
|
|
156
|
+ id: "gid://shopify/CartLine/1fef0eff-d077-4d50-8c03-36c748d245a3?cart=Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz"
|
|
157
|
+ quantity: 3
|
|
158
|
+ }
|
|
159
|
+ ) {
|
|
160
|
+ cart {
|
|
161
|
+ id
|
|
162
|
+ lines(first: 10) {
|
|
163
|
+ edges {
|
|
164
|
+ node {
|
|
165
|
+ id
|
|
166
|
+ quantity
|
|
167
|
+ merchandise {
|
|
168
|
+ ... on ProductVariant {
|
|
169
|
+ id
|
|
170
|
+ }
|
|
171
|
+ }
|
|
172
|
+ }
|
|
173
|
+ }
|
|
174
|
+ }
|
|
175
|
+ cost {
|
|
176
|
+ totalAmount {
|
|
177
|
+ amount
|
|
178
|
+ currencyCode
|
|
179
|
+ }
|
|
180
|
+ subtotalAmount {
|
|
181
|
+ amount
|
|
182
|
+ currencyCode
|
|
183
|
+ }
|
|
184
|
+ totalTaxAmount {
|
|
185
|
+ amount
|
|
186
|
+ currencyCode
|
|
187
|
+ }
|
|
188
|
+ totalDutyAmount {
|
|
189
|
+ amount
|
|
190
|
+ currencyCode
|
|
191
|
+ }
|
|
192
|
+ }
|
|
193
|
+ }
|
|
194
|
+ }
|
|
195
|
+}
|
|
196
|
+
|
|
197
|
+5. Get cart with the total price
|
|
198
|
+
|
|
199
|
+query GetCart($cartId: ID!) {
|
|
200
|
+ cart(id: $cartId) {
|
|
201
|
+ id
|
|
202
|
+ createdAt
|
|
203
|
+
|
|
204
|
+ cost {
|
|
205
|
+ subtotalAmount {
|
|
206
|
+ amount
|
|
207
|
+ currencyCode
|
|
208
|
+ }
|
|
209
|
+ totalAmount {
|
|
210
|
+ amount
|
|
211
|
+ currencyCode
|
|
212
|
+ }
|
|
213
|
+ totalTaxAmount {
|
|
214
|
+ amount
|
|
215
|
+ currencyCode
|
|
216
|
+ }
|
|
217
|
+ }
|
|
218
|
+ lines(first: 10) {
|
|
219
|
+ edges {
|
|
220
|
+ node {
|
|
221
|
+ id
|
|
222
|
+ quantity
|
|
223
|
+ merchandise {
|
|
224
|
+ ... on ProductVariant {
|
|
225
|
+ id
|
|
226
|
+ title
|
|
227
|
+ price {
|
|
228
|
+ amount
|
|
229
|
+ currencyCode
|
|
230
|
+ }
|
|
231
|
+ product {
|
|
232
|
+ title
|
|
233
|
+ }
|
|
234
|
+ }
|
|
235
|
+ }
|
|
236
|
+ }
|
|
237
|
+ }
|
|
238
|
+ }
|
|
239
|
+ }
|
|
240
|
+}
|
|
241
|
+
|
|
242
|
+{
|
|
243
|
+ "cartId": "gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz?key=6979c8734cf8208ce9021ba5947673d7"
|
|
244
|
+}
|
|
245
|
+
|
|
246
|
+response:
|
|
247
|
+{
|
|
248
|
+ "data": {
|
|
249
|
+ "cart": {
|
|
250
|
+ "id": "gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz?key=6979c8734cf8208ce9021ba5947673d7",
|
|
251
|
+ "createdAt": "2024-12-19T06:36:30Z",
|
|
252
|
+ "cost": {
|
|
253
|
+ "subtotalAmount": {
|
|
254
|
+ "amount": "1750.0",
|
|
255
|
+ "currencyCode": "MYR"
|
|
256
|
+ },
|
|
257
|
+ "totalAmount": {
|
|
258
|
+ "amount": "1925.0",
|
|
259
|
+ "currencyCode": "MYR"
|
|
260
|
+ },
|
|
261
|
+ "totalTaxAmount": {
|
|
262
|
+ "amount": "175.0",
|
|
263
|
+ "currencyCode": "MYR"
|
|
264
|
+ }
|
|
265
|
+ },
|
|
266
|
+ "lines": {
|
|
267
|
+ "edges": [
|
|
268
|
+ {
|
|
269
|
+ "node": {
|
|
270
|
+ "id": "gid://shopify/CartLine/1fef0eff-d077-4d50-8c03-36c748d245a3?cart=Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz",
|
|
271
|
+ "quantity": 5,
|
|
272
|
+ "merchandise": {
|
|
273
|
+ "id": "gid://shopify/ProductVariant/42372238213203",
|
|
274
|
+ "title": "M",
|
|
275
|
+ "price": {
|
|
276
|
+ "amount": "350.0",
|
|
277
|
+ "currencyCode": "MYR"
|
|
278
|
+ },
|
|
279
|
+ "product": {
|
|
280
|
+ "title": "KEMBOJA IN BEIGE"
|
|
281
|
+ }
|
|
282
|
+ }
|
|
283
|
+ }
|
|
284
|
+ }
|
|
285
|
+ ]
|
|
286
|
+ }
|
|
287
|
+ }
|
|
288
|
+ }
|
|
289
|
+}
|
|
290
|
+
|
|
291
|
+6. Generate checkout url
|
|
292
|
+
|
|
293
|
+query checkoutURL {
|
|
294
|
+ cart(id: "gid://shopify/Cart/Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz?key=6979c8734cf8208ce9021ba5947673d7") {
|
|
295
|
+ checkoutUrl
|
|
296
|
+ }
|
|
297
|
+}
|
|
298
|
+
|
|
299
|
+response:
|
|
300
|
+{
|
|
301
|
+ "data": {
|
|
302
|
+ "cart": {
|
|
303
|
+ "checkoutUrl": "https://amberdevstore.myshopify.com/cart/c/Z2NwLXVzLWVhc3QxOjAxSkZFVDNONktKMjJNUlE4NTI2UVo0Tlcz?key=6979c8734cf8208ce9021ba5947673d7"
|
|
304
|
+ }
|
|
305
|
+ }
|
|
306
|
+}
|