Skip to content

Commit 5674592

Browse files
author
Nikita Chubukov
committed
MC-5906: The order of product SKU is not respected
- Added order by conditions for product collection
1 parent 2abb4fb commit 5674592

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

app/code/Magento/Rule/Model/Condition/Sql/Builder.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,24 @@ public function attachConditionToCollection(
250250
$this->_joinTablesToCollection($collection, $combine);
251251
$whereExpression = (string)$this->_getMappedSqlCombination($combine);
252252
if (!empty($whereExpression)) {
253-
// Select ::where method adds braces even on empty expression
254-
$collection->getSelect()->where($whereExpression);
253+
if (!empty($combine->getConditions())) {
254+
foreach ($combine->getConditions() as $condition) {
255+
$conditions = $condition->getData()['value'];
256+
$attribute = $condition->getData()['attribute'];
257+
}
258+
if (!empty($conditions)) {
259+
$conditions = explode(',', $conditions);
260+
foreach ($conditions as &$condition) {
261+
$condition = "'" . trim($condition) . "'";
262+
}
263+
$conditions = implode(', ', $conditions);
264+
}
265+
266+
$collection->getSelect()->where($whereExpression)->order("FIELD($attribute, $conditions)");
267+
} else {
268+
// Select ::where method adds braces even on empty expression
269+
$collection->getSelect()->where($whereExpression);
270+
}
255271
}
256272
}
257273
}

0 commit comments

Comments
 (0)