azri 2 veckor sedan
förälder
incheckning
d68655b757

+ 2
- 1
src/components/ProductList/ProductList.jsx Visa fil

@@ -41,6 +41,7 @@ const ProductList = ({ size = 99999 }) => {
41 41
               width: '100%',
42 42
               aspectRatio: '3 / 4',
43 43
               objectFit: 'cover',
44
+              objectPosition:'top center'
44 45
             }}
45 46
           />
46 47
 
@@ -56,7 +57,7 @@ const ProductList = ({ size = 99999 }) => {
56 57
               {title}
57 58
             </Typography>
58 59
             <Typography variant="body" >
59
-              {`${currency} ${price}`}
60
+              {`${currency} ${parseFloat(price).toFixed(2)}`}
60 61
             </Typography>
61 62
             <Typography variant="body2" sx={{ mt: 2 }}>
62 63
               {extra_desc}

+ 77
- 69
src/components/ProductSelected/ProductSelected.jsx Visa fil

@@ -1,84 +1,92 @@
1
-import React from 'react';
1
+import { useEffect } from 'react';
2 2
 import { Box, Typography, Button, useMediaQuery } from '@mui/material';
3 3
 import Grid from '@mui/material/Grid2';
4
+import { useSelector, useDispatch } from 'react-redux';
5
+import { fetchProducts } from '../../redux/slices/productSlice';
4 6
 
5 7
 const ProductSelected = () => {
6 8
 
7
-  const images = [
8
-    {
9
-      url: 'https://via.placeholder.com/300',
10
-      title: 'KEMBOJA IN BEIGE',
11
-      price: 123.90,
12
-      description: "Atma Sari Kurta Raya Collection 2024",
13
-      extra_desc: "or 3 payments of 68.50 MYR with Atome"
14
-    },
15
-    {
16
-      url: 'https://via.placeholder.com/300',
17
-      title: 'KEMBOJA IN BEIGE',
18
-      price: 123.90,
19
-      description: "Atma Sari Kurta Raya Collection 2024",
20
-      extra_desc: "or 3 payments of 68.50 MYR with Atome"
21
-    },
22
-    {
23
-      url: 'https://via.placeholder.com/300',
24
-      title: 'KEMBOJA IN BEIGE',
25
-      price: 123.90,
26
-      description: "Atma Sari Kurta Raya Collection 2024",
27
-      extra_desc: "or 3 payments of 68.50 MYR with Atome"
28
-    },
29
-    {
30
-      url: 'https://via.placeholder.com/300',
31
-      title: 'KEMBOJA IN BEIGE',
32
-      price: 123.90,
33
-      description: "Atma Sari Kurta Raya Collection 2024",
34
-      extra_desc: "or 3 payments of 68.50 MYR with Atome"
35
-    }
36
-  ];
9
+  const products = useSelector((state) => state.products.products.data)
10
+  const dispatch = useDispatch();
11
+
12
+  useEffect(() => {
13
+
14
+    dispatch(fetchProducts())
15
+
16
+  }, [])
17
+
18
+  const renderProduct = (id, img_url, title, collection, price, currency, extra_desc) => {
19
+
20
+    return (
21
+      <Grid item size={{ xs: 6, sm: 6, md: 3 }}>
22
+        <Box
23
+          onClick={() => { window.location.href = `/products/${id}` }}
24
+          sx={{
25
+            overflow: 'hidden',
26
+            position: 'relative',
27
+            cursor: 'pointer'
28
+          }}
29
+
30
+        >
31
+          <img
32
+            src={img_url}
33
+            alt={title}
34
+            style={{
35
+              width: '100%',
36
+              aspectRatio: '3 / 4',
37
+              objectFit: 'cover',
38
+              objectPosition: 'top center'
39
+            }}
40
+          />
41
+
42
+          {/* <Button sx={{ position: "absolute", top: 20, left: 20, boxShadow: 0 }} variant="contained">
43
+            NEW
44
+          </Button> */}
45
+
46
+          <Box sx={{ py: 5 }}>
47
+            <Typography variant="body2" >
48
+              {collection}
49
+            </Typography>
50
+            <Typography variant="h5" sx={{ fontWeight: "bolder" }}>
51
+              {title}
52
+            </Typography>
53
+            <Typography variant="body" >
54
+              {`${currency} ${parseFloat(price).toFixed(2)}`}
55
+            </Typography>
56
+            <Typography variant="body2" sx={{ mt: 2 }}>
57
+              {extra_desc}
58
+            </Typography>
59
+          </Box>
60
+        </Box>
61
+      </Grid>
62
+    )
63
+
64
+  }
65
+
37 66
 
38 67
   const isMobileScreen = useMediaQuery((theme) => theme.breakpoints.down('sm'))
39 68
 
40
-  const displayedImages = isMobileScreen ? images.slice(0, 2) : images;
69
+  const displayedImages = isMobileScreen ? products.slice(0, 2) : products.slice(0, 4);
41 70
 
42 71
   return (
43 72
     <Box sx={{ mb: 5 }}>
44 73
       <Grid container spacing={1} columns={12}>
45
-        {displayedImages.map((image, index) => (<Grid item size={{ xs: 6, md: 3 }} key={index}>
46
-          <Box
47
-            sx={{
48
-              overflow: 'hidden',
49
-              position: 'relative'
50
-            }}
51
-          >
52
-            <img
53
-              src={image.url}
54
-              alt={image.title}
55
-              style={{
56
-                width: '100%',
57
-                aspectRatio: '3 / 4',
58
-                objectFit: 'cover',
59
-              }}
60
-            />
61
-
62
-            {/* <Button sx={{ position: "absolute", top: 20, left: 20, boxShadow: 0 }} variant="contained">
63
-              NEW
64
-            </Button> */}
65
-
66
-            <Box sx={{ py: 5 }}>
67
-              <Typography variant="body2" >
68
-                {image.description}
69
-              </Typography>
70
-              <Typography variant="h5" sx={{ fontWeight: "bolder" }}>
71
-                {image.title}
72
-              </Typography>
73
-              <Typography variant="body" >
74
-                {`RM ${image.price}`}
75
-              </Typography>
76
-              <Typography variant="body2" sx={{ mt: 2 }}>
77
-                {image.extra_desc}
78
-              </Typography>
79
-            </Box>
80
-          </Box>
81
-        </Grid>))}
74
+        {displayedImages.map((product, index) => {
75
+
76
+          let { id, title, compareAtPriceRange, images, collections } = product
77
+          let price = compareAtPriceRange.maxVariantPrice.amount
78
+          let currency = compareAtPriceRange.maxVariantPrice.currencyCode
79
+          let img_url = images.nodes[0].url
80
+          let collection_name = collections.nodes[0]?.title
81
+
82
+          // ID
83
+          const parts = id.split('/');
84
+          let prodID = parts[parts.length - 1];
85
+
86
+
87
+          return renderProduct(prodID, img_url, title, collection_name, price, currency, "")
88
+
89
+        })}
82 90
       </Grid>
83 91
     </Box>
84 92
   );

+ 8
- 4
src/pages/Cart.jsx Visa fil

@@ -96,7 +96,6 @@ const Cart = () => {
96 96
                   <Typography variant='body1'>Variant</Typography>
97 97
                 </TableCell>
98 98
                 <TableCell align='center'>
99
-
100 99
                   <Typography variant='body1'>Quantity</Typography>
101 100
                 </TableCell>
102 101
                 <TableCell align='center'>
@@ -131,15 +130,14 @@ const Cart = () => {
131 130
                         }}
132 131
                       />
133 132
                     </TableCell>
133
+
134 134
                     <TableCell>
135 135
                       <Typography variant='body2' sx={{ fontWeight: "bold", mb: 1 }}>{product.title}</Typography>
136 136
 
137 137
                       {product?.collections?.nodes?.map(({ title }) => (<Typography variant='body2'>{title}</Typography>))}
138 138
 
139 139
                     </TableCell>
140
-                    <TableCell align='center'>
141
-                      <Typography variant='body2' sx={{ fontWeight: "bold" }} >{title}</Typography>
142
-                    </TableCell>
140
+
143 141
                     <TableCell align='center'>
144 142
                       <Box sx={{ display: "flex", justifyContent: "center" }}>
145 143
 
@@ -161,9 +159,15 @@ const Cart = () => {
161 159
 
162 160
                       </Box>
163 161
                     </TableCell>
162
+                    
163
+                    <TableCell align='center'>
164
+                      <Typography variant='body2' sx={{ fontWeight: "bold" }} >{title}</Typography>
165
+                    </TableCell>
166
+
164 167
                     <TableCell align='center'>
165 168
                       <Typography variant='h6' sx={{ fontWeight: "bold" }}>{`${currencyCode} ${parseFloat(amount).toFixed(2)}`}</Typography>
166 169
                     </TableCell>
170
+
167 171
                   </TableRow>
168 172
                 )
169 173
 

Laddar…
Avbryt
Spara