Skip to content

Commit ce51d67

Browse files
committed
ACP2E-3941: Updating Store Code Cleared Design Configuration
1 parent 7da46f5 commit ce51d67

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
namespace Magento\Backend\Plugin;
7+
8+
use Magento\Backend\Controller\Adminhtml\System\Store\Save;
9+
use Magento\Backend\Model\View\Result\Redirect;
10+
use Magento\Framework\App\Cache\TypeListInterface;
11+
class StoreSaveFlushConfig
12+
{
13+
/**
14+
* @var TypeListInterface
15+
*/
16+
private $cacheTypeList;
17+
18+
/**
19+
* @param TypeListInterface $cacheTypeList
20+
*/
21+
public function __construct(
22+
TypeListInterface $cacheTypeList
23+
) {
24+
$this->cacheTypeList = $cacheTypeList;
25+
}
26+
27+
/**
28+
* Flush config cache after store save
29+
*
30+
* @param Save $subject
31+
* @param Redirect $result
32+
* @return Redirect
33+
*/
34+
public function afterExecute(Save $subject, $result)
35+
{
36+
$postData = $subject->getRequest()->getPostValue();
37+
if (isset($postData['store_type']) && $postData['store_type'] === 'store') {
38+
$this->cacheTypeList->cleanType('config');
39+
}
40+
return $result;
41+
}
42+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
namespace Magento\Backend\Test\Unit\Plugin;
7+
8+
use Magento\Backend\Plugin\StoreSaveFlushConfig;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Backend\Controller\Adminhtml\System\Store\Save;
11+
use Magento\Framework\App\Cache\TypeListInterface;
12+
use Magento\Framework\App\RequestInterface;
13+
use Magento\Backend\Model\View\Result\Redirect;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class StoreSaveFlushConfigTest extends TestCase
18+
{
19+
/**
20+
* @var ObjectManager
21+
*/
22+
private $objectManager;
23+
24+
/**
25+
* @var StoreSaveFlushConfig
26+
*/
27+
private $plugin;
28+
29+
/**
30+
* @var TypeListInterface|MockObject
31+
*/
32+
private $cacheTypeListMock;
33+
34+
/**
35+
* @var Save|MockObject
36+
*/
37+
private $subjectMock;
38+
39+
/**
40+
* @var RequestInterface|MockObject
41+
*/
42+
private $requestMock;
43+
44+
/**
45+
* @var Redirect|MockObject
46+
*/
47+
private $resultMock;
48+
49+
protected function setUp(): void
50+
{
51+
$this->objectManager = new ObjectManager($this);
52+
$this->cacheTypeListMock = $this->createMock(TypeListInterface::class);
53+
$this->subjectMock = $this->createMock(Save::class);
54+
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
55+
->addMethods(['getPostValue'])
56+
->disableOriginalConstructor()
57+
->getMockForAbstractClass();
58+
$this->resultMock = $this->createMock(Redirect::class);
59+
$this->plugin = $this->objectManager->getObject(
60+
StoreSaveFlushConfig::class,
61+
['cacheTypeList' => $this->cacheTypeListMock]
62+
);
63+
}
64+
65+
public function testAfterExecuteWithStoreTypeStoreClearsConfigCache()
66+
{
67+
$postData = ['store_type' => 'store'];
68+
$this->subjectMock->method('getRequest')->willReturn($this->requestMock);
69+
$this->requestMock->method('getPostValue')->willReturn($postData);
70+
$this->cacheTypeListMock->expects($this->once())->method('cleanType')->with('config');
71+
$result = $this->plugin->afterExecute($this->subjectMock, $this->resultMock);
72+
$this->assertSame($this->resultMock, $result);
73+
}
74+
75+
public function testAfterExecuteWithNonStoreTypeDoesNotClearCache()
76+
{
77+
$postData = ['store_type' => 'website'];
78+
$this->subjectMock->method('getRequest')->willReturn($this->requestMock);
79+
$this->requestMock->method('getPostValue')->willReturn($postData);
80+
$this->cacheTypeListMock->expects($this->never())->method('cleanType');
81+
$result = $this->plugin->afterExecute($this->subjectMock, $this->resultMock);
82+
$this->assertSame($this->resultMock, $result);
83+
}
84+
}

app/code/Magento/Backend/etc/adminhtml/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,7 @@
168168
</type>
169169
<preference for="CsrfRequestValidator" type="Magento\Backend\App\Request\BackendValidator" />
170170
<preference for="Magento\Backend\Model\Image\UploadResizeConfigInterface" type="Magento\Backend\Model\Image\UploadResizeConfig" />
171+
<type name="Magento\Backend\Controller\Adminhtml\System\Store\Save">
172+
<plugin name="backend_store_save_flush_config" type="Magento\Backend\Plugin\StoreSaveFlushConfig" />
173+
</type>
171174
</config>

0 commit comments

Comments
 (0)