Skip to content

Commit b75955f

Browse files
committed
Merge remote-tracking branch 'tango/MAGETWO-94080' into TANGO-PR-22
2 parents e5df24d + 6ef2a2e commit b75955f

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,22 @@ public function addToCollection($collection)
124124
{
125125
$attribute = $this->getAttributeObject();
126126

127-
if ($attribute->getUsedInProductListing() && $collection->isEnabledFlat()) {
128-
$alias = array_keys($collection->getSelect()->getPart('from'))[0];
129-
$this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.' . $attribute->getAttributeCode();
127+
if ($collection->isEnabledFlat()) {
128+
if ($this->isEnabledInFlat($attribute)) {
129+
$alias = array_keys($collection->getSelect()->getPart('from'))[0];
130+
$this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.' . $attribute->getAttributeCode();
131+
} else {
132+
$alias = 'at_' . $attribute->getAttributeCode();
133+
if (!in_array($alias, array_keys($collection->getSelect()->getPart('from')))) {
134+
$collection->joinAttribute(
135+
$attribute->getAttributeCode(),
136+
'catalog_product/'.$attribute->getAttributeCode(),
137+
'entity_id'
138+
);
139+
}
140+
141+
$this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.value';
142+
}
130143
return $this;
131144
}
132145

@@ -245,4 +258,15 @@ public function collectValidatedAttributes($productCollection)
245258
{
246259
return $this->addToCollection($productCollection);
247260
}
261+
262+
/**
263+
* @param \Magento\Framework\DataObject $attribute
264+
* @return bool
265+
*/
266+
private function isEnabledInFlat(\Magento\Framework\DataObject $attribute): bool
267+
{
268+
return $attribute->getData('backend_type') === 'static'
269+
|| (int) $attribute->getData('used_in_product_listing') === 1
270+
|| (int) $attribute->getData('used_for_sort_by') === 1;
271+
}
248272
}

dev/tests/integration/testsuite/Magento/CatalogWidget/Block/Product/ProductListTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ public function testCreateCollectionWithMultipleSkuCondition()
8989
}
9090

9191
/**
92-
* Test product list widget can process condition with dropdown type of attribute which has Store Scope
92+
* Test product list widget can process condition with dropdown type of attribute
9393
*
9494
* @magentoDbIsolation disabled
9595
* @magentoDataFixture Magento/Catalog/_files/products_with_dropdown_attribute.php
9696
*/
97-
public function testCreateCollectionWithDropdownAttributeStoreScope()
97+
public function testCreateCollectionWithDropdownAttribute()
9898
{
9999
/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
100100
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
@@ -118,6 +118,9 @@ public function testCreateCollectionWithDropdownAttributeStoreScope()
118118
$attribute->setUsedInProductListing(0);
119119
$attribute->save();
120120
$this->performAssertions(2);
121+
$attribute->setIsGlobal(1);
122+
$attribute->save();
123+
$this->performAssertions(2);
121124
}
122125

123126
/**

0 commit comments

Comments
 (0)