22
33namespace Kiboko \Component \Flow \Magento2 ;
44
5+ use phpDocumentor \Reflection \Types \This ;
6+
57class FilterGroup
68{
79 private array $ filters = [];
@@ -13,15 +15,24 @@ public function asArray(): array
1315
1416 public function withFilter (string $ field , string $ operator , mixed $ value ): self
1517 {
16- $ this ->filters = [
17- '[filters][0][ field] ' => $ field ,
18- '[filters][0][ value] ' => $ value ,
19- '[filters][0][ condition_type] ' => $ operator ,
18+ $ this ->filters [] = [
19+ 'field ' => $ field ,
20+ 'value ' => $ value ,
21+ 'condition_type ' => $ operator ,
2022 ];
2123
2224 return $ this ;
2325 }
2426
27+ public function compileFilters (int $ groupIndex = 0 ): array
28+ {
29+ return array_merge (...array_map (fn (array $ item , int $ key ) => [
30+ sprintf ('searchCriteria[filter_groups][%s][filters][%s][field] ' , $ groupIndex , $ key ) => $ item ['field ' ],
31+ sprintf ('searchCriteria[filter_groups][%s][filters][%s][value] ' , $ groupIndex , $ key ) => $ item ['value ' ],
32+ sprintf ('searchCriteria[filter_groups][%s][filters][%s][condition_type] ' , $ groupIndex , $ key ) => $ item ['condition_type ' ],
33+ ], $ this ->filters , array_keys ($ this ->filters )));
34+ }
35+
2536 public function greaterThan (string $ field , mixed $ value ): self
2637 {
2738 return $ this ->withFilter ($ field , 'gt ' , $ value );
0 commit comments