Skip to content

Commit 0e121ab

Browse files
author
Stanislav Idolov
authored
ENGCOM-1250: Use LEFT JOIN When Checking for null Attributes #14356
2 parents 208aed4 + e4d9338 commit 0e121ab

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,10 @@ protected function _getAttributeConditionSql($attribute, $condition, $joinType =
14981498
$condition
14991499
);
15001500
} else {
1501+
if (isset($condition['null'])) {
1502+
$joinType = 'left';
1503+
}
1504+
15011505
$this->_addAttributeJoin($attribute, $joinType);
15021506
if (isset($this->_joinAttributes[$attribute]['condition_alias'])) {
15031507
$field = $this->_joinAttributes[$attribute]['condition_alias'];

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/CollectionTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,20 @@ public function testJoinTable()
149149

150150
self::assertContains($expected, str_replace(PHP_EOL, '', $sql));
151151
}
152+
153+
/**
154+
* Checks that a collection uses the correct join when filtering by null.
155+
*
156+
* This actually affects AbstractCollection, but inheritance yada yada.
157+
*
158+
* @magentoDataFixture Magento/Catalog/Model/ResourceModel/_files/product_simple.php
159+
* @magentoDbIsolation enabled
160+
*/
161+
public function testFilterByNull()
162+
{
163+
$this->collection->addAttributeToFilter([['attribute' => 'special_price', 'null' => true]]);
164+
$productCount = $this->collection->count();
165+
166+
$this->assertEquals(1, $productCount, 'Product with null special_price not found');
167+
}
152168
}

0 commit comments

Comments
 (0)