Bladeren bron

shopping bag

master
azri 10 uur geleden
bovenliggende
commit
a646356766

+ 1
- 4
src/App.js Bestand weergeven

@@ -30,10 +30,7 @@ function App() {
30 30
     // if we got cart, then just fetch from BE based on ID
31 31
     if (!isEmptyObject(cartHistory)) {
32 32
 
33
-      let cartId = cartHistory.id.split('/')
34
-      cartId = cartId[cartId.length - 1]
35
-
36
-      dispatch(fetchCart("gid://shopify/Cart/Z2NwLWFzaWEtc291dGhlYXN0MTowMUpGTkVDODRQNFY2RUtNV1JZTlJDVFBQNA?key=6d58758401066b048e3795c9cf0fa716"));
33
+      dispatch(fetchCart(cartHistory.id));
37 34
 
38 35
     }
39 36
 

+ 41
- 23
src/components/Navbar/Navbar.jsx Bestand weergeven

@@ -17,6 +17,11 @@ import CategoryIcon from '@mui/icons-material/Category';
17 17
 import HomeIcon from '@mui/icons-material/Home';
18 18
 import BrushIcon from '@mui/icons-material/Brush';
19 19
 import LoyaltyIcon from '@mui/icons-material/Loyalty';
20
+import { useSelector } from 'react-redux';
21
+
22
+function calculateTotalQuantity(cartItems) {
23
+  return cartItems.reduce((total, item) => total + item.quantity, 0);
24
+}
20 25
 
21 26
 const LanguageSelect = styled(Select)(({ theme }) => ({
22 27
   backgroundColor: 'black',
@@ -49,37 +54,50 @@ const LanguageSelectItem = styled(MenuItem)(() => ({
49 54
   },
50 55
 }));
51 56
 
57
+const navItem = [
58
+  {
59
+    title: "DISCOVER",
60
+    link: "/products",
61
+    icon: <CategoryIcon />
62
+  },
63
+  {
64
+    title: "HOME",
65
+    link: "/",
66
+    icon: <HomeIcon />
67
+  },
68
+  {
69
+    title: "BEAUTY",
70
+    link: "/products",
71
+    icon: <BrushIcon />
72
+  },
73
+  {
74
+    title: "SALE",
75
+    link: "/products",
76
+    icon: <LoyaltyIcon />
77
+  }
78
+]
79
+
52 80
 
53 81
 const Navbar = () => {
54 82
 
55 83
   const [showHeader, setShowHeader] = useState(true);
56 84
   const [lastScrollPos, setLastScrollPos] = useState(0);
57 85
   const [language, setLanguage] = useState('English');
86
+  
87
+  const cart = useSelector((state) => state.cart.cart)
88
+  const [cartAmount, setCartAmount] = useState(0);
58 89
 
59 90
   const [open, setOpen] = React.useState(false);
91
+  
92
+  useEffect(() => {
93
+    
94
+    if(!cart?.lines?.nodes) return // don't need to do anything if we have no cart data
95
+
96
+    setCartAmount(calculateTotalQuantity(cart?.lines?.nodes))
97
+
98
+  }, [cart])
99
+  
60 100
 
61
-  const navItem = [
62
-    {
63
-      title: "DISCOVER",
64
-      link: "/products",
65
-      icon: <CategoryIcon />
66
-    },
67
-    {
68
-      title: "HOME",
69
-      link: "/",
70
-      icon: <HomeIcon />
71
-    },
72
-    {
73
-      title: "BEAUTY",
74
-      link: "/products",
75
-      icon: <BrushIcon />
76
-    },
77
-    {
78
-      title: "SALE",
79
-      link: "/products",
80
-      icon: <LoyaltyIcon />
81
-    }
82
-  ]
83 101
 
84 102
   const handleChange = (event) => {
85 103
     setLanguage(event.target.value);
@@ -228,7 +246,7 @@ const Navbar = () => {
228 246
               <SearchIcon sx={{ color: "white" }} />
229 247
             </IconButton>
230 248
 
231
-            <Badge sx={{cursor:"pointer"}} onClick={()=>{ window.location.href = "/cart" }} badgeContent={1} color="primary">
249
+            <Badge sx={{cursor:"pointer"}} onClick={()=>{ window.location.href = "/cart" }} badgeContent={cartAmount} color="primary">
232 250
               <LocalMallIcon color="action" sx={{ color: "white" }} />
233 251
             </Badge>
234 252
 

+ 56
- 21
src/components/ProductDetails/ProductDetails.jsx Bestand weergeven

@@ -3,12 +3,15 @@ import {
3 3
   Box,
4 4
   Typography,
5 5
   Button,
6
-  TextField
6
+  TextField,
7
+  CircularProgress
7 8
 } from "@mui/material";
8 9
 import AddIcon from '@mui/icons-material/Add';
9 10
 import RemoveIcon from '@mui/icons-material/Remove';
10 11
 import { useSelector, useDispatch } from "react-redux";
11
-import { createCart } from "../../redux/slices/cartSlice";
12
+import { createCart, addItemToCart } from "../../redux/slices/cartSlice";
13
+import Alert from '@mui/material/Alert';
14
+import AlertTitle from '@mui/material/AlertTitle';
12 15
 
13 16
 // Utility function to check if an object is empty
14 17
 const isEmptyObject = (obj) => Object.keys(obj).length === 0 && obj.constructor === Object;
@@ -31,6 +34,8 @@ const ProductDetails = () => {
31 34
     quantityAvailable: 0
32 35
   })
33 36
   const [variants, setVariants] = useState([])
37
+  const [showLoader, setShowLoader] = useState(false)
38
+  const [alert, setAlert] = useState({ open: false, severity: '', message: '' });
34 39
 
35 40
   useEffect(() => {
36 41
     if (product) {
@@ -138,33 +143,53 @@ const ProductDetails = () => {
138 143
     let cartHistory = localStorage.getItem('amber-cart');
139 144
     cartHistory = cartHistory ? JSON.parse(cartHistory) : {};
140 145
 
146
+    setShowLoader(true) //cause I want to prevent user from mutiple clicking
147
+
141 148
     // if we got no cart, then create a new one
142 149
     if (isEmptyObject(cart) || isEmptyObject(cartHistory)) {
143 150
 
144
-      dispatch(createCart());
151
+      dispatch(createCart())
152
+      .then(() => {
153
+        showAlert('success', 'Cart created successfully!');
154
+      })
155
+      .catch(() => {
156
+        showAlert('error', 'Failed to create cart. Please try again.');
157
+      })
158
+      .finally(() => setShowLoader(false));
145 159
 
146 160
     } else {
147 161
 
148
-      // // Update cart content
149
-      // const existingItemIndex = cartHistory.lines?.findIndex(
150
-      //   (line) => line.merchandiseId === item.merchandiseId
151
-      // );
152
-
153
-      // if (existingItemIndex !== -1) {
154
-      //   // If the item exists, update the quantity
155
-      //   cartHistory.lines[existingItemIndex].quantity += item.quantity;
156
-      // } else {
157
-      //   // If the item doesn't exist, add it
158
-      //   cartHistory.lines = [...(cartHistory.lines || []), item];
159
-      // }
160
-
161
-      // // Update Redux store and localStorage
162
-      // dispatch(updateCart(cartHistory)); // Redux action to update cart
163
-      // localStorage.setItem('amber-cart', JSON.stringify(cartHistory));
162
+      console.log("ADD ITEM:", variantSelection)
163
+      
164
+      dispatch(addItemToCart({
165
+        cartId: cartHistory.id,
166
+        lines:[
167
+          {
168
+            merchandiseId:variantSelection.id,
169
+            quantity
170
+          }
171
+        ]
172
+      }))
173
+      .then(() => {
174
+        showAlert('success', 'Item added to cart successfully!');
175
+      })
176
+      .catch(() => {
177
+        showAlert('error', 'Failed to add item to cart. Please try again.');
178
+      })
179
+      .finally(() => setShowLoader(false));
164 180
     }
165 181
 
166 182
   }
167 183
 
184
+  const showAlert = (severity, message) => {
185
+    setAlert({ open: true, severity, message });
186
+
187
+    // Auto-close the alert after 3 seconds
188
+    setTimeout(() => {
189
+      setAlert({ ...alert, open: false });
190
+    }, 2000);
191
+  };
192
+
168 193
   const handleIncrement = () => {
169 194
     setQuantity((prevQuantity) => (prevQuantity >= variantSelection.quantityAvailable ? variantSelection.quantityAvailable : prevQuantity + 1));
170 195
   };
@@ -282,6 +307,7 @@ const ProductDetails = () => {
282 307
           variant="contained"
283 308
           color="common.black"
284 309
           fullWidth
310
+          disabled={variantSelection?.quantityAvailable == 0 || showLoader}
285 311
           sx={{
286 312
             backgroundColor: (theme) => theme.palette.common.black,
287 313
             color: "white",
@@ -292,10 +318,19 @@ const ProductDetails = () => {
292 318
             },
293 319
           }}
294 320
         >
295
-          ADD TO CART
321
+          ADD TO CART {showLoader && <CircularProgress sx={{ml:1}} color="white" size={20} />} 
296 322
         </Button>
297 323
       </Box>
298
-
324
+      {alert.open && (
325
+        <Alert
326
+          severity={alert.severity}
327
+          onClose={() => setAlert({ ...alert, open: false })}
328
+          sx={{ marginTop: 2 }}
329
+        >
330
+          <AlertTitle>{alert.severity === 'success' ? 'Success' : 'Error'}</AlertTitle>
331
+          {alert.message}
332
+        </Alert>
333
+      )}
299 334
     </Box>
300 335
   );
301 336
 };

+ 95
- 93
src/pages/Cart.jsx Bestand weergeven

@@ -1,4 +1,4 @@
1
-import React from 'react'
1
+import { useEffect, useState } from 'react'
2 2
 import { Box, Button, IconButton } from '@mui/material'
3 3
 import SocialMedia from '../components/SocialMedia'
4 4
 import Feature from '../components/Feature'
@@ -12,31 +12,24 @@ import TableHead from '@mui/material/TableHead';
12 12
 import TableRow from '@mui/material/TableRow';
13 13
 import AddIcon from '@mui/icons-material/Add';
14 14
 import RemoveIcon from '@mui/icons-material/Remove';
15
+import { useSelector, useDispatch } from 'react-redux';
15 16
 
16 17
 const Cart = () => {
17 18
 
18
-  function createData(img_src, description, colour, quantity, price) {
19
-    return { img_src, description, colour, quantity, price };
20
-  }
21
-
22
-  const rows = [
23
-    {
24
-      img_src: 'https://via.placeholder.com/300',
25
-      name: 'MELUR',
26
-      description: 'Atma Sari New Raya Collection 2024',
27
-      colour: 'black',
28
-      quantity: 1,
29
-      price: 335.50
30
-    },
31
-    {
32
-      img_src: 'https://via.placeholder.com/300',
33
-      name: 'MELUR2',
34
-      description: 'Atma Sari New Raya Collection 2025',
35
-      colour: 'red',
36
-      quantity: 2,
37
-      price: 665.00
38
-    },
39
-  ];
19
+  const dispatch = useDispatch()
20
+  const cart = useSelector((state) => state.cart.cart)
21
+  const [cartProducts, setCartProducts] = useState([]) // this is being used as view only, will not used as a way to manipulate cart in any way
22
+
23
+  useEffect(() => {
24
+
25
+    console.log(cart)
26
+
27
+  }, [])
28
+
29
+  useEffect(() => {
30
+    setCartProducts(cart?.lines?.nodes || [])
31
+  }, [cart])
32
+
40 33
 
41 34
   return (
42 35
     <>
@@ -51,21 +44,14 @@ const Cart = () => {
51 44
           md: 5,
52 45
           lg: 10
53 46
         },
54
-        mt:10
47
+        mt: 10
55 48
       }}>
56 49
 
57 50
 
58 51
         {/* Header */}
59
-        <Grid container spacing={2} alignItems="center" sx={{ mb: 5, flexDirection: { xs: 'column-reverse', lg: 'row' } }}> 
60
-
61
-          {/* Type */}
62
-          <Grid item size={{xs:12, lg:2}}>
63
-            <Typography variant="body2">
64
-              <p>Mens Fashion <span style={{ fontWeight: "bold", display: "inline-block" }}>Shopping Bag</span></p>
65
-            </Typography>
66
-          </Grid>
52
+        <Grid container spacing={2} alignItems="center" sx={{ mb: 5, flexDirection: { xs: 'column-reverse', lg: 'row' } }}>
67 53
 
68
-          <Grid item size={{xs:12, md:4}}>
54
+          <Grid item size={{ xs: 12, md: 4 }}>
69 55
             <Typography variant="h5" sx={{ fontWeight: "bold" }}>
70 56
               SHOPPING BAG
71 57
             </Typography>
@@ -85,7 +71,7 @@ const Cart = () => {
85 71
                   <Typography variant='body1'>Description</Typography>
86 72
                 </TableCell>
87 73
                 <TableCell align='center'>
88
-                  <Typography variant='body1'>Colour</Typography>
74
+                  <Typography variant='body1'>Variant</Typography>
89 75
                 </TableCell>
90 76
                 <TableCell align='center'>
91 77
 
@@ -97,49 +83,59 @@ const Cart = () => {
97 83
               </TableRow>
98 84
             </TableHead>
99 85
             <TableBody>
100
-              {rows.map((row) => (
101
-                <TableRow
102
-                  key={row.id}
103
-                  sx={{
104
-                    '& td, & th': { border: 0 },
105
-                    '&:last-child td, &:last-child th': { border: 0 }
106
-                  }}
107
-                >
108
-                  <TableCell component="th" scope="row">
109
-                    <img
110
-                      src={row.img_src}
111
-                      alt={row.img_src}
112
-                      style={{
113
-                        width: 100,
114
-                        height: 100,
115
-                        aspectRatio: '4 / 4',
116
-                        objectFit: 'cover',
117
-                      }}
118
-                    />
119
-                  </TableCell>
120
-                  <TableCell>
121
-                    <Typography variant='body2' sx={{ fontWeight: "bold", mb: 1 }}>{row.name}</Typography>
122
-                    <Typography variant='body2'>{row.description}</Typography>
123
-                  </TableCell>
124
-                  <TableCell align='center'>
125
-                    <Typography variant='h6' sx={{ fontWeight: "bold" }} >{row.colour}</Typography>
126
-                  </TableCell>
127
-                  <TableCell align='center'>
128
-                    <Box sx={{ display: "flex", justifyContent: "center" }}>
129
-                      <IconButton>
130
-                        <RemoveIcon sx={{ fontSize: 16, margin: "0 15px" }} />
131
-                      </IconButton>
132
-                      <p style={{ fontSize: 20, fontWeight: "bold" }}>{row.quantity}</p>
133
-                      <IconButton >
134
-                        <AddIcon sx={{ fontSize: 16, margin: "0 15px" }} />
135
-                      </IconButton>
136
-                    </Box>
137
-                  </TableCell>
138
-                  <TableCell align='center'>
139
-                    <Typography variant='h6' sx={{ fontWeight: "bold" }}>{`RM ${parseFloat(row.price).toFixed(2)}`}</Typography>
140
-                  </TableCell>
141
-                </TableRow>
142
-              ))}
86
+              {cartProducts?.map(({ cost, merchandise, quantity }) => {
87
+                
88
+                let {amount, currencyCode} = cost.totalAmount
89
+                let {id, image, product, title } = merchandise // the title here is actually the variant title name
90
+
91
+                return (
92
+                  <TableRow
93
+                    key={id}
94
+                    sx={{
95
+                      '& td, & th': { border: 0 },
96
+                      '&:last-child td, &:last-child th': { border: 0 }
97
+                    }}
98
+                  >
99
+                    <TableCell component="th" scope="row">
100
+                      <img
101
+                        src={image.src}
102
+                        alt={image.src}
103
+                        style={{
104
+                          width: 100,
105
+                          height: 100,
106
+                          aspectRatio: '4 / 4',
107
+                          objectFit: 'cover',
108
+                          objectPosition:"top center"
109
+                        }}
110
+                      />
111
+                    </TableCell>
112
+                    <TableCell>
113
+                      <Typography variant='body2' sx={{ fontWeight: "bold", mb: 1 }}>{product.title}</Typography>
114
+                      
115
+                      {product?.collections?.nodes?.map(({title}) => (<Typography variant='body2'>{title}</Typography>) )}
116
+
117
+                    </TableCell>
118
+                    <TableCell align='center'>
119
+                      <Typography variant='body2' sx={{ fontWeight: "bold" }} >{title}</Typography>
120
+                    </TableCell>
121
+                    <TableCell align='center'>
122
+                      <Box sx={{ display: "flex", justifyContent: "center" }}>
123
+                        <IconButton>
124
+                          <RemoveIcon sx={{ fontSize: 16, margin: "0 15px" }} />
125
+                        </IconButton>
126
+                        <p style={{ fontSize: 20, fontWeight: "bold" }}>{quantity}</p>
127
+                        <IconButton >
128
+                          <AddIcon sx={{ fontSize: 16, margin: "0 15px" }} />
129
+                        </IconButton>
130
+                      </Box>
131
+                    </TableCell>
132
+                    <TableCell align='center'>
133
+                      <Typography variant='h6' sx={{ fontWeight: "bold" }}>{`${currencyCode} ${parseFloat(amount).toFixed(2)}`}</Typography>
134
+                    </TableCell>
135
+                  </TableRow>
136
+                )
137
+
138
+              })}
143 139
             </TableBody>
144 140
           </Table>
145 141
         </TableContainer>
@@ -147,7 +143,7 @@ const Cart = () => {
147 143
         {/* INVOICES */}
148 144
         <Grid container spacing={2} sx={{ mb: 5 }}>
149 145
 
150
-          <Grid item size={{xs:12, sm:4, md:3}} sx={{ ml: "auto" }}>
146
+          <Grid item size={{ xs: 12, sm: 4, md: 3 }} sx={{ ml: "auto" }}>
151 147
             <Box
152 148
               display="flex"
153 149
               justifyContent="space-between"
@@ -155,16 +151,12 @@ const Cart = () => {
155 151
               sx={{ mb: 2 }}
156 152
             >
157 153
               <Typography variant="body1" sx={{ fontWeight: "400" }}>Subtotal</Typography>
158
-              <Typography variant="body1" sx={{ fontWeight: "400" }}>{`RM ${parseFloat(500).toFixed(2)}`}</Typography>
159
-            </Box>
160
-            <Box
161
-              display="flex"
162
-              justifyContent="space-between"
163
-              alignItems="center"
164
-              sx={{ mb: 2 }}
165
-            >
166
-              <Typography variant="body1" sx={{ fontWeight: "400" }}>Shipping</Typography>
167
-              <Typography variant="body1" sx={{ fontWeight: "400" }}>{`RM ${parseFloat(500).toFixed(2)}`}</Typography>
154
+              <Typography variant="body1" sx={{ fontWeight: "400" }}>
155
+                {`
156
+                  ${cart?.cost?.subtotalAmount?.currencyCode} 
157
+                  ${parseFloat(cart?.cost?.subtotalAmount?.amount).toFixed(2)}
158
+                `}
159
+              </Typography>
168 160
             </Box>
169 161
             <Box
170 162
               display="flex"
@@ -173,7 +165,12 @@ const Cart = () => {
173 165
               sx={{ mb: 2 }}
174 166
             >
175 167
               <Typography variant="body1" sx={{ fontWeight: "400" }}>Taxes</Typography>
176
-              <Typography variant="body1" sx={{ fontWeight: "400" }}>{`RM ${parseFloat(500).toFixed(2)}`}</Typography>
168
+              <Typography variant="body1" sx={{ fontWeight: "400" }}>
169
+                {`
170
+                  ${cart?.cost?.totalTaxAmount?.currencyCode} 
171
+                  ${parseFloat(cart?.cost?.totalTaxAmount?.amount).toFixed(2)}
172
+                `}
173
+              </Typography>
177 174
             </Box>
178 175
             <Box
179 176
               display="flex"
@@ -182,7 +179,12 @@ const Cart = () => {
182 179
               sx={{ mb: 2 }}
183 180
             >
184 181
               <Typography variant="body1" sx={{ fontWeight: "400" }}>Total</Typography>
185
-              <Typography variant="body1" sx={{ fontWeight: "bold" }}>{`RM ${parseFloat(500).toFixed(2)}`}</Typography>
182
+              <Typography variant="body1" sx={{ fontWeight: "bold" }}>
183
+                {`
184
+                  ${cart?.cost?.totalAmount?.currencyCode} 
185
+                  ${parseFloat(cart?.cost?.totalAmount?.amount).toFixed(2)}
186
+                `}
187
+              </Typography>
186 188
             </Box>
187 189
           </Grid>
188 190
 
@@ -190,7 +192,7 @@ const Cart = () => {
190 192
 
191 193
         {/* BUY NOW */}
192 194
         <Box sx={{ mb: 15 }}>
193
-          <Box sx={{ display: "flex", justifyContent: "space-between", alignItems: "center", flexDirection:{xs:"column-reverse", md:"row" } }}>
195
+          <Box sx={{ display: "flex", justifyContent: "space-between", alignItems: "center", flexDirection: { xs: "column-reverse", md: "row" } }}>
194 196
             <Typography variant='body2'><span style={{ fontWeight: "bolder" }}>NEED HELP?</span> CALL US: +44 (0)10 2345 6789 | EMAIL CUSTOMER CARE | SHIPPING INFORMATION | RETURNS & EXCHANGES</Typography>
195 197
             <Button
196 198
               variant="contained"
@@ -203,8 +205,8 @@ const Cart = () => {
203 205
                 px: 8,
204 206
                 py: 2,
205 207
                 mb: {
206
-                  xs:5,
207
-                  md:0
208
+                  xs: 5,
209
+                  md: 0
208 210
                 },
209 211
                 "&:hover": {
210 212
                   backgroundColor: (theme) => theme.palette.grey[900],

+ 9
- 9
src/redux/slices/cartSlice.js Bestand weergeven

@@ -7,7 +7,6 @@ const initialState = {
7 7
   error: null,
8 8
 };
9 9
 
10
-// Async Thunks
11 10
 export const createCart = createAsyncThunk(
12 11
   'cart/createCart',
13 12
   async () => {
@@ -16,11 +15,11 @@ export const createCart = createAsyncThunk(
16 15
   }
17 16
 );
18 17
 
19
-export const addItemToCart = createAsyncThunk(
20
-  'cart/addItemToCart',
21
-  async ({ cartId, lines }, { rejectWithValue }) => {
18
+export const fetchCart = createAsyncThunk(
19
+  'cart/fetchCart',
20
+  async (cartId, { rejectWithValue }) => {
22 21
     try {
23
-      const response = await CartService.addItemToCart(cartId, lines);
22
+      const response = await CartService.getCart(cartId);
24 23
       return response;
25 24
     } catch (error) {
26 25
       return rejectWithValue(error.message);
@@ -28,11 +27,11 @@ export const addItemToCart = createAsyncThunk(
28 27
   }
29 28
 );
30 29
 
31
-export const fetchCart = createAsyncThunk(
32
-  'cart/fetchCart',
33
-  async (cartId, { rejectWithValue }) => {
30
+export const addItemToCart = createAsyncThunk(
31
+  'cart/addItemToCart',
32
+  async ({ cartId, lines }, { rejectWithValue }) => {
34 33
     try {
35
-      const response = await CartService.getCart(cartId);
34
+      const response = await CartService.addItemToCart(cartId, lines);
36 35
       return response;
37 36
     } catch (error) {
38 37
       return rejectWithValue(error.message);
@@ -94,6 +93,7 @@ export const cartSlice = createSlice({
94 93
       })
95 94
       .addCase(addItemToCart.fulfilled, (state, action) => {
96 95
         state.status = 'succeeded';
96
+        localStorage.setItem('amber-cart', JSON.stringify(action.payload));
97 97
         state.cart = action.payload;
98 98
       })
99 99
       .addCase(addItemToCart.rejected, (state, action) => {

+ 84
- 25
src/services/CartService.js Bestand weergeven

@@ -17,10 +17,6 @@ const createCart = async () => {
17 17
           createdAt
18 18
           updatedAt
19 19
         }
20
-        userErrors {
21
-          field
22
-          message
23
-        }
24 20
       }
25 21
     }
26 22
   `;
@@ -30,35 +26,74 @@ const createCart = async () => {
30 26
 
31 27
 // Add a line item to the cart
32 28
 const addItemToCart = async (cartId, lines) => {
29
+
33 30
   const query = `
34
-    mutation AddItemToCart($cartId: ID!, $lines: [CartLineInput!]!) {
31
+    mutation($cartId: ID!, $lines: [CartLineInput!]!) {
35 32
       cartLinesAdd(cartId: $cartId, lines: $lines) {
36 33
         cart {
37 34
           id
35
+          createdAt
36
+          updatedAt
37
+          cost {
38
+            totalAmount {
39
+              amount
40
+              currencyCode
41
+            }
42
+            subtotalAmount {
43
+              amount
44
+              currencyCode
45
+            }
46
+            totalTaxAmount {
47
+              amount
48
+              currencyCode
49
+            }
50
+          }
38 51
           lines(first: 10) {
39
-            edges {
40
-              node {
41
-                id
42
-                quantity
43
-                merchandise {
44
-                  ... on ProductVariant {
45
-                    id
52
+            nodes {
53
+              id
54
+              merchandise {
55
+                ... on ProductVariant {
56
+                  id
57
+                  title
58
+                  selectedOptions {
59
+                    name
60
+                    value
61
+                  }
62
+                  image {
63
+                    src
64
+                  }
65
+                  product {
46 66
                     title
67
+                    collections(first: 5) {
68
+                      nodes {
69
+                        title
70
+                      }
71
+                    }
47 72
                   }
48 73
                 }
49 74
               }
75
+              quantity
76
+              cost {
77
+                totalAmount {
78
+                  amount
79
+                  currencyCode
80
+                }
81
+              }
50 82
             }
51 83
           }
52 84
         }
53
-        userErrors {
54
-          field
55
-          message
56
-        }
57 85
       }
58 86
     }
59 87
   `;
60 88
   const variables = { cartId, lines };
61
-  const { data } = await client.request(query, variables);
89
+
90
+  const {data, errors, extensions} = await client.request(query,{
91
+    variables: {
92
+      cartId,
93
+      lines
94
+    }
95
+  });
96
+  
62 97
   return data.cartLinesAdd.cart;
63 98
 };
64 99
 
@@ -80,22 +115,46 @@ const getCart = async (cartId) => {
80 115
             amount
81 116
             currencyCode
82 117
           }
118
+          totalTaxAmount {
119
+            amount
120
+            currencyCode
121
+          }
83 122
         }
84
-        lines(first: 99) {
85
-          edges {
86
-            node {
87
-              id
88
-              quantity
89
-              merchandise {
90
-                ... on ProductVariant {
91
-                  id
123
+        lines(first: 10) {
124
+          nodes {
125
+            id
126
+            merchandise {
127
+              ... on ProductVariant {
128
+                id
129
+                title
130
+                selectedOptions {
131
+                  name
132
+                  value
133
+                }
134
+                image {
135
+                  src
136
+                }
137
+                product {
92 138
                   title
139
+                  collections(first: 5) {
140
+                    nodes {
141
+                      title
142
+                    }
143
+                  }
93 144
                 }
94 145
               }
95 146
             }
147
+            quantity
148
+            cost {
149
+              totalAmount {
150
+                amount
151
+                currencyCode
152
+              }
153
+            }
96 154
           }
97 155
         }
98 156
       }
157
+        
99 158
     }
100 159
   `;
101 160
 

Laden…
Annuleren
Opslaan