Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataProductHashMap.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
10 
15 {
19  private $hashMap = [];
20 
24  private $collectionFactory;
25 
29  private $hashMapPool;
30 
34  private $connection;
35 
41  public function __construct(
42  CollectionFactory $collectionFactory,
43  HashMapPool $hashMapPool,
44  ResourceConnection $connection
45  ) {
46  $this->collectionFactory = $collectionFactory;
47  $this->hashMapPool = $hashMapPool;
48  $this->connection = $connection;
49  }
50 
57  public function getAllData($categoryId)
58  {
59  if (!isset($this->hashMap[$categoryId])) {
60  $productsCollection = $this->collectionFactory->create();
61  $productsCollection->getSelect()
62  ->joinInner(
63  ['cp' => $this->connection->getTableName('catalog_category_product')],
64  'cp.product_id = e.entity_id',
65  []
66  )
67  ->where(
68  $productsCollection->getConnection()->prepareSqlCondition(
69  'cp.category_id',
70  [
71  'in' => $this->hashMapPool->getDataMap(
72  DataCategoryHashMap::class,
73  $categoryId
74  )->getAllData($categoryId)
75  ]
76  )
77  )->group('e.entity_id');
78  $this->hashMap[$categoryId] = $productsCollection->getAllIds();
79  }
80  return $this->hashMap[$categoryId];
81  }
82 
86  public function getData($categoryId, $key)
87  {
88  $categorySpecificData = $this->getAllData($categoryId);
89  if (isset($categorySpecificData[$key])) {
90  return $categorySpecificData[$key];
91  }
92  return [];
93  }
94 
98  public function resetData($categoryId)
99  {
100  $this->hashMapPool->resetMap(DataCategoryHashMap::class, $categoryId);
101  unset($this->hashMap[$categoryId]);
102  }
103 }
__construct(CollectionFactory $collectionFactory, HashMapPool $hashMapPool, ResourceConnection $connection)
$connection
Definition: bulk.php:13