Skip to content

Commit 962d600

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

File tree

1 file changed

+38
-15
lines changed
  • app/code/Magento/GroupedProduct/Model/ResourceModel/Product/Indexer/Price

1 file changed

+38
-15
lines changed

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

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructureFactory;
1717
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure;
1818
use Magento\GroupedProduct\Model\ResourceModel\Product\Link;
19+
use Magento\GroupedProduct\Model\Product\Type\Grouped as GroupedType;
1920

2021
/**
2122
* Calculate minimal and maximal prices for Grouped products
@@ -111,24 +112,43 @@ public function executeByDimension(array $dimensions, \Traversable $entityIds =
111112
/**
112113
* Prepare data index select for Grouped products prices
113114
* @param $dimensions
114-
* @param array $entityIds the parent entity ids limitation
115+
* @param int|array $entityIds the parent entity ids limitation
115116
* @return \Magento\Framework\DB\Select
116117
*/
117118
protected function _prepareGroupedProductPriceDataSelect($dimensions, $entityIds = null)
118119
{
119-
$connection = $this->getConnection();
120+
$select = $this->getConnection()->select();
120121

121-
$taxClassId = $connection->getCheckSql('MIN(i.tax_class_id) IS NULL', '0', 'MIN(i.tax_class_id)');
122-
$minCheckSql = $connection->getCheckSql('e.required_options = 0', 'i.min_price', 0);
123-
$maxCheckSql = $connection->getCheckSql('e.required_options = 0', 'i.max_price', 0);
124-
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
122+
$select->from(
123+
['e' => $this->getTable('catalog_product_entity')],
124+
'entity_id'
125+
);
125126

126-
$select = $connection->select()->from(['l' => $this->getTable('catalog_product_link')], []);
127+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
128+
$select->joinLeft(
129+
['l' => $this->getTable('catalog_product_link')],
130+
'e.' . $linkField . ' = l.product_id AND l.link_type_id=' . Link::LINK_TYPE_GROUPED,
131+
[]
132+
);
133+
//aditional infromation about inner products
134+
$select->joinLeft(
135+
['le' => $this->getTable('catalog_product_entity')],
136+
'le.entity_id = l.linked_product_id',
137+
[]
138+
);
127139
$select->columns(
128140
[
129-
'entity_id' => new \Zend_Db_Expr('l.product_id'),
130-
'customer_group_id' => new \Zend_Db_Expr('i.customer_group_id'),
131-
'website_id' => new \Zend_Db_Expr('i.website_id'),
141+
'i.customer_group_id',
142+
'i.website_id',
143+
]
144+
);
145+
$taxClassId = $this->getConnection()->getCheckSql('MIN(i.tax_class_id) IS NULL', '0', 'MIN(i.tax_class_id)');
146+
$minCheckSql = $this->getConnection()->getCheckSql('le.required_options = 0', 'i.min_price', 0);
147+
$maxCheckSql = $this->getConnection()->getCheckSql('le.required_options = 0', 'i.max_price', 0);
148+
$select->joinLeft(
149+
['i' => $this->getMainTable($dimensions)],
150+
'i.entity_id = l.linked_product_id',
151+
[
132152
'tax_class_id' => $taxClassId,
133153
'price' => new \Zend_Db_Expr('NULL'),
134154
'final_price' => new \Zend_Db_Expr('NULL'),
@@ -137,13 +157,16 @@ protected function _prepareGroupedProductPriceDataSelect($dimensions, $entityIds
137157
'tier_price' => new \Zend_Db_Expr('NULL'),
138158
]
139159
);
140-
$select->join(['i' => $this->getMainTable($dimensions)], 'i.entity_id = l.linked_product_id', []);
141-
$select->join(['e' => $this->getTable('catalog_product_entity')], "e.$linkField = l.linked_product_id", []);
142-
$select->where('l.link_type_id = ?', Link::LINK_TYPE_GROUPED);
143-
$select->group(['l.product_id', 'i.customer_group_id', 'i.website_id']);
160+
$select->group(
161+
['e.entity_id', 'i.customer_group_id', 'i.website_id']
162+
);
163+
$select->where(
164+
'e.type_id=?',
165+
GroupedType::TYPE_CODE
166+
);
144167

145168
if ($entityIds !== null) {
146-
$select->where('l.product_id IN(?)', $entityIds);
169+
$select->where('e.entity_id IN(?)', $entityIds);
147170
}
148171

149172
return $select;

0 commit comments

Comments
 (0)