Skip to content

Commit 6f33bd3

Browse files
committed
ACP2E-23: [Magento Cloud] Error message in PDP disappearing quickly - Code refactoring applied.
1 parent 824dc0e commit 6f33bd3

File tree

6 files changed

+134
-40
lines changed

6 files changed

+134
-40
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\Theme\CustomerData;
9+
10+
use Magento\Catalog\Model\Product\ProductFrontendAction\Synchronizer;
11+
use Magento\Framework\App\Config;
12+
use Magento\Framework\App\RequestInterface;
13+
use Magento\Framework\Message\ManagerInterface as MessageManager;
14+
use Magento\Theme\CustomerData\MessageServiceInterface;
15+
16+
class MessageService implements MessageServiceInterface
17+
{
18+
/**
19+
* @var Config
20+
*/
21+
private $appConfig;
22+
23+
/**
24+
* @var RequestInterface
25+
*/
26+
private $request;
27+
28+
/**
29+
* Manager messages
30+
*
31+
* @var MessageManager
32+
*/
33+
private $messageManager;
34+
35+
/**
36+
* Constructor
37+
*
38+
* @param Config $appConfig
39+
* @param RequestInterface $request
40+
* @param MessageManager $messageManager
41+
*/
42+
public function __construct(
43+
Config $appConfig,
44+
RequestInterface $request,
45+
MessageManager $messageManager
46+
) {
47+
$this->appConfig = $appConfig;
48+
$this->request = $request;
49+
$this->messageManager = $messageManager;
50+
}
51+
52+
/**
53+
* Verify flag value for synchronize product actions with backend or not
54+
* @return object
55+
*/
56+
public function getMessages(): object
57+
{
58+
$clearSessionMessages = true;
59+
60+
if ((bool) $this->appConfig->getValue(Synchronizer::ALLOW_SYNC_WITH_BACKEND_PATH)) {
61+
62+
$forceNewSectionTimestamp = $this->request->getParam('force_new_section_timestamp') ?? null;
63+
64+
if ('true' !== $forceNewSectionTimestamp) {
65+
$clearSessionMessages = false;
66+
}
67+
}
68+
69+
return $this->messageManager->getMessages($clearSessionMessages);
70+
}
71+
}

app/code/Magento/Catalog/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<preference for="Magento\Catalog\Api\Data\MassActionInterface" type="\Magento\Catalog\Model\MassAction" />
7777
<preference for="Magento\Catalog\Model\ProductLink\Data\ListCriteriaInterface" type="Magento\Catalog\Model\ProductLink\Data\ListCriteria" />
7878
<preference for="Magento\Catalog\Api\CategoryListDeleteBySkuInterface" type="Magento\Catalog\Model\CategoryLinkRepository"/>
79+
<preference for="Magento\Theme\CustomerData\MessageServiceInterface" type="Magento\Catalog\Model\Theme\CustomerData\MessageService"/>
7980
<type name="Magento\Customer\Model\ResourceModel\Visitor">
8081
<plugin name="catalogLog" type="Magento\Catalog\Model\Plugin\Log" />
8182
</type>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Theme\CustomerData;
9+
10+
use Magento\Framework\Message\ManagerInterface as MessageManager;
11+
12+
class MessageService implements MessageServiceInterface
13+
{
14+
/**
15+
* Manager messages
16+
*
17+
* @var MessageManager
18+
*/
19+
private $messageManager;
20+
21+
/**
22+
* Constructor
23+
*
24+
* @param MessageManager $messageManager
25+
*/
26+
public function __construct(
27+
MessageManager $messageManager
28+
) {
29+
$this->messageManager = $messageManager;
30+
}
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function getMessages()
36+
{
37+
return $this->messageManager->getMessages(true);
38+
}
39+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Theme\CustomerData;
9+
10+
interface MessageServiceInterface
11+
{
12+
/**
13+
* @return object
14+
*/
15+
public function getMessages();
16+
}

app/code/Magento/Theme/CustomerData/Messages.php

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
namespace Magento\Theme\CustomerData;
88

99
use Magento\Customer\CustomerData\SectionSourceInterface;
10-
use Magento\Framework\App\Config;
11-
use Magento\Framework\App\RequestInterface;
12-
use Magento\Framework\App\ObjectManager;
1310
use Magento\Framework\Message\ManagerInterface as MessageManager;
1411
use Magento\Framework\Message\MessageInterface;
1512
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
@@ -32,43 +29,33 @@ class Messages implements SectionSourceInterface
3229
private $interpretationStrategy;
3330

3431
/**
35-
* @var RequestInterface
32+
* @var MessageServiceInterface
3633
*/
37-
private $request;
38-
39-
/**
40-
* @var Config
41-
*/
42-
private $appConfig;
34+
private $messageService;
4335

4436
/**
4537
* Constructor
4638
*
4739
* @param MessageManager $messageManager
4840
* @param InterpretationStrategyInterface $interpretationStrategy
49-
* @param RequestInterface $request
50-
* @param Config $appConfig
41+
* @param MessageServiceInterface $messageService
5142
*/
5243
public function __construct(
5344
MessageManager $messageManager,
5445
InterpretationStrategyInterface $interpretationStrategy,
55-
?RequestInterface $request = null,
56-
?Config $appConfig = null
46+
MessageServiceInterface $messageService
5747
) {
5848
$this->messageManager = $messageManager;
5949
$this->interpretationStrategy = $interpretationStrategy;
60-
$this->request = $request ?: ObjectManager::getInstance()->get(RequestInterface::class);
61-
$this->appConfig = $appConfig ?: ObjectManager::getInstance()->get(Config::class);
50+
$this->messageService = $messageService;
6251
}
6352

6453
/**
6554
* @inheritdoc
6655
*/
6756
public function getSectionData()
6857
{
69-
$forceNewSectionTimestampFlg = $this->sectionTimestampFlag();
70-
71-
$messages = $this->messageManager->getMessages($forceNewSectionTimestampFlg);
58+
$messages = $this->messageService->getMessages();
7259
$messageResponse = array_reduce(
7360
$messages->getItems(),
7461
function (array $result, MessageInterface $message) {
@@ -84,25 +71,4 @@ function (array $result, MessageInterface $message) {
8471
'messages' => $messageResponse
8572
];
8673
}
87-
88-
/**
89-
* Verify flag value for synchronizing product actions with backend or not.
90-
*
91-
* @return boolean
92-
*/
93-
private function sectionTimestampFlag(): bool
94-
{
95-
$forceNewSectionTimestampFlg = true;
96-
97-
if ((bool) $this->appConfig->getValue('catalog/recently_products/synchronize_with_backend')) {
98-
$forceNewSectionTimestampFlg = false;
99-
$forceNewSectionTimestamp = $this->request->getParam('force_new_section_timestamp')
100-
?? null;
101-
102-
if ('true' === $forceNewSectionTimestamp) {
103-
$forceNewSectionTimestampFlg = true;
104-
}
105-
}
106-
return $forceNewSectionTimestampFlg;
107-
}
10874
}

app/code/Magento/Theme/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<preference for="Magento\Framework\View\Model\PageLayout\Config\BuilderInterface" type="Magento\Theme\Model\PageLayout\Config\Builder"/>
2020
<preference for="Magento\Theme\Model\Design\Config\MetadataProviderInterface" type="Magento\Theme\Model\Design\Config\MetadataProvider"/>
2121
<preference for="Magento\Theme\Model\Theme\StoreThemesResolverInterface" type="Magento\Theme\Model\Theme\StoreThemesResolver"/>
22+
<preference for="Magento\Theme\CustomerData\MessageServiceInterface" type="Magento\Theme\CustomerData\MessageService"/>
2223
<type name="Magento\Theme\Model\Config">
2324
<arguments>
2425
<argument name="configCache" xsi:type="object">Magento\Framework\App\Cache\Type\Config</argument>

0 commit comments

Comments
 (0)