Skip to content

Commit 10adf8c

Browse files
committed
ACP2E-2053: Unable to save products with different attribute sets in Async bulk REST API
1 parent e2b98b7 commit 10adf8c

File tree

2 files changed

+26
-79
lines changed

2 files changed

+26
-79
lines changed

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/AbstractTest.php

Lines changed: 15 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,15 @@
1010
*/
1111
namespace Magento\Catalog\Test\Unit\Model\ResourceModel;
1212

13-
use Magento\Catalog\Model\Factory;
1413
use Magento\Catalog\Model\Product;
1514
use Magento\Catalog\Model\ResourceModel\AbstractResource;
1615
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
17-
use Magento\Eav\Model\Entity\Attribute\Set;
18-
use Magento\Eav\Model\Entity\Attribute\UniqueValidationInterface;
19-
use Magento\Eav\Model\Entity\Context;
2016
use Magento\Framework\DataObject;
21-
use Magento\Store\Model\StoreManagerInterface;
22-
use PHPUnit\Framework\MockObject\MockObject;
17+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2318
use PHPUnit\Framework\TestCase;
2419

2520
class AbstractTest extends TestCase
2621
{
27-
/**
28-
* @var Context|MockObject
29-
*/
30-
private $context;
31-
32-
/**
33-
* @var StoreManagerInterface|MockObject
34-
*/
35-
private $storeManager;
36-
37-
/**
38-
* @var Factory|MockObject
39-
*/
40-
private $modelFactory;
41-
42-
/**
43-
* @var UniqueValidationInterface|MockObject
44-
*/
45-
private $uniqueValidator;
46-
47-
/**
48-
* @var AbstractResource|MockObject
49-
*/
50-
private $model;
51-
52-
/**
53-
* @inheritDoc
54-
*/
55-
protected function setUp(): void
56-
{
57-
parent::setUp();
58-
$this->context = $this->createMock(Context::class);
59-
$this->storeManager = $this->createMock(StoreManagerInterface::class);
60-
$this->modelFactory = $this->createMock(Factory::class);
61-
$this->uniqueValidator = $this->createMock(UniqueValidationInterface::class);
62-
}
63-
6422
/**
6523
* Get attribute list
6624
*
@@ -89,6 +47,8 @@ protected function _getAttributes()
8947

9048
public function testWalkAttributes()
9149
{
50+
$objectManager = new ObjectManager($this);
51+
9252
$code = 'test_attr';
9353
$set = 10;
9454
$storeId = 100;
@@ -125,33 +85,17 @@ public function testWalkAttributes()
12585

12686
$attributes[$code] = $attribute;
12787

128-
$attrSetEntity = $this->createMock(Set::class);
129-
$this->context->method('getAttributeSetEntity')
130-
->willReturn($attrSetEntity);
131-
$attrSetEntity->expects($this->once())
132-
->method('addSetInfo')
133-
->with($entityType, $attributes, $set);
134-
135-
$this->model = $this->getMockBuilder(AbstractResource::class)
136-
->setConstructorArgs(
137-
[
138-
$this->context,
139-
$this->storeManager,
140-
$this->modelFactory,
141-
[],
142-
$this->uniqueValidator
143-
]
144-
)
145-
->onlyMethods(['getAttributesByCode', 'getEntityType'])
146-
->getMockForAbstractClass();
147-
148-
$this->model->expects($this->once())
149-
->method('getAttributesByCode')
150-
->willReturn($attributes);
151-
$this->model->expects($this->once())
152-
->method('getEntityType')
153-
->willReturn($entityType);
154-
155-
$this->model->walkAttributes('backend/afterSave', [$object]);
88+
/** @var AbstractResource $model */
89+
$arguments = $objectManager->getConstructArguments(
90+
AbstractResource::class
91+
);
92+
$model = $this->getMockBuilder(AbstractResource::class)
93+
->setMethods(['getAttributesByCode'])
94+
->setConstructorArgs($arguments)
95+
->getMock();
96+
97+
$model->expects($this->once())->method('getAttributesByCode')->willReturn($attributes);
98+
99+
$model->walkAttributes('backend/afterSave', [$object]);
156100
}
157101
}

app/code/Magento/Eav/Model/Entity/AbstractEntity.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,16 @@ public function isPartialSave($flag = null)
553553
*/
554554
public function loadAllAttributes($object = null)
555555
{
556-
return $this->attributeLoader->loadAllAttributes($this, $object);
556+
$result = $this->attributeLoader->loadAllAttributes($this, $object);
557+
if ($object instanceof DataObject && $object->getAttributeSetId()) {
558+
$suffix = $this->getAttributesCacheSuffix($object);
559+
$this->_attrSetEntity->addSetInfo(
560+
$this->getEntityType(),
561+
$this->getAttributesByScope($suffix),
562+
$object->getAttributeSetId()
563+
);
564+
}
565+
return $result;
557566
}
558567

559568
/**
@@ -650,14 +659,8 @@ public function walkAttributes($partMethod, array $args = [], $collectExceptionM
650659
}
651660
$results = [];
652661
$suffix = $this->getAttributesCacheSuffix($args[0]);
653-
$attributes = $this->getAttributesByScope($suffix);
654-
foreach ($args as $arg) {
655-
if ($arg instanceof DataObject && $arg->getAttributeSetId()) {
656-
$this->_attrSetEntity->addSetInfo($this->getEntityType(), $attributes, $arg->getAttributeSetId());
657-
}
658-
}
659662
$instance = null;
660-
foreach ($attributes as $attrCode => $attribute) {
663+
foreach ($this->getAttributesByScope($suffix) as $attrCode => $attribute) {
661664
if (isset($args[0]) && is_object($args[0]) && !$this->_isApplicableAttribute($args[0], $attribute)) {
662665
continue;
663666
}

0 commit comments

Comments
 (0)