瀏覽代碼

fix product selected link

master
azri 1 周之前
父節點
當前提交
7d9ef2b26b
共有 1 個文件被更改,包括 47 次插入46 次删除
  1. 47
    46
      src/components/ProductSelected/ProductSelected.jsx

+ 47
- 46
src/components/ProductSelected/ProductSelected.jsx 查看文件

@@ -38,50 +38,55 @@ const ProductSelected = () => {
38 38
   };
39 39
 
40 40
 
41
-  const renderProduct = (id, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, extra_desc) => {
41
+  const renderProduct = (handle, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, extra_desc) => {
42 42
 
43 43
     return (
44 44
       <Grid item size={{ xs: 6, sm: 6, md: 3 }}>
45
-
46
-        <Box
47
-          onClick={() => { window.location.href = `/products/${id}` }}
48
-          sx={{
49
-            overflow: 'hidden',
50
-            position: 'relative',
51
-            cursor: 'pointer'
52
-          }}
53
-
54
-        >
55
-          <img
56
-            src={img_url}
57
-            alt={title}
58
-            style={{
59
-              width: '100%',
60
-              aspectRatio: '3 / 4',
61
-              objectFit: 'cover',
62
-              objectPosition: 'top center'
45
+        <a
46
+          href={`/products/${handle}`}
47
+          style={{
48
+            color: 'black',
49
+            textDecoration: 'none'
50
+          }}>
51
+          <Box
52
+            sx={{
53
+              overflow: 'hidden',
54
+              position: 'relative',
55
+              cursor: 'pointer',
63 56
             }}
64
-          />
65 57
 
66
-          {/* <Button sx={{ position: "absolute", top: 20, left: 20, boxShadow: 0 }} variant="contained">
58
+          >
59
+            <img
60
+              src={img_url}
61
+              alt={title}
62
+              style={{
63
+                width: '100%',
64
+                aspectRatio: '3 / 4',
65
+                objectFit: 'cover',
66
+                objectPosition: 'top center'
67
+              }}
68
+            />
69
+
70
+            {/* <Button sx={{ position: "absolute", top: 20, left: 20, boxShadow: 0 }} variant="contained">
67 71
             NEW
68 72
           </Button> */}
69 73
 
70
-          <Box sx={{ pb: 5, pt: 3 }}>
71
-            <Typography variant="body1" sx={{ fontWeight: "400", mb: 1 }}>
72
-              {collection_name}
73
-            </Typography>
74
-            <Typography variant="h5" sx={{ fontWeight: "bolder", mb: 1 }}>
75
-              {title}
76
-            </Typography>
77
-            <Typography variant="body1" sx={{ fontWeight: "400" }}>
78
-              {`${minPriceCurrency} ${parseFloat(minPrice).toFixed(2)}`}
79
-            </Typography>
80
-            <Typography variant="body1" sx={{ mt: 2 }}>
81
-              {extra_desc}
82
-            </Typography>
74
+            <Box sx={{ pb: 5, pt: 3 }}>
75
+              <Typography variant="body1" sx={{ fontWeight: "400", mb: 1 }}>
76
+                {collection_name}
77
+              </Typography>
78
+              <Typography variant="h5" sx={{ fontWeight: "bolder", mb: 1 }}>
79
+                {title}
80
+              </Typography>
81
+              <Typography variant="body1" sx={{ fontWeight: "400" }}>
82
+                {`${minPriceCurrency} ${parseFloat(minPrice).toFixed(2)}`}
83
+              </Typography>
84
+              <Typography variant="body1" sx={{ mt: 2 }}>
85
+                {extra_desc}
86
+              </Typography>
87
+            </Box>
83 88
           </Box>
84
-        </Box>
89
+        </a>
85 90
       </Grid>
86 91
     )
87 92
 
@@ -97,19 +102,19 @@ const ProductSelected = () => {
97 102
       <Grid size={{ xs: 12, md: 4 }} sx={{ mx: "auto", display: "flex", alignItems: "center", justifyContent: "center", my: 4 }}>
98 103
         <ChevronLeftIcon
99 104
           style={{
100
-            cursor:"pointer",
101
-            color:"#B7B7B7"
105
+            cursor: "pointer",
106
+            color: "#B7B7B7"
102 107
           }}
103 108
           onClick={swipeToLeft}
104 109
         />
105
-        <Typography variant="h4" sx={{mx:2}}>
110
+        <Typography variant="h4" sx={{ mx: 2 }}>
106 111
           NEW IN
107 112
         </Typography>
108 113
 
109 114
         <KeyboardArrowRightIcon
110 115
           style={{
111
-            cursor:"pointer",
112
-            color:"#B7B7B7"
116
+            cursor: "pointer",
117
+            color: "#B7B7B7"
113 118
           }}
114 119
           onClick={swipeToRight}
115 120
         />
@@ -129,7 +134,7 @@ const ProductSelected = () => {
129 134
       >
130 135
         {filterProducts.map((product, index) => {
131 136
 
132
-          let { id, title, images, collections, minVariantPrice, maxVariantPrice, productType, variants } = product
137
+          let { handle, title, images, collections, minVariantPrice, maxVariantPrice, productType, variants } = product
133 138
 
134 139
           let minPrice = minVariantPrice.amount
135 140
           let minPriceCurrency = minVariantPrice.currencyCode
@@ -139,13 +144,9 @@ const ProductSelected = () => {
139 144
           let img_url = images[0]?.url
140 145
           let collection_name = collections[0]?.title
141 146
 
142
-          // ID
143
-          const parts = id.split('/');
144
-          let prodID = parts[parts.length - 1];
145
-
146 147
           return (
147 148
             <SwiperSlide>
148
-              {renderProduct(prodID, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, "")}
149
+              {renderProduct(handle, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, "")}
149 150
             </SwiperSlide>
150 151
           )
151 152
 

Loading…
取消
儲存