Skip to content

Commit 784b943

Browse files
committed
MC-42243: Sorting by price is incorrect if price for shared catalog is 0
1 parent 32d3756 commit 784b943

File tree

7 files changed

+14
-35
lines changed

7 files changed

+14
-35
lines changed

app/code/Magento/AdvancedSearch/Model/ResourceModel/Index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ protected function _getCatalogProductPriceData($productIds = null)
107107
$this->tableResolver->resolve('catalog_product_index_price', $dimensions),
108108
['entity_id', 'customer_group_id', 'website_id', 'min_price']
109109
);
110-
$select->where('min_price IS NOT NULL');
111110
if ($productIds) {
112111
$select->where('entity_id IN (?)', $productIds);
113112
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,9 +1767,7 @@ public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC)
17671767
if ($attribute == 'price' && $storeId != 0) {
17681768
$this->addPriceData();
17691769
if ($this->_productLimitationFilters->isUsingPriceIndex()) {
1770-
$this->getSelect()->order(
1771-
new \Zend_Db_Expr("price_index.min_price IS NULL, price_index.min_price {$dir}")
1772-
);
1770+
$this->getSelect()->order("price_index.min_price {$dir}");
17731771
return $this;
17741772
}
17751773
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -394,16 +394,8 @@ private function getSelectForUpdate(string $sourceTable): Select
394394
);
395395
$select->columns(
396396
[
397-
'min_price' => $connection->getCheckSql(
398-
'i.min_price IS NOT NULL',
399-
'i.min_price + io.min_price',
400-
'NULL'
401-
),
402-
'max_price' => $connection->getCheckSql(
403-
'i.max_price IS NOT NULL',
404-
'i.max_price + io.max_price',
405-
'NULL'
406-
),
397+
'min_price' => new ColumnValueExpression('i.min_price + io.min_price'),
398+
'max_price' => new ColumnValueExpression('i.max_price + io.max_price'),
407399
'tier_price' => $connection->getCheckSql(
408400
'i.tier_price IS NOT NULL',
409401
'i.tier_price + io.tier_price',

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ public function getQuery(array $dimensions, string $productType, array $entityId
216216
$select->columns(
217217
[
218218
//orig_price in catalog_product_index_price_final_tmp
219-
'price' => $price,
219+
'price' => $connection->getIfNullSql($price, 0),
220220
//price in catalog_product_index_price_final_tmp
221-
'final_price' => $finalPrice,
222-
'min_price' => $finalPrice,
223-
'max_price' => $finalPrice,
221+
'final_price' => $connection->getIfNullSql($finalPrice, 0),
222+
'min_price' => $connection->getIfNullSql($finalPrice, 0),
223+
'max_price' => $connection->getIfNullSql($finalPrice, 0),
224224
'tier_price' => $tierPrice,
225225
]
226226
);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function process(Select $select)
6060
[]
6161
);
6262
$select->where('si.is_in_stock = ?', Stock::STOCK_IN_STOCK);
63+
$select->orWhere('si_parent.is_in_stock = ?', Stock::STOCK_OUT_OF_STOCK);
6364
}
6465

6566
return $select;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds)
149149
);
150150
$this->tableMaintainer->insertFromSelect($select, $temporaryPriceTable->getTableName(), []);
151151

152-
$this->applyConfigurableOption($temporaryPriceTable, $dimensions, iterator_to_array($entityIds));
153152
$this->basePriceModifier->modifyPrice($temporaryPriceTable, iterator_to_array($entityIds));
153+
$this->applyConfigurableOption($temporaryPriceTable, $dimensions, iterator_to_array($entityIds));
154154
}
155155

156156
/**
@@ -251,8 +251,8 @@ private function updateTemporaryTable(string $temporaryPriceTableName, string $t
251251
// adds price of custom option, that was applied in DefaultPrice::_applyCustomOption
252252
$selectForCrossUpdate->columns(
253253
[
254-
'min_price' => 'io.min_price',
255-
'max_price' => 'io.max_price',
254+
'min_price' => new \Zend_Db_Expr('i.min_price - i.price + io.min_price'),
255+
'max_price' => new \Zend_Db_Expr('i.max_price - i.price + io.max_price'),
256256
'tier_price' => 'io.tier_price',
257257
]
258258
);

app/code/Magento/Elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,11 @@ public function apply()
6969
foreach ($items as $item) {
7070
$ids[] = (int)$item->getId();
7171
}
72+
$orderList = join(',', $ids);
7273
$this->collection->getSelect()
7374
->where('e.entity_id IN (?)', $ids)
74-
->reset(\Magento\Framework\DB\Select::ORDER);
75-
$sortOrder = $this->searchResult->getSearchCriteria()
76-
->getSortOrders();
77-
if (!empty($sortOrder['price']) && $this->collection->getLimitationFilters()->isUsingPriceIndex()) {
78-
$sortDirection = $sortOrder['price'];
79-
$this->collection->getSelect()
80-
->order(
81-
new \Zend_Db_Expr("price_index.min_price IS NULL, price_index.min_price {$sortDirection}")
82-
);
83-
} else {
84-
$orderList = join(',', $ids);
85-
$this->collection->getSelect()
86-
->order(new \Zend_Db_Expr("FIELD(e.entity_id,$orderList)"));
87-
}
75+
->reset(\Magento\Framework\DB\Select::ORDER)
76+
->order(new \Zend_Db_Expr("FIELD(e.entity_id,$orderList)"));
8877
}
8978

9079
/**

0 commit comments

Comments
 (0)