From a6b32299b511997d700caf47820624e86dd8bc64 Mon Sep 17 00:00:00 2001 From: Alex Bomko Date: Sat, 17 Jun 2017 21:50:25 +0300 Subject: [PATCH] MAGETWO-69946: Product list widget is not working with SKU field --- .../CatalogWidget/Model/Rule/Condition/Product.php | 2 +- .../Test/Unit/Model/Rule/Condition/ProductTest.php | 14 ++++++++++---- .../Model/Rule/Condition/ProductTest.php | 9 +++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php b/app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php index 07d0bf6b588b6..63e5f6b4f8de7 100644 --- a/app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php +++ b/app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php @@ -222,7 +222,7 @@ protected function addNotGlobalAttribute( public function getMappedSqlField() { $result = ''; - if ($this->getAttribute() == 'category_ids') { + if (in_array($this->getAttribute(), ['category_ids', 'sku'])) { $result = parent::getMappedSqlField(); } elseif (isset($this->joinedAttributes[$this->getAttribute()])) { $result = $this->joinedAttributes[$this->getAttribute()]; diff --git a/app/code/Magento/CatalogWidget/Test/Unit/Model/Rule/Condition/ProductTest.php b/app/code/Magento/CatalogWidget/Test/Unit/Model/Rule/Condition/ProductTest.php index b878e483cc1fa..8777828a8c4d4 100644 --- a/app/code/Magento/CatalogWidget/Test/Unit/Model/Rule/Condition/ProductTest.php +++ b/app/code/Magento/CatalogWidget/Test/Unit/Model/Rule/Condition/ProductTest.php @@ -36,11 +36,11 @@ protected function setUp() '', false ); - $eavConfig->expects($this->once())->method('getAttribute')->willReturn($this->attributeMock); + $eavConfig->expects($this->any())->method('getAttribute')->willReturn($this->attributeMock); $ruleMock = $this->getMock(\Magento\SalesRule\Model\Rule::class, [], [], '', false); $storeManager = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class); $storeMock = $this->getMock(\Magento\Store\Api\Data\StoreInterface::class); - $storeManager->expects($this->once())->method('getStore')->willReturn($storeMock); + $storeManager->expects($this->any())->method('getStore')->willReturn($storeMock); $this->resourceMock = $this->getMock( \Magento\Indexer\Model\ResourceModel\FrontendResource::class, [], @@ -49,8 +49,8 @@ protected function setUp() false ); $productResource = $this->getMock(\Magento\Catalog\Model\ResourceModel\Product::class, [], [], '', false); - $productResource->expects($this->once())->method('loadAllAttributes')->willReturnSelf(); - $productResource->expects($this->once())->method('getAttributesByCode')->willReturn([]); + $productResource->expects($this->any())->method('loadAllAttributes')->willReturnSelf(); + $productResource->expects($this->any())->method('getAttributesByCode')->willReturn([]); $this->model = $objectManagerHelper->getObject( \Magento\CatalogWidget\Model\Rule\Condition\Product::class, [ @@ -88,4 +88,10 @@ public function testAddToCollection() $this->resourceMock->expects($this->once())->method('getMainTable')->willReturn('catalog_product_index_eav'); $this->model->addToCollection($collectionMock); } + + public function testGetMappedSqlFieldSku() + { + $this->model->setAttribute('sku'); + $this->assertEquals('e.sku', $this->model->getMappedSqlField()); + } } diff --git a/dev/tests/integration/testsuite/Magento/CatalogWidget/Model/Rule/Condition/ProductTest.php b/dev/tests/integration/testsuite/Magento/CatalogWidget/Model/Rule/Condition/ProductTest.php index 5244ee174434e..01c22db7fe9a2 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogWidget/Model/Rule/Condition/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogWidget/Model/Rule/Condition/ProductTest.php @@ -94,4 +94,13 @@ public function testGetMappedSqlFieldCategoryIdsAttribute() $this->conditionProduct->setAttribute('category_ids'); $this->assertEquals('e.entity_id', $this->conditionProduct->getMappedSqlField()); } + + /** + * @magentoDataFixture Magento/Catalog/_files/product_simple.php + */ + public function testGetMappedSqlFieldSkuAttribute() + { + $this->conditionProduct->setAttribute('sku'); + $this->assertEquals('e.sku', $this->conditionProduct->getMappedSqlField()); + } }