-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Closed
Labels
Fixed in 2.2.xThe issue has been fixed in 2.2 release lineThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is not validGate 1 Failed. Automatic verification of issue format is failedGate 1 Failed. Automatic verification of issue format is failedReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseThe issue has been reproduced on latest 2.2 release
Description
Empty SearchCriteria causes the error in \Magento\Framework\Data\Collection\AbstractDb::_setOrder
Target SQL has wrong ORDER BY clause (without any field inside):
SELECT ... ORDER BY DESC
This is the code to get error:
class SalesRules
{
/** @var \Magento\Framework\Api\Search\SearchCriteriaBuilder */
protected $_builderSearchCriteria;
/** @var \Magento\SalesRule\Api\RuleRepositoryInterface */
protected $_repoRule;
public function __construct(
\Magento\Framework\Api\Search\SearchCriteriaBuilder $builderSearchCriteria,
\Magento\SalesRule\Api\RuleRepositoryInterface $repoRule
) {
$this->_builderSearchCriteria = $builderSearchCriteria;
$this->_repoRule = $repoRule;
}
/**
* Add sales rules.
*/
public function init()
{
$crit = $this->_builderSearchCriteria->create();
$all = $this->_repoRule->getList($crit);
}
}
Method \Magento\SalesRule\Model\RuleRepository::getList adds order for $filed=null:

I suppose we need field validation in \Magento\Framework\Data\Collection\AbstractDb::_setOrder
private function _setOrder($field, $direction, $unshift = false)
{
if($field) {
...
}
return $this;
}
or validation in the \Magento\SalesRule\Model\RuleRepository::getList:
/** @var \Magento\Framework\Api\SortOrder $sortOrder */
foreach ($sortOrders as $sortOrder) {
$field = $sortOrder->getField();
if($field) {
$collection->addOrder(
$field,
($sortOrder->getDirection() == SortOrder::SORT_ASC) ? 'ASC' : 'DESC'
);
}
}
Metadata
Metadata
Assignees
Labels
Fixed in 2.2.xThe issue has been fixed in 2.2 release lineThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is not validGate 1 Failed. Automatic verification of issue format is failedGate 1 Failed. Automatic verification of issue format is failedReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseThe issue has been reproduced on latest 2.2 release