@@ -98,6 +98,27 @@ const formatSuggestions = (searchSuggestions) => {
9898 }
9999 }
100100 ) ,
101+ // Einstein suggestions for popular and recent searches
102+ popularSearchSuggestions : searchSuggestions ?. einsteinSuggestions ?. popularSearchPhrases ?. map (
103+ ( phrase ) => {
104+ return {
105+ type : 'popular' ,
106+ name : phrase . phrase ,
107+ link : searchUrlBuilder ( phrase . phrase ) ,
108+ exactMatch : phrase . exactMatch
109+ }
110+ }
111+ ) ,
112+ recentSearchSuggestions : searchSuggestions ?. einsteinSuggestions ?. recentSearchPhrases ?. map (
113+ ( phrase ) => {
114+ return {
115+ type : 'recent' ,
116+ name : phrase . phrase ,
117+ link : searchUrlBuilder ( phrase . phrase ) ,
118+ exactMatch : phrase . exactMatch
119+ }
120+ }
121+ ) ,
101122 searchPhrase : searchSuggestions ?. searchPhrase
102123 }
103124}
@@ -130,17 +151,169 @@ const Search = (props) => {
130151 const [ searchQuery , setSearchQuery ] = useState ( '' )
131152 const navigate = useNavigation ( )
132153
133- const searchSuggestion = useSearchSuggestions (
134- {
135- parameters : {
136- q : searchQuery ,
137- expand : 'images,prices'
138- }
154+ // Mock Einstein suggestions data
155+ const mockEinsteinSuggestions = {
156+ "brandSuggestions" : {
157+ "suggestedTerms" : [
158+ {
159+ "originalTerm" : "dress"
160+ }
161+ ]
139162 } ,
140- {
141- enabled : searchQuery ?. length >= RECENT_SEARCH_MIN_LENGTH
142- }
143- )
163+ "einsteinSuggestions" : {
164+ "popularSearchPhrases" : [
165+ {
166+ "exactMatch" : false ,
167+ "phrase" : "Dresses"
168+ }
169+ ] ,
170+ "recentSearchPhrases" : [
171+ {
172+ "exactMatch" : false ,
173+ "phrase" : "Dresses"
174+ }
175+ ]
176+ } ,
177+ "categorySuggestions" : {
178+ "categories" : [
179+ {
180+ "id" : "womens-clothing-dresses" ,
181+ "name" : "Dresses" ,
182+ "parentCategoryName" : "Clothing"
183+ }
184+ ] ,
185+ "suggestedPhrases" : [
186+ {
187+ "exactMatch" : false ,
188+ "phrase" : "Dresses"
189+ }
190+ ] ,
191+ "suggestedTerms" : [
192+ {
193+ "originalTerm" : "dress" ,
194+ "terms" : [
195+ {
196+ "completed" : false ,
197+ "corrected" : false ,
198+ "exactMatch" : true ,
199+ "value" : "dress"
200+ }
201+ ]
202+ }
203+ ]
204+ } ,
205+ "contentSuggestions" : {
206+ "suggestedTerms" : [
207+ {
208+ "originalTerm" : "dress"
209+ }
210+ ]
211+ } ,
212+ "customSuggestions" : {
213+ "suggestedPhrases" : [
214+ {
215+ "exactMatch" : false ,
216+ "phrase" : "Dresses"
217+ }
218+ ] ,
219+ "suggestedTerms" : [
220+ {
221+ "originalTerm" : "dress" ,
222+ "terms" : [
223+ {
224+ "completed" : false ,
225+ "corrected" : false ,
226+ "exactMatch" : true ,
227+ "value" : "dress"
228+ }
229+ ]
230+ }
231+ ]
232+ } ,
233+ "productSuggestions" : {
234+ "products" : [
235+ {
236+ "currency" : "GBP" ,
237+ "productId" : "A Standard Dress-1" ,
238+ "productName" : "A Standard Dress"
239+ } ,
240+ {
241+ "currency" : "GBP" ,
242+ "image" : {
243+ "alt" : "Floral Dress, , small" ,
244+ "disBaseLink" : "https://edge.disstg.commercecloud.salesforce.com/dw/image/v2/ZZRF_001/on/demandware.static/-/Sites-apparel-m-catalog/default/dw17dc4593/images/small/PG.10237222.JJB52A0.PZ.jpg" ,
245+ "link" : "https://zzrf-001.dx.commercecloud.salesforce.com/on/demandware.static/-/Sites-apparel-m-catalog/default/dw17dc4593/images/small/PG.10237222.JJB52A0.PZ.jpg" ,
246+ "title" : "Floral Dress, "
247+ } ,
248+ "price" : 82.56 ,
249+ "productId" : "25592581M" ,
250+ "productName" : "Floral Dress"
251+ } ,
252+ {
253+ "currency" : "GBP" ,
254+ "image" : {
255+ "alt" : "Pack-And-Go Dress, , small" ,
256+ "disBaseLink" : "https://edge.disstg.commercecloud.salesforce.com/dw/image/v2/ZZRF_001/on/demandware.static/-/Sites-apparel-m-catalog/default/dwb331c78d/images/small/PG.10239018.JJ3WCXX.PZ.jpg" ,
257+ "link" : "https://zzrf-001.dx.commercecloud.salesforce.com/on/demandware.static/-/Sites-apparel-m-catalog/default/dwb331c78d/images/small/PG.10239018.JJ3WCXX.PZ.jpg" ,
258+ "title" : "Pack-And-Go Dress, "
259+ } ,
260+ "price" : 82.56 ,
261+ "productId" : "25589753M" ,
262+ "productName" : "Pack-And-Go Dress"
263+ } ,
264+ {
265+ "currency" : "GBP" ,
266+ "image" : {
267+ "alt" : "V-Neck Dress, , small" ,
268+ "disBaseLink" : "https://edge.disstg.commercecloud.salesforce.com/dw/image/v2/ZZRF_001/on/demandware.static/-/Sites-apparel-m-catalog/default/dwf295eccb/images/small/PG.10229762.JJ169XX.PZ.jpg" ,
269+ "link" : "https://zzrf-001.dx.commercecloud.salesforce.com/on/demandware.static/-/Sites-apparel-m-catalog/default/dwf295eccb/images/small/PG.10229762.JJ169XX.PZ.jpg" ,
270+ "title" : "V-Neck Dress, "
271+ } ,
272+ "price" : 75.52 ,
273+ "productId" : "25593727M" ,
274+ "productName" : "V-Neck Dress"
275+ } ,
276+ {
277+ "currency" : "GBP" ,
278+ "image" : {
279+ "alt" : "Neutral Floral Dress, , small" ,
280+ "disBaseLink" : "https://edge.disstg.commercecloud.salesforce.com/dw/image/v2/ZZRF_001/on/demandware.static/-/Sites-apparel-m-catalog/default/dw0db45f1c/images/small/PG.10227905.JJ0KMXX.PZ.jpg" ,
281+ "link" : "https://zzrf-001.dx.commercecloud.salesforce.com/on/demandware.static/-/Sites-apparel-m-catalog/default/dw0db45f1c/images/small/PG.10227905.JJ0KMXX.PZ.jpg" ,
282+ "title" : "Neutral Floral Dress, "
283+ } ,
284+ "price" : 82.56 ,
285+ "productId" : "25592479M" ,
286+ "productName" : "Neutral Floral Dress"
287+ }
288+ ] ,
289+ "suggestedPhrases" : [
290+ {
291+ "exactMatch" : true ,
292+ "phrase" : "dress"
293+ }
294+ ] ,
295+ "suggestedTerms" : [
296+ {
297+ "originalTerm" : "dress" ,
298+ "terms" : [
299+ {
300+ "completed" : false ,
301+ "corrected" : false ,
302+ "exactMatch" : true ,
303+ "value" : "dress"
304+ }
305+ ]
306+ }
307+ ]
308+ } ,
309+ "searchPhrase" : "dress"
310+ }
311+
312+ const searchSuggestion = {
313+ data : mockEinsteinSuggestions ,
314+ isLoading : false ,
315+ error : null
316+ }
144317 const searchInputRef = useRef ( )
145318 const miawChatRef = useRef ( {
146319 newChatLaunched : false ,
@@ -160,7 +333,9 @@ const Search = (props) => {
160333 const searchSuggestionsAvailable =
161334 searchSuggestions &&
162335 ( searchSuggestions ?. categorySuggestions ?. length ||
163- searchSuggestions ?. phraseSuggestions ?. length )
336+ searchSuggestions ?. phraseSuggestions ?. length ||
337+ searchSuggestions ?. popularSearchSuggestions ?. length ||
338+ searchSuggestions ?. recentSearchSuggestions ?. length )
164339
165340 const saveRecentSearch = ( searchText ) => {
166341 // Get recent searches or an empty array if undefined.
0 commit comments