Skip to content

Commit e610fae

Browse files
committed
ACP2E-322:'Move out of stock to the bottom' automating sorting is not updated when product's stock changes
1 parent 8e0b549 commit e610fae

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

app/code/Magento/CatalogInventory/Model/ResourceModel/StockStatusFilter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ public function execute(
9595
implode(' AND ', $joinCondition),
9696
[]
9797
);
98-
if (!$this->hasSearchResultApplier()) {
98+
99+
if ($this->hasSearchResultApplier()) {
100+
$select->columns(["{$stockStatusTableAlias}.stock_status AS is_salable"]);
101+
} else {
99102
$select->where("{$stockStatusTableAlias}.stock_status = ?", StockStatusInterface::STATUS_IN_STOCK);
100103
}
101104

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ private function categoryProductByCustomSortOrder(int $categoryId): array
201201
$searchCriteria = $this->searchResult->getSearchCriteria();
202202
$sortOrders = $searchCriteria->getSortOrders() ?? [];
203203
$sortOrders = array_merge(['is_salable' => \Magento\Framework\DB\Select::SQL_DESC], $sortOrders);
204-
$defaultColumnsFilter = ['is_salable', 'position', 'name', 'price', 'entity_id'];
205204

206205
$connection = $this->collection->getConnection();
207206
$query = clone $connection->select()
@@ -220,7 +219,7 @@ private function categoryProductByCustomSortOrder(int $categoryId): array
220219
'cat_index.product_id = e.entity_id'
221220
. ' AND cat_index.category_id = ' . $categoryId
222221
. ' AND cat_index.store_id = ' . $storeId,
223-
['cat_index.position AS cat_index_position']
222+
['cat_index.position']
224223
);
225224
foreach ($sortOrders as $field => $dir) {
226225
if ($field === 'name') {
@@ -244,7 +243,12 @@ private function categoryProductByCustomSortOrder(int $categoryId): array
244243
['price_index.max_price AS price']
245244
);
246245
}
247-
if (in_array($field, $defaultColumnsFilter, true)) {
246+
$columnFilters = [];
247+
$columnsParts = $query->getPart('columns');
248+
foreach ($columnsParts as $columns) {
249+
$columnFilters[] = $columns[2] ?? $columns[1];
250+
}
251+
if (in_array($field, $columnFilters, true)) {
248252
$query->order(new \Zend_Db_Expr("{$field} {$dir}"));
249253
}
250254
}

0 commit comments

Comments
 (0)