@@ -651,24 +651,52 @@ protected function addFilterGroupToCollection(
651
651
Collection $ collection
652
652
) {
653
653
$ fields = [];
654
- $ categoryFilter = [];
654
+
655
655
foreach ($ filterGroup ->getFilters () as $ filter ) {
656
656
$ conditionType = $ filter ->getConditionType () ? $ filter ->getConditionType () : 'eq ' ;
657
+ $ isApplied = $ this ->applyCustomFilter ($ collection , $ filter , $ conditionType );
657
658
658
- if ($ filter ->getField () == 'category_id ' ) {
659
- $ categoryFilter [$ conditionType ][] = $ filter ->getValue ();
660
- continue ;
659
+ if (!$ isApplied ) {
660
+ $ fields [] = ['attribute ' => $ filter ->getField (), $ conditionType => $ filter ->getValue ()];
661
661
}
662
- $ fields [] = ['attribute ' => $ filter ->getField (), $ conditionType => $ filter ->getValue ()];
663
662
}
664
663
665
- if ($ categoryFilter ) {
664
+ if ($ fields ) {
665
+ $ collection ->addFieldToFilter ($ fields );
666
+ }
667
+ }
668
+
669
+ /**
670
+ * Apply custom filters to product collection.
671
+ *
672
+ * @param Collection $collection
673
+ * @param \Magento\Framework\Api\Filter $filter
674
+ * @param string $conditionType
675
+ * @return bool
676
+ */
677
+ private function applyCustomFilter (Collection $ collection , \Magento \Framework \Api \Filter $ filter , $ conditionType )
678
+ {
679
+ if ($ filter ->getField () == 'category_id ' ) {
680
+ $ categoryFilter [$ conditionType ][] = $ filter ->getValue ();
666
681
$ collection ->addCategoriesFilter ($ categoryFilter );
682
+ return true ;
667
683
}
668
684
669
- if ($ fields ) {
670
- $ collection ->addFieldToFilter ($ fields );
685
+ if ($ filter ->getField () == 'store ' ) {
686
+ $ collection ->addStoreFilter ($ filter ->getValue ());
687
+ return true ;
671
688
}
689
+
690
+ if ($ filter ->getField () == 'website_id ' ) {
691
+ $ value = $ filter ->getValue ();
692
+ if (strpos ($ value , ', ' ) !== false ) {
693
+ $ value = explode (', ' , $ value );
694
+ }
695
+ $ collection ->addWebsiteFilter ($ value );
696
+ return true ;
697
+ }
698
+
699
+ return false ;
672
700
}
673
701
674
702
/**
0 commit comments