Closed
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
The issue has been fixed in 2.2 release lineThe issue has been fixed in 2.3 release lineGate 2 Passed. Manual verification of the issue description passedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Failed. Automatic verification of issue format is failedThe issue has been reproduced on latest 2.1 releaseThe issue has been reproduced on latest 2.2 release