Skip to content

Commit 5623c99

Browse files
committed
Merge remote-tracking branch 'remotes/origin/MAGETWO-44159' into BugFestW4
2 parents b9f2ad7 + 2bea2a1 commit 5623c99

File tree

6 files changed

+67
-24
lines changed

6 files changed

+67
-24
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,20 @@ protected function _getWebsiteDateTable()
224224
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
225225
*/
226226
protected function _prepareFinalPriceData($entityIds = null)
227+
{
228+
return $this->prepareFinalPriceDataForType($entityIds, $this->getTypeId());
229+
}
230+
231+
/**
232+
* Prepare products default final price in temporary index table
233+
*
234+
* @param int|array $entityIds the entity ids limitation
235+
* @param string|null $type product type, all if null
236+
* @return $this
237+
* @throws \Magento\Framework\Exception\LocalizedException
238+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
239+
*/
240+
protected function prepareFinalPriceDataForType($entityIds, $type)
227241
{
228242
$this->_prepareDefaultFinalPriceTable();
229243

@@ -260,11 +274,12 @@ protected function _prepareFinalPriceData($entityIds = null)
260274
'tp.entity_id = e.entity_id AND tp.website_id = cw.website_id' .
261275
' AND tp.customer_group_id = cg.customer_group_id',
262276
[]
263-
)->where(
264-
'e.type_id = ?',
265-
$this->getTypeId()
266277
);
267278

279+
if ($type !== null) {
280+
$select->where('e.type_id = ?', $type);
281+
}
282+
268283
// add enable products limitation
269284
$statusCond = $connection->quoteInto(
270285
'=?',
@@ -299,10 +314,10 @@ protected function _prepareFinalPriceData($entityIds = null)
299314

300315
$select->columns(
301316
[
302-
'orig_price' => $price,
303-
'price' => $finalPrice,
304-
'min_price' => $finalPrice,
305-
'max_price' => $finalPrice,
317+
'orig_price' => $connection->getIfNullSql($price, 0),
318+
'price' => $connection->getIfNullSql($finalPrice, 0),
319+
'min_price' => $connection->getIfNullSql($finalPrice, 0),
320+
'max_price' => $connection->getIfNullSql($finalPrice, 0),
306321
'tier_price' => new \Zend_Db_Expr('tp.min_price'),
307322
'base_tier' => new \Zend_Db_Expr('tp.min_price'),
308323
]
@@ -554,9 +569,10 @@ protected function _applyCustomOption()
554569
/**
555570
* Mode Final Prices index to primary temporary index table
556571
*
572+
* @param int[]|null $entityIds
557573
* @return $this
558574
*/
559-
protected function _movePriceDataToIndexTable()
575+
protected function _movePriceDataToIndexTable($entityIds = null)
560576
{
561577
$columns = [
562578
'entity_id' => 'entity_id',
@@ -574,6 +590,10 @@ protected function _movePriceDataToIndexTable()
574590
$table = $this->_getDefaultFinalPriceTable();
575591
$select = $connection->select()->from($table, $columns);
576592

593+
if ($entityIds !== null) {
594+
$select->where('entity_id in (?)', count($entityIds) > 0 ? $entityIds : 0);
595+
}
596+
577597
$query = $select->insertFromSelect($this->getIdxTable(), [], false);
578598
$connection->query($query);
579599

app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Dynamic/DataProvider.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ public function getAggregation(
135135
$column = $select->getPart(Select::COLUMNS)[0];
136136
$select->reset(Select::COLUMNS);
137137
$rangeExpr = new \Zend_Db_Expr(
138-
$this->connection->quoteInto('(FLOOR(' . $column[1] . ' / ? ) + 1)', $range)
138+
$this->connection->getIfNullSql(
139+
$this->connection->quoteInto('FLOOR(' . $column[1] . ' / ? ) + 1', $range),
140+
1
141+
)
139142
);
140143

141144
$select

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,46 @@ public function reindexEntity($entityIds)
4848
protected function reindex($entityIds = null)
4949
{
5050
if ($this->hasEntity() || !empty($entityIds)) {
51-
$this->_prepareFinalPriceData($entityIds);
51+
if (!empty($entityIds)) {
52+
$allEntityIds = $this->getRelatedProducts($entityIds);
53+
$this->prepareFinalPriceDataForType($allEntityIds, null);
54+
} else {
55+
$this->_prepareFinalPriceData($entityIds);
56+
}
5257
$this->_applyCustomOption();
53-
$this->_applyConfigurableOption();
54-
$this->_movePriceDataToIndexTable();
58+
$this->_applyConfigurableOption($entityIds);
59+
$this->_movePriceDataToIndexTable($entityIds);
5560
}
5661
return $this;
5762
}
5863

64+
/**
65+
* Get related product
66+
*
67+
* @param int[] $entityIds
68+
* @return int[]
69+
*/
70+
private function getRelatedProducts($entityIds)
71+
{
72+
$select = $this->getConnection()->select()->union(
73+
[
74+
$this->getConnection()->select()
75+
->from($this->getTable('catalog_product_super_link'), 'parent_id')
76+
->where('parent_id in (?)', $entityIds),
77+
$this->getConnection()->select()
78+
->from($this->getTable('catalog_product_super_link'), 'product_id')
79+
->where('parent_id in (?)', $entityIds),
80+
$this->getConnection()->select()
81+
->from($this->getTable('catalog_product_super_link'), 'product_id')
82+
->where('product_id in (?)', $entityIds),
83+
]
84+
);
85+
return array_map(
86+
'intval',
87+
$this->getConnection()->fetchCol($select)
88+
);
89+
}
90+
5991
/**
6092
* Retrieve table name for custom option temporary aggregation data
6193
*

app/code/Magento/ConfigurableProduct/Setup/InstallData.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
4747
'minimal_price',
4848
'msrp',
4949
'msrp_display_actual_price_type',
50-
'price',
5150
'special_price',
5251
'special_from_date',
5352
'special_to_date',

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<data name="product/data/checkout_data/dataset" xsi:type="string">configurable_two_options</data>
1515
<data name="product/data/name" xsi:type="string">Configurable Product %isolation%</data>
1616
<data name="product/data/sku" xsi:type="string">configurable_sku_%isolation%</data>
17-
<data name="product/data/price/value" xsi:type="string">100</data>
1817
<data name="product/data/price/dataset" xsi:type="string">default</data>
1918
<data name="product/data/category_ids/dataset" xsi:type="string">default_subcategory</data>
2019
<data name="product/data/short_description" xsi:type="string">Configurable short description</data>
@@ -39,7 +38,6 @@
3938
<data name="product/data/checkout_data/dataset" xsi:type="string">configurable_two_options</data>
4039
<data name="product/data/name" xsi:type="string">Configurable Product %isolation%</data>
4140
<data name="product/data/sku" xsi:type="string">configurable_sku_%isolation%</data>
42-
<data name="product/data/price/value" xsi:type="string">100</data>
4341
<data name="product/data/short_description" xsi:type="string">Configurable short description</data>
4442
<data name="product/data/description" xsi:type="string">Configurable Product description %isolation%</data>
4543
<data name="product/data/weight" xsi:type="string">2</data>
@@ -60,7 +58,6 @@
6058
<data name="product/data/checkout_data/dataset" xsi:type="string">configurable_two_new_options_with_special_price</data>
6159
<data name="product/data/name" xsi:type="string">Configurable Product %isolation%</data>
6260
<data name="product/data/sku" xsi:type="string">configurable_sku_%isolation%</data>
63-
<data name="product/data/price/value" xsi:type="string">100</data>
6461
<data name="product/data/special_price" xsi:type="string">10</data>
6562
<data name="product/data/short_description" xsi:type="string">Configurable short description</data>
6663
<data name="product/data/description" xsi:type="string">Configurable Product description %isolation%</data>
@@ -83,7 +80,6 @@
8380
<data name="product/data/checkout_data/dataset" xsi:type="string">configurable_two_options_with_assigned_product</data>
8481
<data name="product/data/name" xsi:type="string">Configurable Product %isolation%</data>
8582
<data name="product/data/sku" xsi:type="string">configurable_sku_%isolation%</data>
86-
<data name="product/data/price/value" xsi:type="string">100</data>
8783
<data name="product/data/short_description" xsi:type="string">Configurable short description</data>
8884
<data name="product/data/description" xsi:type="string">Configurable Product description %isolation%</data>
8985
<data name="product/data/weight" xsi:type="string">2</data>
@@ -102,7 +98,6 @@
10298
<data name="product/data/name" xsi:type="string">Configurable Product %isolation%</data>
10399
<data name="product/data/sku" xsi:type="string">configurable_sku_%isolation%</data>
104100
<data name="product/data/tax_class_id" xsi:type="string">Taxable Goods</data>
105-
<data name="product/data/price/value" xsi:type="string">10</data>
106101
<data name="product/data/price/dataset" xsi:type="string">MAGETWO-12620</data>
107102
<data name="product/data/category_ids/dataset" xsi:type="string">default_subcategory</data>
108103
<data name="product/data/weight" xsi:type="string">1</data>
@@ -116,7 +111,6 @@
116111
<data name="product/data/configurable_attributes_data/dataset" xsi:type="string">two_searchable_options</data>
117112
<data name="product/data/name" xsi:type="string">Configurable Product %isolation%</data>
118113
<data name="product/data/sku" xsi:type="string">configurable_sku_%isolation%</data>
119-
<data name="product/data/price/value" xsi:type="string">100</data>
120114
<data name="product/data/price/dataset" xsi:type="string">default</data>
121115
<data name="product/data/category_ids/new_category" xsi:type="string">no</data>
122116
<data name="product/data/category_ids/dataset" xsi:type="string">default_subcategory</data>

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/UpdateConfigurableProductEntityTest.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<data name="updatedProduct/data/checkout_data/cartItem/price" xsi:type="string">153</data>
1818
<data name="updatedProduct/data/name" xsi:type="string">Configurable Product %isolation%</data>
1919
<data name="updatedProduct/data/sku" xsi:type="string">configurable_sku_%isolation%</data>
20-
<data name="updatedProduct/data/price/value" xsi:type="string">99</data>
2120
<data name="updatedProduct/data/category_ids/dataset" xsi:type="string">default_subcategory</data>
2221
<data name="updatedProduct/data/short_description" xsi:type="string">Configurable short description</data>
2322
<data name="updatedProduct/data/description" xsi:type="string">Configurable Product description %isolation%</data>
@@ -42,7 +41,6 @@
4241
<data name="updatedProduct/data/checkout_data/cartItem/price" xsi:type="string">154</data>
4342
<data name="updatedProduct/data/name" xsi:type="string">Configurable Product %isolation%</data>
4443
<data name="updatedProduct/data/sku" xsi:type="string">configurable_sku_%isolation%</data>
45-
<data name="updatedProduct/data/price/value" xsi:type="string">99</data>
4644
<data name="updatedProduct/data/short_description" xsi:type="string">Configurable short description</data>
4745
<data name="updatedProduct/data/description" xsi:type="string">Configurable Product description %isolation%</data>
4846
<data name="updatedProduct/data/weight" xsi:type="string">3</data>
@@ -65,7 +63,6 @@
6563
<data name="updatedProduct/data/checkout_data/cartItem/price" xsi:type="string">112</data>
6664
<data name="updatedProduct/data/name" xsi:type="string">Configurable Product %isolation%</data>
6765
<data name="updatedProduct/data/sku" xsi:type="string">configurable_sku_%isolation%</data>
68-
<data name="updatedProduct/data/price/value" xsi:type="string">99</data>
6966
<data name="updatedProduct/data/category_ids/dataset" xsi:type="string">default_subcategory</data>
7067
<data name="updatedProduct/data/short_description" xsi:type="string">Configurable short description</data>
7168
<data name="updatedProduct/data/description" xsi:type="string">Configurable Product description %isolation%</data>
@@ -88,7 +85,6 @@
8885
<data name="updatedProduct/data/checkout_data/dataset" xsi:type="string">configurable_two_attributes</data>
8986
<data name="updatedProduct/data/name" xsi:type="string">Configurable Product %isolation%</data>
9087
<data name="updatedProduct/data/sku" xsi:type="string">configurable_sku_%isolation%</data>
91-
<data name="updatedProduct/data/price/value" xsi:type="string">99</data>
9288
<data name="updatedProduct/data/short_description" xsi:type="string">Configurable short description</data>
9389
<data name="updatedProduct/data/description" xsi:type="string">Configurable Product description %isolation%</data>
9490
<data name="updatedProduct/data/weight" xsi:type="string">3</data>
@@ -106,7 +102,6 @@
106102
<data name="updatedProduct/data/configurable_attributes_data/dataset" xsi:type="string">one_new_options</data>
107103
<data name="updatedProduct/data/name" xsi:type="string">Configurable Product %isolation%</data>
108104
<data name="updatedProduct/data/sku" xsi:type="string">configurable_sku_%isolation%</data>
109-
<data name="updatedProduct/data/price/value" xsi:type="string">99</data>
110105
<constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" />
111106
<constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductPage" />
112107
</variation>

0 commit comments

Comments
 (0)