Browse Source

feat module 1,2,4 : product suggestion display based on menu

master
nadia 1 day ago
parent
commit
ffd17a6095
1 changed files with 4 additions and 15 deletions
  1. 4
    15
      src/components/ProductSuggestion/ProductSuggestion.jsx

+ 4
- 15
src/components/ProductSuggestion/ProductSuggestion.jsx View File

@@ -4,21 +4,10 @@ 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';
7
+import { isProductInVisibleMenu } from '../../config/menuCollections';
8 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
-};
9
+// const allowedSuggestionCollections = getMenuCollectionTitlesByProductType();
10
+// const isProductAllowedInSuggestion = (product) => { ... };
22 11
 
23 12
 const ProductSuggestion = () => {
24 13
 
@@ -34,7 +23,7 @@ const ProductSuggestion = () => {
34 23
         return shuffled.slice(0, num);
35 24
       };
36 25
 
37
-      const visibleProducts = products.filter(isProductAllowedInSuggestion);
26
+      const visibleProducts = products.filter((product) => isProductInVisibleMenu(product, products));
38 27
       // const randomProducts = getRandomProducts(products, 4);
39 28
       const randomProducts = getRandomProducts(visibleProducts, 4); // Select 4 random visible products
40 29
       setSuggestProducts(randomProducts);

Loading…
Cancel
Save