Skip to content

Commit b07ec00

Browse files
MAGETWO-93173: [2.3] Widget selection by Enabled Products causes a fatal on Storefront in case of "Flat Product" configuration
1 parent 1cb9235 commit b07ec00

File tree

2 files changed

+30
-9
lines changed
  • app/code/Magento/CatalogWidget/Model/Rule/Condition
  • dev/tests/integration/testsuite/Magento/CatalogWidget/Model/Rule/Condition

2 files changed

+30
-9
lines changed

app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
namespace Magento\CatalogWidget\Model\Rule\Condition;
1111

12+
use Magento\Catalog\Api\Data\ProductInterface;
1213
use Magento\Catalog\Model\ProductCategoryList;
1314

1415
/**
@@ -77,17 +78,22 @@ public function __construct(
7778
}
7879

7980
/**
80-
* {@inheritdoc}
81+
* @inheritdoc
8182
*/
8283
public function loadAttributeOptions()
8384
{
8485
$productAttributes = $this->_productResource->loadAllAttributes()->getAttributesByCode();
86+
$productAttributes = array_filter(
87+
$productAttributes,
88+
function ($attribute) {
89+
return $attribute->getFrontendLabel() &&
90+
$attribute->getFrontendInput() !== 'text' &&
91+
$attribute->getAttributeCode() !== ProductInterface::STATUS;
92+
}
93+
);
8594

8695
$attributes = [];
8796
foreach ($productAttributes as $attribute) {
88-
if (!$attribute->getFrontendLabel() || $attribute->getFrontendInput() == 'text') {
89-
continue;
90-
}
9197
$attributes[$attribute->getAttributeCode()] = $attribute->getFrontendLabel();
9298
}
9399

@@ -100,7 +106,7 @@ public function loadAttributeOptions()
100106
}
101107

102108
/**
103-
* {@inheritdoc}
109+
* @inheritdoc
104110
*/
105111
protected function _addSpecialAttributes(array &$attributes)
106112
{
@@ -224,7 +230,7 @@ protected function addNotGlobalAttribute(
224230
}
225231

226232
/**
227-
* {@inheritdoc}
233+
* @inheritdoc
228234
*/
229235
public function getMappedSqlField()
230236
{
@@ -243,7 +249,7 @@ public function getMappedSqlField()
243249
}
244250

245251
/**
246-
* {@inheritdoc}
252+
* @inheritdoc
247253
*/
248254
public function collectValidatedAttributes($productCollection)
249255
{

dev/tests/integration/testsuite/Magento/CatalogWidget/Model/Rule/Condition/ProductTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\CatalogWidget\Model\Rule\Condition;
88

9+
use Magento\Catalog\Api\Data\ProductInterface;
10+
911
class ProductTest extends \PHPUnit\Framework\TestCase
1012
{
1113
/**
@@ -18,6 +20,9 @@ class ProductTest extends \PHPUnit\Framework\TestCase
1820
*/
1921
protected $objectManager;
2022

23+
/**
24+
* @inheritdoc
25+
*/
2126
protected function setUp()
2227
{
2328
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
@@ -28,19 +33,26 @@ protected function setUp()
2833
$this->conditionProduct->setRule($rule);
2934
}
3035

36+
/**
37+
* @return void
38+
*/
3139
public function testLoadAttributeOptions()
3240
{
3341
$this->conditionProduct->loadAttributeOptions();
3442
$options = $this->conditionProduct->getAttributeOption();
35-
$this->assertArrayHasKey('sku', $options);
36-
$this->assertArrayHasKey('attribute_set_id', $options);
43+
$this->assertArrayHasKey(ProductInterface::SKU, $options);
44+
$this->assertArrayHasKey(ProductInterface::ATTRIBUTE_SET_ID, $options);
3745
$this->assertArrayHasKey('category_ids', $options);
46+
$this->assertArrayNotHasKey(ProductInterface::STATUS, $options);
3847
foreach ($options as $code => $label) {
3948
$this->assertNotEmpty($label);
4049
$this->assertNotEmpty($code);
4150
}
4251
}
4352

53+
/**
54+
* @return void
55+
*/
4456
public function testAddGlobalAttributeToCollection()
4557
{
4658
$collection = $this->objectManager->create(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
@@ -53,6 +65,9 @@ public function testAddGlobalAttributeToCollection()
5365
$this->assertEquals('at_special_price.value', $this->conditionProduct->getMappedSqlField());
5466
}
5567

68+
/**
69+
* @return void
70+
*/
5671
public function testAddNonGlobalAttributeToCollectionNoProducts()
5772
{
5873
$collection = $this->objectManager->create(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);

0 commit comments

Comments
 (0)