Amber Shopify Project created using ReactJS+React-Redux with GraphQL API integration. Storefront Shopify API: https://github.com/Shopify/shopify-app-js/tree/main/packages/api-clients/storefront-api-client#readme
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

guide.txt 6.4KB

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