Skip to content

Commit 5fb691c

Browse files
committed
ACP2E-448: [Page Builder] Product widget preview breaks for bundle products
- With test
1 parent 81340cb commit 5fb691c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection/FilterApplier.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Bundle\Model\ResourceModel\Selection\Collection;
77

88
use Magento\Bundle\Model\ResourceModel\Selection\Collection;
9+
use Zend_Db_Select_Exception;
910

1011
/**
1112
* An applier of additional filters to a selection collection.
@@ -32,16 +33,17 @@ class FilterApplier
3233
* @param string $conditionType
3334
*
3435
* @return void
36+
* @throws Zend_Db_Select_Exception
3537
*/
36-
public function apply(Collection $collection, $field, $value, $conditionType = 'eq')
38+
public function apply(Collection $collection, string $field, $value, string $conditionType = 'eq')
3739
{
3840
foreach ($collection->getSelect()->getPart('from') as $tableAlias => $data) {
3941
if ($data['tableName'] == $collection->getTable('catalog_product_bundle_selection')) {
4042
$field = $tableAlias . '.' . $field;
4143
}
4244
}
4345

44-
$collection->getSelect()
46+
$collection->getSelect()->distinct(true)
4547
->where($field . $this->conditionTypesMap[$conditionType], $value);
4648
}
4749
}

app/code/Magento/Bundle/Test/Unit/Model/ResourceModel/Selection/Collection/FilterApplierTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
namespace Magento\Bundle\Test\Unit\Model\ResourceModel\Selection\Collection;
99

10+
use Magento\Bundle\Model\ResourceModel\Selection\Collection;
1011
use Magento\Bundle\Model\ResourceModel\Selection\Collection\FilterApplier;
1112
use Magento\Framework\DB\Select;
1213
use PHPUnit\Framework\TestCase;
14+
use Zend_Db_Select_Exception;
1315

1416
/**
1517
* Test selection collection filter applier
@@ -37,12 +39,13 @@ protected function setUp(): void
3739
* @param $expectedCondition
3840
* @param $expectedValue
3941
* @dataProvider applyDataProvider
42+
* @throws Zend_Db_Select_Exception
4043
*/
4144
public function testApply($field, $value, $conditionType, $expectedCondition, $expectedValue): void
4245
{
4346
$tableName = 'catalog_product_bundle_selection';
4447
$select = $this->createMock(Select::class);
45-
$collection = $this->createMock(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class);
48+
$collection = $this->createMock(Collection::class);
4649
$collection->method('getSelect')
4750
->willReturn($select);
4851
$collection->method('getTable')
@@ -60,6 +63,10 @@ public function testApply($field, $value, $conditionType, $expectedCondition, $e
6063
]
6164
]
6265
);
66+
$select->expects($this->once())
67+
->method('distinct')
68+
->with(true)
69+
->willReturnSelf();
6370
$select->expects($this->once())
6471
->method('where')
6572
->with($expectedCondition, $expectedValue);

0 commit comments

Comments
 (0)