Преглед изворни кода

feat module 1,2,4 : sort child menu items by latest product updated

master
nadia пре 1 дан
родитељ
комит
a17ea89d5a
3 измењених фајлова са 28 додато и 3 уклоњено
  1. 26
    3
      src/config/menuCollections.js
  2. 1
    0
      src/services/ProductService.js
  3. 1
    0
      src/utils/helpers.js

+ 26
- 3
src/config/menuCollections.js Прегледај датотеку

107
         menuCollections[productType][menuGroup].set(key, {
107
         menuCollections[productType][menuGroup].set(key, {
108
           ...collection,
108
           ...collection,
109
           menuGroup,
109
           menuGroup,
110
+          latestProductUpdatedAt: product?.updatedAt || product?.createdAt || null,
110
         });
111
         });
112
+      } else {
113
+        const existingCollection = menuCollections[productType][menuGroup].get(key);
114
+        const existingUpdatedAt = existingCollection?.latestProductUpdatedAt
115
+          ? Date.parse(existingCollection.latestProductUpdatedAt)
116
+          : 0;
117
+        const productUpdatedAt = product?.updatedAt || product?.createdAt || null;
118
+        const productUpdatedAtTime = productUpdatedAt ? Date.parse(productUpdatedAt) : 0;
119
+
120
+        if (productUpdatedAtTime > existingUpdatedAt) {
121
+          menuCollections[productType][menuGroup].set(key, {
122
+            ...existingCollection,
123
+            latestProductUpdatedAt: productUpdatedAt,
124
+          });
125
+        }
111
       }
126
       }
112
     });
127
     });
113
 
128
 
123
   collection,
138
   collection,
124
 });
139
 });
125
 
140
 
126
-// Utility function to sort collections by their updatedAt timestamp, with a fallback to title comparison
141
+// Utility function to sort collections by their latest product update timestamp, with collection updatedAt and title fallbacks
127
 const sortCollectionsByNewest = (collections = []) => (
142
 const sortCollectionsByNewest = (collections = []) => (
128
   [...collections].sort((a, b) => {
143
   [...collections].sort((a, b) => {
129
-    const aUpdatedAt = a?.updatedAt ? Date.parse(a.updatedAt) : 0;
130
-    const bUpdatedAt = b?.updatedAt ? Date.parse(b.updatedAt) : 0;
144
+    const aUpdatedAt = a?.latestProductUpdatedAt
145
+      ? Date.parse(a.latestProductUpdatedAt)
146
+      : a?.updatedAt
147
+        ? Date.parse(a.updatedAt)
148
+        : 0;
149
+    const bUpdatedAt = b?.latestProductUpdatedAt
150
+      ? Date.parse(b.latestProductUpdatedAt)
151
+      : b?.updatedAt
152
+        ? Date.parse(b.updatedAt)
153
+        : 0;
131
 
154
 
132
     if (aUpdatedAt !== bUpdatedAt) {
155
     if (aUpdatedAt !== bUpdatedAt) {
133
       return bUpdatedAt - aUpdatedAt;
156
       return bUpdatedAt - aUpdatedAt;

+ 1
- 0
src/services/ProductService.js Прегледај датотеку

23
           handle
23
           handle
24
           title
24
           title
25
           createdAt 
25
           createdAt 
26
+          updatedAt
26
           productType
27
           productType
27
           tags
28
           tags
28
           priceRange {
29
           priceRange {

+ 1
- 0
src/utils/helpers.js Прегледај датотеку

20
         handle: product?.handle || "",
20
         handle: product?.handle || "",
21
         title: product?.title || "",
21
         title: product?.title || "",
22
         createdAt: publishedDate || product?.createdAt,
22
         createdAt: publishedDate || product?.createdAt,
23
+        updatedAt: product?.updatedAt || product?.createdAt,
23
         collections: product?.collections?.nodes || null,
24
         collections: product?.collections?.nodes || null,
24
         descriptionHtml: product?.descriptionHtml || "",
25
         descriptionHtml: product?.descriptionHtml || "",
25
         tags:product?.tags || null,
26
         tags:product?.tags || null,

Loading…
Откажи
Сачувај