Skip to content

Commit 566902e

Browse files
committed
Merge remote-tracking branch 'goinc/MAGETWO-51956' into pr-613
2 parents 8ca1d0c + f6c1d93 commit 566902e

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ public function getNewChildSelectOptions()
7171
*/
7272
public function collectValidatedAttributes($productCollection)
7373
{
74-
$alias = array_keys($productCollection->getSelect()->getPart('from'))[0];
7574
foreach ($this->getConditions() as $condition) {
76-
$condition->setData('attribute', $alias . '.' . $condition->getData('attribute'));
7775
$condition->addToCollection($productCollection);
7876
}
7977
return $this;

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ protected function _addSpecialAttributes(array &$attributes)
112112
public function addToCollection($collection)
113113
{
114114
$attribute = $this->getAttributeObject();
115+
116+
if ($collection->isEnabledFlat()) {
117+
$alias = array_keys($collection->getSelect()->getPart('from'))[0];
118+
$this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.' . $attribute->getAttributeCode();
119+
return $this;
120+
}
121+
115122
if ('category_ids' == $attribute->getAttributeCode() || $attribute->isStatic()) {
116123
return $this;
117124
}
@@ -157,7 +164,7 @@ protected function addGlobalAttribute(
157164
);
158165
}
159166

160-
$this->joinedAttributes[$attribute->getAttributeCode()] = $alias;
167+
$this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.value';
161168

162169
return $this;
163170
}
@@ -206,14 +213,10 @@ public function getMappedSqlField()
206213
$result = '';
207214
if ($this->getAttribute() == 'category_ids') {
208215
$result = parent::getMappedSqlField();
216+
} elseif (isset($this->joinedAttributes[$this->getAttribute()])) {
217+
$result = $this->joinedAttributes[$this->getAttribute()];
209218
} elseif ($this->getAttributeObject()->isStatic()) {
210219
$result = $this->getAttributeObject()->getAttributeCode();
211-
} elseif ($this->getAttributeObject()->isScopeGlobal()) {
212-
if (isset($this->joinedAttributes[$this->getAttribute()])) {
213-
$result = $this->joinedAttributes[$this->getAttribute()] . '.value';
214-
} else {
215-
$result = parent::getMappedSqlField();
216-
}
217220
} elseif ($this->getValueParsed()) {
218221
$result = 'e.entity_id';
219222
}

app/code/Magento/CatalogWidget/Test/Unit/Model/Rule/Condition/CombineTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,9 @@ public function testGetNewChildSelectOptions()
7272

7373
public function testCollectValidatedAttributes()
7474
{
75-
$collection = $this->getMockBuilder('\Magento\Catalog\Model\ResourceModel\Product\Collection')
76-
->disableOriginalConstructor()->setMethods(['getSelect'])
77-
->getMock();
78-
$select = $this->getMockBuilder('\Magento\Framework\DB\Select')
79-
->disableOriginalConstructor()->setMethods(['getPart'])
75+
$collection = $this->getMockBuilder('Magento\Catalog\Model\ResourceModel\Product\Collection')
76+
->disableOriginalConstructor()
8077
->getMock();
81-
$select->expects($this->any())->method('getPart')->with('from')->willReturn(['alias_table' => 'table_name']);
82-
$collection->expects($this->any())->method('getSelect')->willReturn($select);
8378
$condition = $this->getMockBuilder('Magento\CatalogWidget\Model\Rule\Condition\Combine')
8479
->disableOriginalConstructor()->setMethods(['addToCollection'])
8580
->getMock();

0 commit comments

Comments
 (0)