Skip to content

Commit 9ec3153

Browse files
committed
Merge branch 'ACP2E-2003' of https://github.com/magento-l3/magento2ce into L3-PR-2023-06-23
2 parents fadc581 + f1baf70 commit 9ec3153

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

app/code/Magento/ConfigurableProduct/Model/Product/SaveHandler.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
use Magento\ConfigurableProduct\Api\OptionRepositoryInterface;
1010
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1111
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable as ResourceModelConfigurable;
12+
use Magento\Framework\App\ObjectManager;
1213
use Magento\Framework\EntityManager\Operation\ExtensionInterface;
1314
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
1415
use Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute;
16+
use Magento\Catalog\Api\ProductRepositoryInterface;
1517

1618
/**
17-
* Class SaveHandler
19+
* Class SaveHandler to update configurable options
1820
*/
1921
class SaveHandler implements ExtensionInterface
2022
{
@@ -29,20 +31,29 @@ class SaveHandler implements ExtensionInterface
2931
private $resourceModel;
3032

3133
/**
32-
* SaveHandler constructor
33-
*
34+
* @var ProductRepositoryInterface
35+
*/
36+
private $productRepository;
37+
38+
/**
3439
* @param ResourceModelConfigurable $resourceModel
3540
* @param OptionRepositoryInterface $optionRepository
41+
* @param ProductRepositoryInterface|null $productRepository
3642
*/
3743
public function __construct(
3844
ResourceModelConfigurable $resourceModel,
39-
OptionRepositoryInterface $optionRepository
45+
OptionRepositoryInterface $optionRepository,
46+
?ProductRepositoryInterface $productRepository = null
4047
) {
4148
$this->resourceModel = $resourceModel;
4249
$this->optionRepository = $optionRepository;
50+
$this->productRepository =
51+
$productRepository ?: ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
4352
}
4453

4554
/**
55+
* Update product options
56+
*
4657
* @param ProductInterface $entity
4758
* @param array $arguments
4859
* @return ProductInterface
@@ -59,6 +70,8 @@ public function execute($entity, $arguments = [])
5970
return $entity;
6071
}
6172

73+
// Refresh product in cache
74+
$this->productRepository->get($entity->getSku(), false, null, true);
6275
if ($extensionAttributes->getConfigurableProductOptions() !== null) {
6376
$this->deleteConfigurableProductAttributes($entity);
6477
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/SaveHandlerTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
namespace Magento\ConfigurableProduct\Test\Unit\Model\Product;
99

1010
use Magento\Catalog\Model\Product;
11+
use Magento\Catalog\Model\ProductRepository;
1112
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
1213
use Magento\ConfigurableProduct\Model\OptionRepository;
1314
use Magento\ConfigurableProduct\Model\Product\SaveHandler;
1415
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableModel;
1516
use Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute;
1617
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable;
1718
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\ConfigurableFactory;
19+
use Magento\Catalog\Api\ProductRepositoryInterface;
1820
use PHPUnit\Framework\MockObject\MockObject;
1921
use PHPUnit\Framework\TestCase;
2022

@@ -38,6 +40,11 @@ class SaveHandlerTest extends TestCase
3840
*/
3941
private $configurable;
4042

43+
/**
44+
* @var ProductRepositoryInterface|MockObject
45+
*/
46+
protected $productRepository;
47+
4148
/**
4249
* @var SaveHandler
4350
*/
@@ -55,9 +62,15 @@ protected function setUp(): void
5562

5663
$this->initConfigurableFactoryMock();
5764

65+
$this->productRepository = $this->getMockBuilder(ProductRepository::class)
66+
->disableOriginalConstructor()
67+
->onlyMethods(['get'])
68+
->getMock();
69+
5870
$this->saveHandler = new SaveHandler(
5971
$this->configurable,
60-
$this->optionRepository
72+
$this->optionRepository,
73+
$this->productRepository
6174
);
6275
}
6376

@@ -97,7 +110,7 @@ public function testExecuteWithEmptyExtensionAttributes()
97110
$product->expects(static::once())
98111
->method('getTypeId')
99112
->willReturn(ConfigurableModel::TYPE_CODE);
100-
$product->expects(static::exactly(1))
113+
$product->expects(static::exactly(2))
101114
->method('getSku')
102115
->willReturn($sku);
103116

@@ -147,7 +160,7 @@ public function testExecute()
147160
$product->expects(static::once())
148161
->method('getTypeId')
149162
->willReturn(ConfigurableModel::TYPE_CODE);
150-
$product->expects(static::exactly(4))
163+
$product->expects(static::exactly(5))
151164
->method('getSku')
152165
->willReturn($sku);
153166

@@ -160,6 +173,9 @@ public function testExecute()
160173
->method('getExtensionAttributes')
161174
->willReturn($extensionAttributes);
162175

176+
$this->productRepository->expects($this->once())
177+
->method('get')->with($sku, false, null, true);
178+
163179
$attributeNew = $this->getMockBuilder(Attribute::class)
164180
->disableOriginalConstructor()
165181
->setMethods(['getAttributeId', 'loadByProductAndAttribute', 'setId', 'getId'])

0 commit comments

Comments
 (0)