Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LowestPriceOptionsProvider.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
13 
18 {
22  private $resource;
23 
27  private $linkedProductSelectBuilder;
28 
32  private $collectionFactory;
33 
37  private $storeManager;
38 
44  private $linkedProductMap;
45 
52  public function __construct(
54  LinkedProductSelectBuilderInterface $linkedProductSelectBuilder,
55  CollectionFactory $collectionFactory,
56  StoreManagerInterface $storeManager
57  ) {
58  $this->resource = $resourceConnection;
59  $this->linkedProductSelectBuilder = $linkedProductSelectBuilder;
60  $this->collectionFactory = $collectionFactory;
61  $this->storeManager = $storeManager;
62  }
63 
68  {
69  $key = $this->storeManager->getStore()->getId() . '-' . $product->getId();
70  if (!isset($this->linkedProductMap[$key])) {
71  $productIds = $this->resource->getConnection()->fetchCol(
72  '(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')'
73  );
74 
75  $this->linkedProductMap[$key] = $this->collectionFactory->create()
76  ->addAttributeToSelect(
77  ['price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id']
78  )
79  ->addIdFilter($productIds)
80  ->getItems();
81  }
82  return $this->linkedProductMap[$key];
83  }
84 }
$storeManager
__construct(ResourceConnection $resourceConnection, LinkedProductSelectBuilderInterface $linkedProductSelectBuilder, CollectionFactory $collectionFactory, StoreManagerInterface $storeManager)