Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConditionsToCollectionApplier.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 
21 {
25  private $conditionsToSearchCriteriaMapper;
26 
30  private $searchCriteriaProcessor;
31 
35  private $mappableConditionsProcessor;
36 
42  public function __construct(
43  ConditionsToSearchCriteriaMapper $conditionsToSearchCriteriaMapper,
44  AdvancedFilterProcessor $searchCriteriaProcessor,
45  MappableConditionsProcessor $mappableConditionsProcessor
46  ) {
47  $this->conditionsToSearchCriteriaMapper = $conditionsToSearchCriteriaMapper;
48  $this->searchCriteriaProcessor = $searchCriteriaProcessor;
49  $this->mappableConditionsProcessor = $mappableConditionsProcessor;
50  }
51 
61  public function applyConditionsToCollection(
62  Combine $conditions,
65  // rebuild conditions to have only those that we know how to map them to product collection
66  $mappableConditions = $this->mappableConditionsProcessor->rebuildConditionsTree($conditions);
67 
68  // transform conditions to search criteria
69  $searchCriteria = $this->conditionsToSearchCriteriaMapper->mapConditionsToSearchCriteria($mappableConditions);
70 
71  $mappedProductCollection = clone $productCollection;
72 
73  // apply search criteria to new version of product collection
74  $this->searchCriteriaProcessor->process($searchCriteria, $mappedProductCollection);
75 
76  return $mappedProductCollection;
77  }
78 }
__construct(ConditionsToSearchCriteriaMapper $conditionsToSearchCriteriaMapper, AdvancedFilterProcessor $searchCriteriaProcessor, MappableConditionsProcessor $mappableConditionsProcessor)
$searchCriteria
applyConditionsToCollection(Combine $conditions, ProductCollection $productCollection)