Skip to content

Commit 8c8f257

Browse files
committed
MC-30262: Inventory Sources and Stock is breaking the Category and CMS
1 parent 5ad40fa commit 8c8f257

File tree

4 files changed

+130
-79
lines changed

4 files changed

+130
-79
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
use Magento\Store\Model\Store;
1515

1616
/**
17-
* Class Product
17+
* Rule product condition data model
18+
*
1819
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1920
*/
2021
class Product extends \Magento\Rule\Model\Condition\Product\AbstractProduct
@@ -250,7 +251,7 @@ protected function addNotGlobalAttribute(
250251
public function getMappedSqlField()
251252
{
252253
$result = '';
253-
if (in_array($this->getAttribute(), ['category_ids', 'sku'])) {
254+
if (in_array($this->getAttribute(), ['category_ids', 'sku', 'attribute_set_id'])) {
254255
$result = parent::getMappedSqlField();
255256
} elseif (isset($this->joinedAttributes[$this->getAttribute()])) {
256257
$result = $this->joinedAttributes[$this->getAttribute()];

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

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,65 @@
55
*/
66
namespace Magento\CatalogWidget\Test\Unit\Model\Rule\Condition;
77

8+
use Magento\Catalog\Model\ProductCategoryList;
9+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
10+
use Magento\Catalog\Model\ResourceModel\Product;
11+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
12+
use Magento\CatalogWidget\Model\Rule\Condition\Product as ProductWidget;
13+
use Magento\Eav\Model\Config;
14+
use Magento\Eav\Model\Entity\AbstractEntity;
15+
use Magento\Framework\DB\Adapter\AdapterInterface;
16+
use Magento\Framework\DB\Select;
817
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
18+
use Magento\SalesRule\Model\Rule;
19+
use Magento\Store\Api\Data\StoreInterface;
20+
use Magento\Store\Model\StoreManagerInterface;
21+
use PHPUnit\Framework\MockObject\MockObject;
22+
use PHPUnit\Framework\TestCase;
923

1024
/**
1125
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1226
*/
13-
class ProductTest extends \PHPUnit\Framework\TestCase
27+
class ProductTest extends TestCase
1428
{
1529
/**
16-
* @var \Magento\CatalogWidget\Model\Rule\Condition\Product
30+
* @var ProductWidget
1731
*/
1832
private $model;
1933

2034
/**
21-
* @var \Magento\Catalog\Model\ResourceModel\Product|\PHPUnit_Framework_MockObject_MockObject
35+
* @var MockObject
2236
*/
23-
private $productResource;
37+
private $attributeMock;
2438

2539
/**
26-
* @var \PHPUnit_Framework_MockObject_MockObject
40+
* @var Product|MockObject
2741
*/
28-
private $attributeMock;
42+
private $productResource;
2943

3044
/**
3145
* @inheritdoc
32-
*
33-
* @return void
3446
*/
3547
protected function setUp()
3648
{
3749
$objectManagerHelper = new ObjectManager($this);
3850

39-
$eavConfig = $this->createMock(\Magento\Eav\Model\Config::class);
40-
$this->attributeMock = $this->createMock(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class);
51+
$eavConfig = $this->createMock(Config::class);
52+
$this->attributeMock = $this->createMock(Attribute::class);
4153
$eavConfig->expects($this->any())->method('getAttribute')->willReturn($this->attributeMock);
42-
$ruleMock = $this->createMock(\Magento\SalesRule\Model\Rule::class);
43-
$storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
44-
$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
54+
$ruleMock = $this->createMock(Rule::class);
55+
$storeManager = $this->createMock(StoreManagerInterface::class);
56+
$storeMock = $this->createMock(StoreInterface::class);
4557
$storeManager->expects($this->any())->method('getStore')->willReturn($storeMock);
46-
$this->productResource = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product::class);
58+
$this->productResource = $this->createMock(Product::class);
4759
$this->productResource->expects($this->once())->method('loadAllAttributes')->willReturnSelf();
4860
$this->productResource->expects($this->once())->method('getAttributesByCode')->willReturn([]);
49-
$productCategoryList = $this->getMockBuilder(\Magento\Catalog\Model\ProductCategoryList::class)
61+
$productCategoryList = $this->getMockBuilder(ProductCategoryList::class)
5062
->disableOriginalConstructor()
5163
->getMock();
5264

5365
$this->model = $objectManagerHelper->getObject(
54-
\Magento\CatalogWidget\Model\Rule\Condition\Product::class,
66+
ProductWidget::class,
5567
[
5668
'config' => $eavConfig,
5769
'storeManager' => $storeManager,
@@ -72,8 +84,8 @@ protected function setUp()
7284
*/
7385
public function testAddToCollection()
7486
{
75-
$collectionMock = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
76-
$selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
87+
$collectionMock = $this->createMock(Collection::class);
88+
$selectMock = $this->createMock(Select::class);
7789
$collectionMock->expects($this->once())->method('getSelect')->willReturn($selectMock);
7890
$selectMock->expects($this->any())->method('join')->willReturnSelf();
7991
$this->attributeMock->expects($this->any())->method('getAttributeCode')->willReturn('code');
@@ -83,10 +95,10 @@ public function testAddToCollection()
8395
$this->attributeMock->expects($this->once())->method('isScopeGlobal')->willReturn(true);
8496
$this->attributeMock->expects($this->once())->method('getBackendType')->willReturn('multiselect');
8597

86-
$entityMock = $this->createMock(\Magento\Eav\Model\Entity\AbstractEntity::class);
98+
$entityMock = $this->createMock(AbstractEntity::class);
8799
$entityMock->expects($this->once())->method('getLinkField')->willReturn('entitiy_id');
88100
$this->attributeMock->expects($this->once())->method('getEntity')->willReturn($entityMock);
89-
$connection = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
101+
$connection = $this->createMock(AdapterInterface::class);
90102

91103
$this->productResource->expects($this->atLeastOnce())->method('getConnection')->willReturn($connection);
92104

@@ -102,5 +114,7 @@ public function testGetMappedSqlFieldSku()
102114
{
103115
$this->model->setAttribute('sku');
104116
$this->assertEquals('e.sku', $this->model->getMappedSqlField());
117+
$this->model->setAttribute('attribute_set_id');
118+
$this->assertEquals('e.attribute_set_id', $this->model->getMappedSqlField());
105119
}
106120
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ public function getMappedSqlField()
625625
$mappedSqlField = $this->getEavAttributeTableAlias() . '.value';
626626
} elseif ($this->getAttribute() == 'category_ids') {
627627
$mappedSqlField = 'e.entity_id';
628+
} elseif ($this->getAttribute() == 'attribute_set_id') {
629+
$mappedSqlField = 'e.attribute_set_id';
628630
} else {
629631
$mappedSqlField = parent::getMappedSqlField();
630632
}

0 commit comments

Comments
 (0)