Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductRenderList.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Catalog\Model;
8 
10 use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
17 
24 {
28  private $collectionProcessor;
29 
33  private $collectionFactory;
34 
38  private $productRenderCollectorComposite;
39 
43  private $searchResultFactory;
44 
48  private $productRenderFactory;
49 
53  private $productAttributes;
54 
58  private $collectionModifier;
59 
71  public function __construct(
72  CollectionFactory $collectionFactory,
73  CollectionProcessorInterface $collectionProcessor,
74  ProductRenderCollectorComposite $productRenderCollectorComposite,
75  ProductRenderSearchResultsFactory $searchResultFactory,
76  ProductRenderFactory $productRenderDtoFactory,
77  \Magento\Catalog\Model\Config $config,
78  CollectionModifier $collectionModifier,
79  array $productAttributes
80  ) {
81  $this->collectionProcessor = $collectionProcessor;
82  $this->collectionFactory = $collectionFactory;
83  $this->productRenderCollectorComposite = $productRenderCollectorComposite;
84  $this->searchResultFactory = $searchResultFactory;
85  $this->productRenderFactory = $productRenderDtoFactory;
86  $this->productAttributes = array_merge($productAttributes, $config->getProductAttributes());
87  $this->collectionModifier = $collectionModifier;
88  }
89 
93  public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria, $storeId, $currencyCode)
94  {
95  $items = [];
96  $productCollection = $this->collectionFactory->create();
97  $productCollection->addAttributeToSelect($this->productAttributes)
98  ->setStoreId($storeId)
99  ->addMinimalPrice()
100  ->addFinalPrice()
101  ->addTaxPercents();
102 
103  $this->collectionModifier->apply($productCollection);
104  $this->collectionProcessor->process($searchCriteria, $productCollection);
105 
106  foreach ($productCollection as $item) {
107  $productRenderInfo = $this->productRenderFactory->create();
108  $productRenderInfo->setStoreId($storeId);
109  $productRenderInfo->setCurrencyCode($currencyCode);
110  $this->productRenderCollectorComposite->collect($item, $productRenderInfo);
111  $items[$item->getId()] = $productRenderInfo;
112  }
113 
114  $searchResult = $this->searchResultFactory->create();
115  $searchResult->setItems($items);
116  $searchResult->setTotalCount(count($items));
117  $searchResult->setSearchCriteria($searchCriteria);
118 
119  return $searchResult;
120  }
121 }
$config
Definition: fraud_order.php:17
$searchCriteria
getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria, $storeId, $currencyCode)
__construct(CollectionFactory $collectionFactory, CollectionProcessorInterface $collectionProcessor, ProductRenderCollectorComposite $productRenderCollectorComposite, ProductRenderSearchResultsFactory $searchResultFactory, ProductRenderFactory $productRenderDtoFactory, \Magento\Catalog\Model\Config $config, CollectionModifier $collectionModifier, array $productAttributes)
$items