33 '!=' =>
':field <> ?',
34 '>=' =>
':field >= ?',
36 '<=' =>
':field <= ?',
38 '{}' =>
':field IN (?)',
39 '!{}' =>
':field NOT IN (?)',
40 '()' =>
':field IN (?)',
41 '!()' =>
':field NOT IN (?)',
47 private $stringConditionOperatorMap = [
48 '{}' =>
':field LIKE ?',
49 '!{}' =>
':field NOT LIKE ?',
60 private $attributeRepository;
67 ExpressionFactory $expressionFactory,
70 $this->_expressionFactory = $expressionFactory;
71 $this->attributeRepository = $attributeRepository ?:
83 $tables = $this->_getChildCombineTablesToJoin($combine);
94 protected function _getChildCombineTablesToJoin(
Combine $combine, $tables = [])
97 if ($condition->getConditions()) {
98 $tables = $this->_getChildCombineTablesToJoin($condition);
101 foreach ($condition->getTablesToJoin() as
$alias =>
$table) {
102 if (!isset($tables[
$alias])) {
118 protected function _joinTablesToCollection(
126 $joinTable[
'condition'],
127 isset($joinTable[
'columns']) ? $joinTable[
'columns'] :
'*' 147 bool $isDefaultStoreUsed =
true 152 if (empty($argument)) {
153 return $this->_expressionFactory->create([
'expression' =>
'1 = -1']);
158 if (!isset($this->_conditionOperatorMap[$conditionOperator])) {
159 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Unknown condition operator'));
166 && in_array($conditionOperator, array_keys($this->stringConditionOperatorMap),
true)
170 $this->_connection->getIfNullSql($this->_connection->quoteIdentifier($argument), $defaultValue),
171 $this->stringConditionOperatorMap[$conditionOperator]
174 $expression =
$value . $this->_connection->quoteInto($sql,
"%$bindValue%");
178 $this->_connection->getIfNullSql($this->_connection->quoteIdentifier($argument), $defaultValue),
179 $this->_conditionOperatorMap[$conditionOperator]
182 $expression =
$value . $this->_connection->quoteInto($sql, $bindValue);
186 if (is_array($bindValue) && \in_array($conditionOperator, [
'()',
'{}'],
true)) {
187 foreach ($bindValue as
$item) {
188 $expression .= $this->_connection->quoteInto(
189 " OR (FIND_IN_SET (?, {$this->_connection->quoteIdentifier($argument)}) > 0)",
195 return $this->_expressionFactory->create(
196 [
'expression' => $expression]
210 protected function _getMappedSqlCombination(
213 bool $isDefaultStoreUsed =
true 217 $getAggregator = $combine->getAggregator();
219 foreach ($conditions as $key => $condition) {
222 $con = (isset($conditions[$key+1]) ? $con :
'');
223 if ($condition instanceof
Combine) {
224 $out .= $this->_getMappedSqlCombination($condition,
$value, $isDefaultStoreUsed);
228 $out .= $out ? (
' ' . $con) :
'';
231 return $this->_expressionFactory->create([
'expression' => $out]);
245 $this->_connection =
$collection->getResource()->getConnection();
246 $this->_joinTablesToCollection(
$collection, $combine);
247 $whereExpression = (string)$this->_getMappedSqlCombination($combine);
248 if (!empty($whereExpression)) {
__construct(ExpressionFactory $expressionFactory, AttributeRepositoryInterface $attributeRepository=null)
_getCombineTablesToJoin(Combine $combine)
_getMappedSqlCondition(AbstractCondition $condition, string $value='', bool $isDefaultStoreUsed=true)
attachConditionToCollection(AbstractCollection $collection, Combine $combine)