diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php b/app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php index 90b206e5a6091..b29dba4c75665 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php @@ -230,6 +230,16 @@ public function afterSave() return parent::afterSave(); } + /** + * Is attribute enabled for flat indexing + * + * @return bool + */ + public function isEnabledInFlat() + { + return $this->_isEnabledInFlat(); + } + /** * Is attribute enabled for flat indexing * diff --git a/app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php b/app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php index 9c679b8bfe9b0..f22879df0ae0c 100644 --- a/app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php +++ b/app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php @@ -119,8 +119,21 @@ public function addToCollection($collection) $attribute = $this->getAttributeObject(); if ($collection->isEnabledFlat()) { - $alias = array_keys($collection->getSelect()->getPart('from'))[0]; - $this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.' . $attribute->getAttributeCode(); + if ($attribute->isEnabledInFlat()) { + $alias = array_keys($collection->getSelect()->getPart('from'))[0]; + $this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.' . $attribute->getAttributeCode(); + } else { + $alias = 'at_' . $attribute->getAttributeCode(); + if (!in_array($alias, array_keys($collection->getSelect()->getPart('from')))) { + $collection->joinAttribute( + $attribute->getAttributeCode(), + 'catalog_product/'.$attribute->getAttributeCode(), + 'entity_id' + ); + } + + $this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.value'; + } return $this; }