Explorar el Código

add discount price

master
azri hace 1 semana
padre
commit
d6812620b0

+ 20
- 4
src/components/Header/Header.jsx Ver fichero

@@ -2,7 +2,7 @@ import React from 'react';
2 2
 import { createStyles, styled } from '@mui/material/styles';
3 3
 import { Box, Typography, Link } from '@mui/material';
4 4
 import InstagramIcon from '@mui/icons-material/Instagram';
5
-import WhatsAppIcon from '@mui/icons-material/WhatsApp'; 
5
+import WhatsAppIcon from '@mui/icons-material/WhatsApp';
6 6
 
7 7
 const TikTokIcon = ({ color = "#000000" }) => {
8 8
     return (
@@ -32,6 +32,13 @@ const headerStyle = createStyles({
32 32
 
33 33
 const Header = () => {
34 34
 
35
+    const scrollToBottom = () => {
36
+        window.scrollTo({
37
+            top: document.body.scrollHeight,
38
+            behavior: 'smooth',
39
+        });
40
+    };
41
+
35 42
     return (
36 43
         <Container>
37 44
             <Box sx={{ color: "white", px: 6.1 }}>
@@ -39,11 +46,20 @@ const Header = () => {
39 46
                     <WhatsAppIcon sx={{ ":hover": { color: "gray" } }} style={headerStyle.icon} onClick={() => { window.open('https://wa.me/+60172282072', '_blank') }} />
40 47
                     <InstagramIcon sx={{ ":hover": { color: "gray" } }} style={headerStyle.icon} onClick={() => { window.open('https://www.instagram.com/amber.officials/?hl=en', '_blank') }} />
41 48
                     <a onClick={() => { window.open('https://www.tiktok.com/@ambermodeofficial', '_blank') }}>
42
-                    <TikTokIcon color={"#FFF"}/>
49
+                        <TikTokIcon color={"#FFF"} />
43 50
                     </a>
44
-                    
51
+
45 52
                 </Box>
46
-                <Typography variant="body2" sx={{ position: "absolute", top: "50%", left: "50%", transform: "translate(-50%, -50%)" }}>Don’t miss out on our next big thing! Click <a style={{ color: "white", textDecoration: "underline", cursor: 'pointer' }}> here</a> to subcribe now.</Typography>
53
+                <Typography variant="body2" sx={{ position: "absolute", top: "50%", left: "50%", transform: "translate(-50%, -50%)" }}>Don’t miss out on our next big thing! Click  <span
54
+                    onClick={scrollToBottom}
55
+                    style={{
56
+                        color: 'white',
57
+                        textDecoration: 'underline',
58
+                        cursor: 'pointer',
59
+                    }}
60
+                >
61
+                    here
62
+                </span> to subcribe now.</Typography>
47 63
             </Box>
48 64
         </Container>
49 65
     );

+ 16
- 6
src/components/ProductDetails/ProductDetails.jsx Ver fichero

@@ -78,9 +78,15 @@ const ProductDetails = () => {
78 78
         })
79 79
 
80 80
         // find variant price if it all match initial variant selection
81
-        for (const { selectedOptions, price, id, quantityAvailable } of productVariants) {
81
+        for (const { selectedOptions, price, compareAtPrice, id, quantityAvailable } of productVariants) {
82
+
82 83
           let { amount, currencyCode } = price;
83 84
 
85
+          if (compareAtPrice?.amount > 0) {
86
+            amount = compareAtPrice?.amount
87
+            currencyCode = compareAtPrice?.currencyCode
88
+          }
89
+
84 90
           // Convert array to object
85 91
           const optionsObject = selectedOptions.reduce(
86 92
             (a, { name, value }) => ({ ...a, [name]: value }),
@@ -107,8 +113,6 @@ const ProductDetails = () => {
107 113
 
108 114
   const handleVariantClick = (name, value) => {
109 115
 
110
-
111
-
112 116
     setVariantSelection({ ...variantSelection, [name]: value })
113 117
 
114 118
     setVariantSelection((prev) => {
@@ -118,9 +122,15 @@ const ProductDetails = () => {
118 122
       let productVariants = product?.variants
119 123
 
120 124
       // find variant price if it all match initial variant selection
121
-      for (const { selectedOptions, price, id, quantityAvailable } of productVariants) {
125
+      for (const { selectedOptions, price, compareAtPrice, id, quantityAvailable } of productVariants) {
126
+
122 127
         let { amount, currencyCode } = price;
123 128
 
129
+        if (compareAtPrice?.amount > 0) {
130
+          amount = compareAtPrice?.amount
131
+          currencyCode = compareAtPrice?.currencyCode
132
+        }
133
+
124 134
         // Convert array to object
125 135
         const optionsObject = selectedOptions.reduce(
126 136
           (a, { name, value }) => ({ ...a, [name]: value }),
@@ -247,7 +257,7 @@ const ProductDetails = () => {
247 257
                     sm: "0.875rem",
248 258
                     md: "1.1rem",
249 259
                   },
250
-                  mb:1
260
+                  mb: 1
251 261
                 }}>
252 262
                   {name}
253 263
                 </Typography>
@@ -286,7 +296,7 @@ const ProductDetails = () => {
286 296
               sm: "0.875rem",
287 297
               md: "1.1rem",
288 298
             },
289
-            mb:1
299
+            mb: 1
290 300
           }}>
291 301
             Quantity
292 302
           </Typography>

+ 79
- 12
src/components/ProductHistoryList/ProductHistoryList.jsx Ver fichero

@@ -10,12 +10,12 @@ const ProductHistoryList = () => {
10 10
   const products = useSelector((state) => state.products.products.data); // only used as referenced
11 11
   const [filterProducts, setFilterProducts] = useState([])
12 12
 
13
-  useEffect(()=>{ 
13
+  useEffect(() => {
14 14
 
15 15
     if (products.length > 0 && localStorage.getItem('amber-product-history')) {
16 16
 
17 17
       const productHandleList = JSON.parse(localStorage.getItem('amber-product-history')) || []
18
-      const selectedProducts = products.filter(({ handle }) => productHandleList.includes(handle) ) || []
18
+      const selectedProducts = products.filter(({ handle }) => productHandleList.includes(handle)) || []
19 19
 
20 20
       setFilterProducts(selectedProducts)
21 21
 
@@ -23,7 +23,22 @@ const ProductHistoryList = () => {
23 23
 
24 24
   }, [products])
25 25
 
26
-  const renderProduct = (handle, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, extra_desc, selected = false) => {
26
+  const renderProduct = (
27
+    handle,
28
+    img_url,
29
+    title,
30
+    collection_name,
31
+    minPrice,
32
+    minPriceCurrency,
33
+    maxPrice,
34
+    maxPriceCurrency,
35
+    minDiscountPrice,
36
+    minDiscountPriceCurrency,
37
+    maxDiscountPrice,
38
+    maxDiscountPriceCurrency,
39
+    extra_desc,
40
+    selected = false
41
+  ) => {
27 42
 
28 43
     return (
29 44
       <Grid className="animate__animated animate__fadeIn" item size={{ xs: 6, sm: 6, md: 3 }}>
@@ -89,15 +104,34 @@ const ProductHistoryList = () => {
89 104
               }}>
90 105
                 {title}
91 106
               </Typography>
92
-              <Typography variant="body2" sx={{
93
-                fontWeight: "100", fontSize: {
94
-                  xs: "0.73rem",
95
-                  sm: "0.73rem",
96
-                  md: "0.875rem",
97
-                },
98
-              }}>
107
+              <Typography
108
+                variant="body2"
109
+                sx={{
110
+                  fontWeight: "100",
111
+                  fontSize: {
112
+                    xs: "0.73rem",
113
+                    sm: "0.73rem",
114
+                    md: "0.875rem",
115
+                  },
116
+                  textDecoration: (minDiscountPrice > 0) ? "line-through" : "none"
117
+                }}
118
+              >
99 119
                 {`${minPriceCurrency} ${parseFloat(minPrice).toFixed(2)}`}
100 120
               </Typography>
121
+
122
+              {(minDiscountPrice > 0) && <Typography
123
+                variant="body2"
124
+                sx={{
125
+                  fontWeight: "100",
126
+                  fontSize: {
127
+                    xs: "0.73rem",
128
+                    sm: "0.73rem",
129
+                    md: "0.875rem",
130
+                  },
131
+                }}
132
+              >
133
+                {`${minDiscountPriceCurrency} ${parseFloat(minDiscountPrice).toFixed(2)}`}
134
+              </Typography>}
101 135
             </Box>
102 136
           </Box>
103 137
         </a>
@@ -112,17 +146,50 @@ const ProductHistoryList = () => {
112 146
       <Grid container spacing={1} columns={12}>
113 147
         {filterProducts.map((product, index) => {
114 148
 
115
-          let { handle, title, images, collections, minVariantPrice, maxVariantPrice, productType, variants, selected } = product
149
+          let {
150
+            handle,
151
+            title,
152
+            images,
153
+            collections,
154
+            minVariantPrice,
155
+            maxVariantPrice,
156
+            compareAtPriceRangeMinVariantPrice,
157
+            compareAtPriceRangeMaxVariantPrice,
158
+            productType,
159
+            variants,
160
+            selected,
161
+          } = product;
116 162
 
117 163
           let minPrice = minVariantPrice.amount
118 164
           let minPriceCurrency = minVariantPrice.currencyCode
119 165
           let maxPrice = maxVariantPrice.amount
120 166
           let maxPriceCurrency = maxVariantPrice.currencyCode
167
+          // SHOULD BE THE DISCOUNTED PRICE
168
+          let minDiscountPrice = compareAtPriceRangeMinVariantPrice.amount;
169
+          let minDiscountPriceCurrency = compareAtPriceRangeMinVariantPrice.currencyCode;
170
+          let maxDiscountPrice = compareAtPriceRangeMaxVariantPrice.amount;
171
+          let maxDiscountPriceCurrency = compareAtPriceRangeMaxVariantPrice.currencyCode;
172
+
121 173
           let img_url = images[0]?.url || defaultImage
122 174
           let collection_name = collections[0]?.title
123 175
 
124 176
           if (index < 4) {
125
-            return renderProduct(handle, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, "", selected)
177
+            return renderProduct(
178
+              handle,
179
+              img_url,
180
+              title,
181
+              collection_name,
182
+              minPrice,
183
+              minPriceCurrency,
184
+              maxPrice,
185
+              maxPriceCurrency,
186
+              minDiscountPrice,
187
+              minDiscountPriceCurrency,
188
+              maxDiscountPrice,
189
+              maxDiscountPriceCurrency,
190
+              "",
191
+              selected
192
+            );
126 193
           }
127 194
 
128 195
         })}

+ 35
- 0
src/components/ProductList/ProductList.jsx Ver fichero

@@ -173,9 +173,14 @@ const ProductList = ({ size = 99999 }) => {
173 173
     minPriceCurrency,
174 174
     maxPrice,
175 175
     maxPriceCurrency,
176
+    minDiscountPrice,
177
+    minDiscountPriceCurrency,
178
+    maxDiscountPrice,
179
+    maxDiscountPriceCurrency,
176 180
     extra_desc,
177 181
     selected = false
178 182
   ) => {
183
+
179 184
     return (
180 185
       <Grid
181 186
         className="animate__animated animate__fadeIn"
@@ -255,6 +260,7 @@ const ProductList = ({ size = 99999 }) => {
255 260
             >
256 261
               {title}
257 262
             </Typography>
263
+
258 264
             <Typography
259 265
               variant="body2"
260 266
               sx={{
@@ -264,10 +270,27 @@ const ProductList = ({ size = 99999 }) => {
264 270
                   sm: "0.73rem",
265 271
                   md: "0.875rem",
266 272
                 },
273
+                textDecoration: (minDiscountPrice > 0) ? "line-through" : "none"
267 274
               }}
268 275
             >
269 276
               {`${minPriceCurrency} ${parseFloat(minPrice).toFixed(2)}`}
270 277
             </Typography>
278
+
279
+            {(minDiscountPrice > 0) && <Typography
280
+              variant="body2"
281
+              sx={{
282
+                fontWeight: "100",
283
+                fontSize: {
284
+                  xs: "0.73rem",
285
+                  sm: "0.73rem",
286
+                  md: "0.875rem",
287
+                },
288
+              }}
289
+            >
290
+              {`${minDiscountPriceCurrency} ${parseFloat(minDiscountPrice).toFixed(2)}`}
291
+            </Typography>}
292
+            
293
+
271 294
           </Box>
272 295
         </Box>
273 296
       </Grid>
@@ -421,6 +444,8 @@ const ProductList = ({ size = 99999 }) => {
421 444
               collections,
422 445
               minVariantPrice,
423 446
               maxVariantPrice,
447
+              compareAtPriceRangeMinVariantPrice,
448
+              compareAtPriceRangeMaxVariantPrice,
424 449
               productType,
425 450
               variants,
426 451
               selected,
@@ -430,6 +455,12 @@ const ProductList = ({ size = 99999 }) => {
430 455
             let minPriceCurrency = minVariantPrice.currencyCode;
431 456
             let maxPrice = maxVariantPrice.amount;
432 457
             let maxPriceCurrency = maxVariantPrice.currencyCode;
458
+            // SHOULD BE THE DISCOUNTED PRICE
459
+            let minDiscountPrice = compareAtPriceRangeMinVariantPrice.amount;
460
+            let minDiscountPriceCurrency = compareAtPriceRangeMinVariantPrice.currencyCode;
461
+            let maxDiscountPrice = compareAtPriceRangeMaxVariantPrice.amount;
462
+            let maxDiscountPriceCurrency = compareAtPriceRangeMaxVariantPrice.currencyCode;
463
+
433 464
             let img_url = images[0]?.url || defaultImage;
434 465
             let collection_name = collections[0]?.title;
435 466
 
@@ -443,6 +474,10 @@ const ProductList = ({ size = 99999 }) => {
443 474
                 minPriceCurrency,
444 475
                 maxPrice,
445 476
                 maxPriceCurrency,
477
+                minDiscountPrice,
478
+                minDiscountPriceCurrency,
479
+                maxDiscountPrice,
480
+                maxDiscountPriceCurrency,
446 481
                 "",
447 482
                 selected
448 483
               );

+ 77
- 11
src/components/ProductSelected/ProductSelected.jsx Ver fichero

@@ -45,7 +45,22 @@ const ProductSelected = () => {
45 45
   };
46 46
 
47 47
 
48
-  const renderProduct = (handle, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, extra_desc) => {
48
+  const renderProduct = (
49
+    handle,
50
+    img_url,
51
+    title,
52
+    collection_name,
53
+    minPrice,
54
+    minPriceCurrency,
55
+    maxPrice,
56
+    maxPriceCurrency,
57
+    minDiscountPrice,
58
+    minDiscountPriceCurrency,
59
+    maxDiscountPrice,
60
+    maxDiscountPriceCurrency,
61
+    extra_desc,
62
+    selected = false
63
+  ) => {
49 64
 
50 65
     return (
51 66
       <Grid item size={{ xs: 6, sm: 6, md: 3 }}>
@@ -116,15 +131,34 @@ const ProductSelected = () => {
116 131
               }}>
117 132
                 {title}
118 133
               </Typography>
119
-              <Typography variant="body2" sx={{
120
-                fontWeight: "100", fontSize: {
121
-                  xs: "0.73rem",
122
-                  sm: "0.73rem",
123
-                  md: "0.875rem",
124
-                },
125
-              }}>
134
+              <Typography
135
+                variant="body2"
136
+                sx={{
137
+                  fontWeight: "100",
138
+                  fontSize: {
139
+                    xs: "0.73rem",
140
+                    sm: "0.73rem",
141
+                    md: "0.875rem",
142
+                  },
143
+                  textDecoration: (minDiscountPrice > 0) ? "line-through" : "none"
144
+                }}
145
+              >
126 146
                 {`${minPriceCurrency} ${parseFloat(minPrice).toFixed(2)}`}
127 147
               </Typography>
148
+
149
+              {(minDiscountPrice > 0) && <Typography
150
+                variant="body2"
151
+                sx={{
152
+                  fontWeight: "100",
153
+                  fontSize: {
154
+                    xs: "0.73rem",
155
+                    sm: "0.73rem",
156
+                    md: "0.875rem",
157
+                  },
158
+                }}
159
+              >
160
+                {`${minDiscountPriceCurrency} ${parseFloat(minDiscountPrice).toFixed(2)}`}
161
+              </Typography>}
128 162
             </Box>
129 163
           </Box>
130 164
         </a>
@@ -161,7 +195,7 @@ const ProductSelected = () => {
161 195
           }}
162 196
           onClick={swipeToLeft}
163 197
         />
164
-        <Typography variant="h4" sx={{ mx: 2, fontWeight:"50" }}>
198
+        <Typography variant="h4" sx={{ mx: 2, fontWeight: "50" }}>
165 199
           NEW IN
166 200
         </Typography>
167 201
 
@@ -189,19 +223,51 @@ const ProductSelected = () => {
189 223
         >
190 224
           {filterProducts.map((product, index) => {
191 225
 
192
-            let { handle, title, images, collections, minVariantPrice, maxVariantPrice, productType, variants } = product
226
+            let {
227
+              handle,
228
+              title,
229
+              images,
230
+              collections,
231
+              minVariantPrice,
232
+              maxVariantPrice,
233
+              compareAtPriceRangeMinVariantPrice,
234
+              compareAtPriceRangeMaxVariantPrice,
235
+              productType,
236
+              variants,
237
+              selected,
238
+            } = product;
193 239
 
194 240
             let minPrice = minVariantPrice.amount
195 241
             let minPriceCurrency = minVariantPrice.currencyCode
196 242
             let maxPrice = maxVariantPrice.amount
197 243
             let maxPriceCurrency = maxVariantPrice.currencyCode
244
+            // SHOULD BE THE DISCOUNTED PRICE
245
+            let minDiscountPrice = compareAtPriceRangeMinVariantPrice.amount;
246
+            let minDiscountPriceCurrency = compareAtPriceRangeMinVariantPrice.currencyCode;
247
+            let maxDiscountPrice = compareAtPriceRangeMaxVariantPrice.amount;
248
+            let maxDiscountPriceCurrency = compareAtPriceRangeMaxVariantPrice.currencyCode;
198 249
 
199 250
             let img_url = images[0]?.url || defaultImage
200 251
             let collection_name = collections[0]?.title
201 252
 
202 253
             return (
203 254
               <SwiperSlide>
204
-                {renderProduct(handle, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, "")}
255
+                {renderProduct(
256
+                  handle,
257
+                  img_url,
258
+                  title,
259
+                  collection_name,
260
+                  minPrice,
261
+                  minPriceCurrency,
262
+                  maxPrice,
263
+                  maxPriceCurrency,
264
+                  minDiscountPrice,
265
+                  minDiscountPriceCurrency,
266
+                  maxDiscountPrice,
267
+                  maxDiscountPriceCurrency,
268
+                  "",
269
+                  selected
270
+                )}
205 271
               </SwiperSlide>
206 272
             )
207 273
 

+ 31
- 0
src/components/ProductSuggestion/ProductSuggestion.jsx Ver fichero

@@ -33,6 +33,10 @@ const ProductSuggestion = () => {
33 33
     minPriceCurrency,
34 34
     maxPrice,
35 35
     maxPriceCurrency,
36
+    minDiscountPrice,
37
+    minDiscountPriceCurrency,
38
+    maxDiscountPrice,
39
+    maxDiscountPriceCurrency,
36 40
     extra_desc,
37 41
     selected = false
38 42
   ) => {
@@ -125,10 +129,25 @@ const ProductSuggestion = () => {
125 129
                     sm: "0.73rem",
126 130
                     md: "0.875rem",
127 131
                   },
132
+                  textDecoration: (minDiscountPrice > 0) ? "line-through" : "none"
128 133
                 }}
129 134
               >
130 135
                 {`${minPriceCurrency} ${parseFloat(minPrice).toFixed(2)}`}
131 136
               </Typography>
137
+
138
+              {(minDiscountPrice > 0) && <Typography
139
+                variant="body2"
140
+                sx={{
141
+                  fontWeight: "100",
142
+                  fontSize: {
143
+                    xs: "0.73rem",
144
+                    sm: "0.73rem",
145
+                    md: "0.875rem",
146
+                  },
147
+                }}
148
+              >
149
+                {`${minDiscountPriceCurrency} ${parseFloat(minDiscountPrice).toFixed(2)}`}
150
+              </Typography>}
132 151
             </Box>
133 152
           </Box>
134 153
         </a>
@@ -149,6 +168,8 @@ const ProductSuggestion = () => {
149 168
             collections,
150 169
             minVariantPrice,
151 170
             maxVariantPrice,
171
+            compareAtPriceRangeMinVariantPrice,
172
+            compareAtPriceRangeMaxVariantPrice,
152 173
             productType,
153 174
             variants,
154 175
             selected,
@@ -158,6 +179,12 @@ const ProductSuggestion = () => {
158 179
           let minPriceCurrency = minVariantPrice.currencyCode;
159 180
           let maxPrice = maxVariantPrice.amount;
160 181
           let maxPriceCurrency = maxVariantPrice.currencyCode;
182
+          // SHOULD BE THE DISCOUNTED PRICE
183
+          let minDiscountPrice = compareAtPriceRangeMinVariantPrice.amount;
184
+          let minDiscountPriceCurrency = compareAtPriceRangeMinVariantPrice.currencyCode;
185
+          let maxDiscountPrice = compareAtPriceRangeMaxVariantPrice.amount;
186
+          let maxDiscountPriceCurrency = compareAtPriceRangeMaxVariantPrice.currencyCode;
187
+
161 188
           let img_url = images[0]?.url || defaultImage
162 189
           let collection_name = collections[0]?.title;
163 190
 
@@ -170,6 +197,10 @@ const ProductSuggestion = () => {
170 197
             minPriceCurrency,
171 198
             maxPrice,
172 199
             maxPriceCurrency,
200
+            minDiscountPrice,
201
+            minDiscountPriceCurrency,
202
+            maxDiscountPrice,
203
+            maxDiscountPriceCurrency,
173 204
             "",
174 205
             selected
175 206
           );

+ 14
- 0
src/services/ProductService.js Ver fichero

@@ -35,6 +35,16 @@ const getProducts = async () => {
35 35
               currencyCode
36 36
             }
37 37
           }
38
+          compareAtPriceRange {
39
+            maxVariantPrice {
40
+              currencyCode
41
+              amount
42
+            }
43
+            minVariantPrice {
44
+              amount
45
+              currencyCode
46
+            }
47
+          }
38 48
           images(first: 4) {
39 49
             nodes {
40 50
               url
@@ -143,6 +153,10 @@ const getProduct = async (handle = "") => {
143 153
             value
144 154
           }
145 155
           quantityAvailable
156
+          compareAtPrice {
157
+            currencyCode
158
+            amount
159
+          }
146 160
         }
147 161
       }
148 162
       metafield(key: "selected", namespace: "custom") {

+ 5
- 2
src/utils/helpers.js Ver fichero

@@ -4,7 +4,7 @@
4 4
 export const formatProductData = (product) => {
5 5
 
6 6
     if(!product) return
7
-
7
+    
8 8
     return {
9 9
         id: product?.id || null,
10 10
         handle: product?.handle || "",
@@ -17,8 +17,11 @@ export const formatProductData = (product) => {
17 17
         selected: (product?.metafield?.key == "selected") ? product?.metafield?.value == "true" : false, // cause I want to have a true false value, somehow BE return text value "true", thus == used to convert it to proper boolean value
18 18
         minVariantPrice: product?.priceRange?.minVariantPrice || {amount:0 , currencyCode:''},
19 19
         maxVariantPrice: product?.priceRange?.maxVariantPrice || {amount:0 , currencyCode:''},
20
+        compareAtPriceRangeMinVariantPrice: product?.compareAtPriceRange?.minVariantPrice || {amount:0 , currencyCode:''},
21
+        compareAtPriceRangeMaxVariantPrice: product?.compareAtPriceRange?.maxVariantPrice || {amount:0 , currencyCode:''},
20 22
         productType: product?.productType || null,
21
-        variants: product?.variants?.nodes || null
23
+        variants: product?.variants?.nodes || null,
24
+        
22 25
     }
23 26
 
24 27
 }

Loading…
Cancelar
Guardar