|
|
@@ -4,6 +4,21 @@ import { useSelector } from 'react-redux';
|
|
4
|
4
|
import Grid from '@mui/material/Grid2';
|
|
5
|
5
|
import { useNavigate } from "react-router-dom";
|
|
6
|
6
|
import defaultImage from "../../assets/images/default.png"
|
|
|
7
|
+import { getMenuCollectionTitlesByProductType } from '../../config/menuCollections';
|
|
|
8
|
+
|
|
|
9
|
+const normalizeTitle = (title = "") => title.trim().toUpperCase();
|
|
|
10
|
+
|
|
|
11
|
+const allowedSuggestionCollections = getMenuCollectionTitlesByProductType();
|
|
|
12
|
+
|
|
|
13
|
+// Function to check if a product is allowed in the suggestion based on its collections
|
|
|
14
|
+const isProductAllowedInSuggestion = (product) => {
|
|
|
15
|
+ const allowedCollections = allowedSuggestionCollections[product?.productType] || [];
|
|
|
16
|
+ const normalizedAllowedCollections = allowedCollections.map(normalizeTitle);
|
|
|
17
|
+
|
|
|
18
|
+ return product?.collections?.some((collection) =>
|
|
|
19
|
+ normalizedAllowedCollections.includes(normalizeTitle(collection?.title))
|
|
|
20
|
+ );
|
|
|
21
|
+};
|
|
7
|
22
|
|
|
8
|
23
|
const ProductSuggestion = () => {
|
|
9
|
24
|
|
|
|
@@ -19,7 +34,9 @@ const ProductSuggestion = () => {
|
|
19
|
34
|
return shuffled.slice(0, num);
|
|
20
|
35
|
};
|
|
21
|
36
|
|
|
22
|
|
- const randomProducts = getRandomProducts(products, 4); // Select 4 random elements
|
|
|
37
|
+ const visibleProducts = products.filter(isProductAllowedInSuggestion);
|
|
|
38
|
+ // const randomProducts = getRandomProducts(products, 4);
|
|
|
39
|
+ const randomProducts = getRandomProducts(visibleProducts, 4); // Select 4 random visible products
|
|
23
|
40
|
setSuggestProducts(randomProducts);
|
|
24
|
41
|
}
|
|
25
|
42
|
}, [products]);
|
|
|
@@ -170,8 +187,9 @@ const ProductSuggestion = () => {
|
|
170
|
187
|
maxVariantPrice,
|
|
171
|
188
|
compareAtPriceRangeMinVariantPrice,
|
|
172
|
189
|
compareAtPriceRangeMaxVariantPrice,
|
|
173
|
|
- productType,
|
|
174
|
|
- variants,
|
|
|
190
|
+ // productType and variants are not needed here because filtering already happens before rendering.
|
|
|
191
|
+ // productType,
|
|
|
192
|
+ // variants,
|
|
175
|
193
|
selected,
|
|
176
|
194
|
} = product;
|
|
177
|
195
|
|