Skip to content

Commit 75d1e40

Browse files
authored
Merge pull request #1212 from magento-nord/NORD-FIXES
Fixed isues: - MAGETWO-69946 Product list widget is not working with SKU field
2 parents 09a4858 + 4eb8398 commit 75d1e40

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ protected function addNotGlobalAttribute(
222222
public function getMappedSqlField()
223223
{
224224
$result = '';
225-
if ($this->getAttribute() == 'category_ids') {
225+
if (in_array($this->getAttribute(), ['category_ids', 'sku'])) {
226226
$result = parent::getMappedSqlField();
227227
} elseif (isset($this->joinedAttributes[$this->getAttribute()])) {
228228
$result = $this->joinedAttributes[$this->getAttribute()];

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ protected function setUp()
3636
'',
3737
false
3838
);
39-
$eavConfig->expects($this->once())->method('getAttribute')->willReturn($this->attributeMock);
39+
$eavConfig->expects($this->any())->method('getAttribute')->willReturn($this->attributeMock);
4040
$ruleMock = $this->getMock(\Magento\SalesRule\Model\Rule::class, [], [], '', false);
4141
$storeManager = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class);
4242
$storeMock = $this->getMock(\Magento\Store\Api\Data\StoreInterface::class);
43-
$storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
43+
$storeManager->expects($this->any())->method('getStore')->willReturn($storeMock);
4444
$this->resourceMock = $this->getMock(
4545
\Magento\Indexer\Model\ResourceModel\FrontendResource::class,
4646
[],
@@ -49,8 +49,8 @@ protected function setUp()
4949
false
5050
);
5151
$productResource = $this->getMock(\Magento\Catalog\Model\ResourceModel\Product::class, [], [], '', false);
52-
$productResource->expects($this->once())->method('loadAllAttributes')->willReturnSelf();
53-
$productResource->expects($this->once())->method('getAttributesByCode')->willReturn([]);
52+
$productResource->expects($this->any())->method('loadAllAttributes')->willReturnSelf();
53+
$productResource->expects($this->any())->method('getAttributesByCode')->willReturn([]);
5454
$this->model = $objectManagerHelper->getObject(
5555
\Magento\CatalogWidget\Model\Rule\Condition\Product::class,
5656
[
@@ -88,4 +88,10 @@ public function testAddToCollection()
8888
$this->resourceMock->expects($this->once())->method('getMainTable')->willReturn('catalog_product_index_eav');
8989
$this->model->addToCollection($collectionMock);
9090
}
91+
92+
public function testGetMappedSqlFieldSku()
93+
{
94+
$this->model->setAttribute('sku');
95+
$this->assertEquals('e.sku', $this->model->getMappedSqlField());
96+
}
9197
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,13 @@ public function testGetMappedSqlFieldCategoryIdsAttribute()
9494
$this->conditionProduct->setAttribute('category_ids');
9595
$this->assertEquals('e.entity_id', $this->conditionProduct->getMappedSqlField());
9696
}
97+
98+
/**
99+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
100+
*/
101+
public function testGetMappedSqlFieldSkuAttribute()
102+
{
103+
$this->conditionProduct->setAttribute('sku');
104+
$this->assertEquals('e.sku', $this->conditionProduct->getMappedSqlField());
105+
}
97106
}

0 commit comments

Comments
 (0)