Skip to content

Commit 40657c6

Browse files
committed
MAGETWO-91798: Implement GroupedProduct Price indexer
1 parent 962d600 commit 40657c6

File tree

3 files changed

+55
-72
lines changed
  • app/code/Magento
    • ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price
    • Downloadable/Model/ResourceModel/Indexer
    • GroupedProduct/Model/ResourceModel/Product/Indexer/Price

3 files changed

+55
-72
lines changed

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price/Configurable.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Query\BaseFinalPrice;
1313
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructureFactory;
1414
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure;
15-
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
16-
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
1715

1816
/**
1917
* Configurable Products Price Indexer Resource model
@@ -62,11 +60,6 @@ class Configurable implements DimensionalIndexerInterface
6260
*/
6361
private $connection;
6462

65-
/**
66-
* @var string
67-
*/
68-
private $productType;
69-
7063
/**
7164
* @var BasePriceModifier
7265
*/
@@ -81,7 +74,6 @@ class Configurable implements DimensionalIndexerInterface
8174
* @param BasePriceModifier $basePriceModifier
8275
* @param bool $fullReindexAction
8376
* @param string $connectionName
84-
* @param string $productType
8577
*/
8678
public function __construct(
8779
BaseFinalPrice $baseFinalPrice,
@@ -91,13 +83,11 @@ public function __construct(
9183
\Magento\Framework\App\ResourceConnection $resource,
9284
BasePriceModifier $basePriceModifier,
9385
$fullReindexAction = false,
94-
$connectionName = 'indexer',
95-
$productType = \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE
86+
$connectionName = 'indexer'
9687
) {
9788
$this->baseFinalPrice = $baseFinalPrice;
9889
$this->indexTableStructureFactory = $indexTableStructureFactory;
9990
$this->tableMaintainer = $tableMaintainer;
100-
$this->productType = $productType;
10191
$this->connectionName = $connectionName;
10292
$this->metadataPool = $metadataPool;
10393
$this->resource = $resource;
@@ -126,7 +116,11 @@ public function executeByDimension(array $dimensions, \Traversable $entityIds =
126116
'maxPriceField' => 'max_price',
127117
'tierPriceField' => 'tier_price',
128118
]);
129-
$select = $this->baseFinalPrice->getQuery($dimensions, $this->productType, iterator_to_array($entityIds));
119+
$select = $this->baseFinalPrice->getQuery(
120+
$dimensions,
121+
\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE,
122+
iterator_to_array($entityIds)
123+
);
130124
$query = $select->insertFromSelect($temporaryPriceTable->getTableName(), [], false);
131125
$this->tableMaintainer->getConnection()->query($query);
132126

@@ -135,6 +129,8 @@ public function executeByDimension(array $dimensions, \Traversable $entityIds =
135129
}
136130

137131
/**
132+
* Apply configurable option
133+
*
138134
* @param IndexTableStructure $temporaryPriceTable
139135
* @param array $dimensions
140136
* @param array $entityIds
@@ -203,14 +199,6 @@ private function fillTemporaryOptionsTable(string $temporaryOptionsTableName, ar
203199
if ($entityIds !== null) {
204200
$select->where('le.entity_id IN (?)', $entityIds);
205201
}
206-
foreach ($dimensions as $dimension) {
207-
if ($dimension->getName() === WebsiteDimensionProvider::DIMENSION_NAME) {
208-
$select->where('website_id = ?', $dimension->getValue());
209-
}
210-
if ($dimension->getName() === CustomerGroupDimensionProvider::DIMENSION_NAME) {
211-
$select->where('customer_group_id = ?', $dimension->getValue());
212-
}
213-
}
214202
$query = $select->insertFromSelect($temporaryOptionsTableName);
215203
$this->getConnection()->query($query);
216204
}

app/code/Magento/Downloadable/Model/ResourceModel/Indexer/Price.php

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Query\BaseFinalPrice;
1818
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructureFactory;
1919
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure;
20-
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
21-
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
2220

2321
/**
2422
* Downloadable Product Price Indexer Resource model
@@ -61,11 +59,6 @@ class Price implements DimensionalIndexerInterface
6159
*/
6260
private $connection;
6361

64-
/**
65-
* @var string
66-
*/
67-
private $productType;
68-
6962
/**
7063
* @var Config
7164
*/
@@ -83,10 +76,8 @@ class Price implements DimensionalIndexerInterface
8376
* @param MetadataPool $metadataPool
8477
* @param Config $eavConfig
8578
* @param ResourceConnection $resource
86-
* @param string $connectionName
87-
* @param string $productType
8879
* @param BasePriceModifier $basePriceModifier
89-
* @param array $priceModifiers
80+
* @param string $connectionName
9081
*/
9182
public function __construct(
9283
BaseFinalPrice $baseFinalPrice,
@@ -96,13 +87,11 @@ public function __construct(
9687
Config $eavConfig,
9788
ResourceConnection $resource,
9889
BasePriceModifier $basePriceModifier,
99-
$connectionName = 'indexer',
100-
$productType = Type::TYPE_DOWNLOADABLE
90+
$connectionName = 'indexer'
10191
) {
10292
$this->baseFinalPrice = $baseFinalPrice;
10393
$this->indexTableStructureFactory = $indexTableStructureFactory;
10494
$this->tableMaintainer = $tableMaintainer;
105-
$this->productType = $productType;
10695
$this->connectionName = $connectionName;
10796
$this->metadataPool = $metadataPool;
10897
$this->resource = $resource;
@@ -136,6 +125,7 @@ public function executeByDimension(array $dimensions, \Traversable $entityIds =
136125

137126
/**
138127
* Calculate and apply Downloadable links price to index
128+
*
139129
* @param IndexTableStructure $temporaryPriceTable
140130
* @param array $dimensions
141131
* @return $this
@@ -159,8 +149,10 @@ private function applyDownloadableLink(
159149

160150
/**
161151
* Retrieve catalog_product attribute instance by attribute code
152+
*
162153
* @param string $attributeCode
163154
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute
155+
* @throws \Magento\Framework\Exception\LocalizedException
164156
*/
165157
protected function getAttribute($attributeCode)
166158
{
@@ -169,6 +161,7 @@ protected function getAttribute($attributeCode)
169161

170162
/**
171163
* Put data into catalog product price indexer Downloadable links price temp table
164+
*
172165
* @param string $temporaryDownloadableTableName
173166
* @param array $dimensions
174167
* @return void
@@ -211,22 +204,13 @@ private function fillTemporaryTable(string $temporaryDownloadableTableName, arra
211204
'max_price' => new \Zend_Db_Expr('SUM(' . $ifPrice . ')'),
212205
]
213206
);
214-
215-
foreach ($dimensions as $dimension) {
216-
if ($dimension->getName() === WebsiteDimensionProvider::DIMENSION_NAME) {
217-
$select->where('`i`.website_id = ?', $dimension->getValue());
218-
}
219-
if ($dimension->getName() === CustomerGroupDimensionProvider::DIMENSION_NAME) {
220-
$select->where('`i`.customer_group_id = ?', $dimension->getValue());
221-
}
222-
}
223-
224207
$query = $select->insertFromSelect($temporaryDownloadableTableName);
225208
$this->getConnection()->query($query);
226209
}
227210

228211
/**
229212
* Update data in the catalog product price indexer temp table
213+
*
230214
* @param string $temporaryPriceTableName
231215
* @param string $temporaryDownloadableTableName
232216
* @return void
@@ -259,6 +243,25 @@ private function updateTemporaryDownloadableTable(
259243
$this->getConnection()->query($query);
260244
}
261245

246+
/**
247+
* Fill final price
248+
*
249+
* @param array $dimensions
250+
* @param \Traversable $entityIds
251+
* @param IndexTableStructure $temporaryPriceTable
252+
* @throws \Magento\Framework\Exception\LocalizedException
253+
* @throws \Zend_Db_Select_Exception
254+
*/
255+
private function fillFinalPrice(
256+
array $dimensions,
257+
\Traversable $entityIds,
258+
IndexTableStructure $temporaryPriceTable
259+
) {
260+
$select = $this->baseFinalPrice->getQuery($dimensions, Type::TYPE_DOWNLOADABLE, iterator_to_array($entityIds));
261+
$query = $select->insertFromSelect($temporaryPriceTable->getTableName(), [], false);
262+
$this->tableMaintainer->getConnection()->query($query);
263+
}
264+
262265
/**
263266
* Get connection
264267
*
@@ -270,6 +273,7 @@ private function getConnection(): \Magento\Framework\DB\Adapter\AdapterInterface
270273
if ($this->connection === null) {
271274
$this->connection = $this->resource->getConnection($this->connectionName);
272275
}
276+
273277
return $this->connection;
274278
}
275279

@@ -283,21 +287,4 @@ private function getTable($tableName)
283287
{
284288
return $this->resource->getTableName($tableName, $this->connectionName);
285289
}
286-
287-
/**
288-
* @param array $dimensions
289-
* @param \Traversable $entityIds
290-
* @param IndexTableStructure $temporaryPriceTable
291-
* @throws \Magento\Framework\Exception\LocalizedException
292-
* @throws \Zend_Db_Select_Exception
293-
*/
294-
private function fillFinalPrice(
295-
array $dimensions,
296-
\Traversable $entityIds,
297-
IndexTableStructure $temporaryPriceTable
298-
) {
299-
$select = $this->baseFinalPrice->getQuery($dimensions, $this->productType, iterator_to_array($entityIds));
300-
$query = $select->insertFromSelect($temporaryPriceTable->getTableName(), [], false);
301-
$this->tableMaintainer->getConnection()->query($query);
302-
}
303290
}

app/code/Magento/GroupedProduct/Model/ResourceModel/Product/Indexer/Price/Grouped.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,20 @@ public function executeByDimension(array $dimensions, \Traversable $entityIds =
104104
'maxPriceField' => 'max_price',
105105
'tierPriceField' => 'tier_price',
106106
]);
107-
$query = $this->_prepareGroupedProductPriceDataSelect($dimensions, iterator_to_array($entityIds))
107+
$query = $this->prepareGroupedProductPriceDataSelect($dimensions, iterator_to_array($entityIds))
108108
->insertFromSelect($temporaryPriceTable->getTableName());
109109
$this->getConnection()->query($query);
110110
}
111111

112112
/**
113113
* Prepare data index select for Grouped products prices
114+
*
114115
* @param $dimensions
115116
* @param int|array $entityIds the parent entity ids limitation
116117
* @return \Magento\Framework\DB\Select
118+
* @throws \Exception
117119
*/
118-
protected function _prepareGroupedProductPriceDataSelect($dimensions, $entityIds = null)
120+
protected function prepareGroupedProductPriceDataSelect($dimensions, $entityIds = null)
119121
{
120122
$select = $this->getConnection()->select();
121123

@@ -130,7 +132,7 @@ protected function _prepareGroupedProductPriceDataSelect($dimensions, $entityIds
130132
'e.' . $linkField . ' = l.product_id AND l.link_type_id=' . Link::LINK_TYPE_GROUPED,
131133
[]
132134
);
133-
//aditional infromation about inner products
135+
//additional information about inner products
134136
$select->joinLeft(
135137
['le' => $this->getTable('catalog_product_entity')],
136138
'le.entity_id = l.linked_product_id',
@@ -172,9 +174,18 @@ protected function _prepareGroupedProductPriceDataSelect($dimensions, $entityIds
172174
return $select;
173175
}
174176

175-
private function getTable($tableName)
177+
/**
178+
* Get main table
179+
*
180+
* @param array $dimensions
181+
* @return string
182+
*/
183+
private function getMainTable($dimensions)
176184
{
177-
return $this->resource->getTableName($tableName, $this->connectionName);
185+
if ($this->fullReindexAction) {
186+
return $this->tableMaintainer->getMainReplicaTable($dimensions);
187+
}
188+
return $this->tableMaintainer->getMainTable($dimensions);
178189
}
179190

180191
/**
@@ -193,16 +204,13 @@ private function getConnection(): \Magento\Framework\DB\Adapter\AdapterInterface
193204
}
194205

195206
/**
196-
* Get main table
207+
* Get table
197208
*
198-
* @param array $dimensions
209+
* @param string $tableName
199210
* @return string
200211
*/
201-
private function getMainTable($dimensions)
212+
private function getTable($tableName)
202213
{
203-
if ($this->fullReindexAction) {
204-
return $this->tableMaintainer->getMainReplicaTable($dimensions);
205-
}
206-
return $this->tableMaintainer->getMainTable($dimensions);
214+
return $this->resource->getTableName($tableName, $this->connectionName);
207215
}
208216
}

0 commit comments

Comments
 (0)