@@ -32,19 +32,27 @@ public function aroundApply(
3232 Filter $ filter
3333 ): void {
3434 if ($ collection instanceof OrderGridCollection) {
35- $ value = trim ((string ) $ filter ->getValue ());
36- if ($ value === '' ) {
35+ $ raw = trim ((string ) $ filter ->getValue ());
36+ if ($ raw === '' ) {
3737 return ;
3838 }
3939
40- if (preg_match ('/^\{+\s*(\d+)\s*\}+$/ ' , $ value , $ m )) {
41- $ term = $ m [1 ];
42- $ collection ->addFieldToFilter ('increment_id ' , ['eq ' => $ term ]);
40+ $ normalized = preg_replace ('/^\{+|\}+$/ ' , '' , $ raw );
41+ $ normalized = ltrim ($ normalized );
42+ $ normalized = ltrim ($ normalized , '# ' );
43+
44+ // Exact increment_id search when normalized is all digits
45+ if ($ normalized !== '' && ctype_digit ($ normalized )) {
46+ $ collection ->addFieldToFilter ('increment_id ' , ['eq ' => $ normalized ]);
4347 return ;
4448 }
4549
46- $ value = trim ($ value , '{} ' );
47- $ like = '% ' . str_replace (['% ' , '_ ' ], ['\\% ' , '\\_ ' ], $ value ) . '% ' ;
50+ // LIKE across key columns (for names, emails, non-digit terms)
51+ $ valueForLike = trim ($ raw , '{} ' );
52+ $ valueForLike = ltrim ($ valueForLike );
53+ $ valueForLike = ltrim ($ valueForLike , '# ' );
54+
55+ $ like = '% ' . str_replace (['% ' , '_ ' ], ['\\% ' , '\\_ ' ], $ valueForLike ) . '% ' ;
4856
4957 $ fields = ['increment_id ' , 'billing_name ' , 'shipping_name ' , 'customer_email ' ];
5058 $ conditions = array_fill (0 , count ($ fields ), ['like ' => $ like ]);
0 commit comments