@@ -29,29 +29,55 @@ const Search = () => {
29
29
if ( ! searchKeyword ) return
30
30
setIsLoading ( true )
31
31
32
- const searchPayload = {
33
- context : {
34
- domain : DOMAIN
35
- } ,
36
- searchString : searchKeyword ,
37
- category : {
38
- categoryCode : router . query . category || 'Retail'
39
- } ,
40
- fulfillment : {
41
- type : 'Delivery' ,
42
- stops : [
43
- {
44
- location : '28.4594965,77.0266383'
45
- }
46
- ]
32
+ // Split search keyword by comma and trim each keyword
33
+ const searchKeywords = searchKeyword . split ( ',' ) . map ( keyword => keyword . trim ( ) )
34
+
35
+ // Create search payloads with different combinations
36
+ const searchPromises = searchKeywords . map ( ( keyword , index ) => {
37
+ const searchString = keyword
38
+
39
+ const searchPayload = {
40
+ context : {
41
+ domain : DOMAIN
42
+ } ,
43
+ searchString : searchString ,
44
+ category : {
45
+ categoryCode : router . query . category || 'Retail'
46
+ } ,
47
+ fulfillment : {
48
+ type : 'Delivery' ,
49
+ stops : [
50
+ {
51
+ location : '28.4594965,77.0266383'
52
+ }
53
+ ]
54
+ }
47
55
}
48
- }
49
56
50
- axios
51
- . post ( `${ apiUrl } /search` , searchPayload )
52
- . then ( res => {
53
- dispatch ( discoveryActions . addTransactionId ( { transactionId : res . data . data [ 0 ] . context . transaction_id } ) )
54
- const parsedSearchItems = parseSearchlist ( res . data . data )
57
+ return axios . post ( `${ apiUrl } /search` , searchPayload )
58
+ } )
59
+
60
+ Promise . all ( searchPromises )
61
+ . then ( responses => {
62
+ // Process each response and extract items
63
+ const allResults = responses
64
+ . filter ( res => res ?. data ?. data ?. [ 0 ] ?. message ?. providers )
65
+ . map ( res => res . data . data [ 0 ] ) // Keep the original response structure
66
+
67
+ console . log ( 'allResults' , allResults )
68
+
69
+ // Get transaction ID from first valid response
70
+ const firstValidResponse = responses . find ( res => res ?. data ?. data ?. [ 0 ] ?. context ?. transaction_id )
71
+ if ( firstValidResponse ) {
72
+ dispatch (
73
+ discoveryActions . addTransactionId ( {
74
+ transactionId : firstValidResponse . data . data [ 0 ] . context . transaction_id
75
+ } )
76
+ )
77
+ }
78
+
79
+ // Parse and combine all search items
80
+ const parsedSearchItems = parseSearchlist ( allResults )
55
81
dispatch ( discoveryActions . addProducts ( { products : parsedSearchItems } ) )
56
82
setItems ( parsedSearchItems )
57
83
setOriginalItems ( parsedSearchItems )
0 commit comments