Skip to content

Commit 5eba4d8

Browse files
committed
ACP2E-23: [Magento Cloud] Error message in PDP disappearing quickly - Code refactoring applied.
1 parent a378c8b commit 5eba4d8

File tree

7 files changed

+29
-24
lines changed

7 files changed

+29
-24
lines changed

app/code/Magento/Catalog/Model/Theme/CustomerData/MessageService.php renamed to app/code/Magento/Catalog/Model/Theme/CustomerData/MessageProvider.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
use Magento\Catalog\Model\Product\ProductFrontendAction\Synchronizer;
1111
use Magento\Framework\App\Config;
1212
use Magento\Framework\App\RequestInterface;
13+
use Magento\Framework\Message\Collection;
1314
use Magento\Framework\Message\ManagerInterface as MessageManager;
14-
use Magento\Theme\CustomerData\MessageServiceInterface;
15+
use Magento\Theme\CustomerData\MessagesProviderInterface;
1516

16-
class MessageService implements MessageServiceInterface
17+
class MessageProvider implements MessagesProviderInterface
1718
{
1819
/**
1920
*
@@ -53,9 +54,9 @@ public function __construct(
5354
/**
5455
* Verify flag value for synchronize product actions with backend or not
5556
*
56-
* @return object
57+
* @return Collection
5758
*/
58-
public function getMessages(): object
59+
public function getMessages(): Collection
5960
{
6061
$clearSessionMessages = true;
6162

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +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"/>
79+
<preference for="Magento\Theme\CustomerData\MessagesProviderInterface" type="Magento\Catalog\Model\Theme\CustomerData\MessageProvider"/>
8080
<type name="Magento\Customer\Model\ResourceModel\Visitor">
8181
<plugin name="catalogLog" type="Magento\Catalog\Model\Plugin\Log" />
8282
</type>

app/code/Magento/Theme/CustomerData/MessageService.php renamed to app/code/Magento/Theme/CustomerData/MessageProvider.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
namespace Magento\Theme\CustomerData;
99

10+
use Magento\Framework\Message\Collection;
1011
use Magento\Framework\Message\ManagerInterface as MessageManager;
1112

12-
class MessageService implements MessageServiceInterface
13+
class MessageProvider implements MessagesProviderInterface
1314
{
1415
/**
1516
* Manager messages
@@ -30,9 +31,9 @@ public function __construct(
3031
}
3132

3233
/**
33-
* @inheritdoc
34+
* @return Collection
3435
*/
35-
public function getMessages()
36+
public function getMessages() : Collection
3637
{
3738
return $this->messageManager->getMessages(true);
3839
}

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

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

99
use Magento\Customer\CustomerData\SectionSourceInterface;
10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\Message\ManagerInterface as MessageManager;
1112
use Magento\Framework\Message\MessageInterface;
1213
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
@@ -29,33 +30,33 @@ class Messages implements SectionSourceInterface
2930
private $interpretationStrategy;
3031

3132
/**
32-
* @var MessageServiceInterface
33+
* @var MessagesProviderInterface
3334
*/
34-
private $messageService;
35+
private $messageProvider;
3536

3637
/**
3738
* Constructor
3839
*
3940
* @param MessageManager $messageManager
4041
* @param InterpretationStrategyInterface $interpretationStrategy
41-
* @param MessageServiceInterface $messageService
42+
* @param MessagesProviderInterface $messageProvider
4243
*/
4344
public function __construct(
4445
MessageManager $messageManager,
4546
InterpretationStrategyInterface $interpretationStrategy,
46-
MessageServiceInterface $messageService
47+
?MessagesProviderInterface $messageProvider = null
4748
) {
4849
$this->messageManager = $messageManager;
4950
$this->interpretationStrategy = $interpretationStrategy;
50-
$this->messageService = $messageService;
51+
$this->messageProvider = $messageProvider ?? ObjectManager::getInstance()->get(MessagesProviderInterface::class);
5152
}
5253

5354
/**
5455
* @inheritdoc
5556
*/
5657
public function getSectionData()
5758
{
58-
$messages = $this->messageService->getMessages();
59+
$messages = $this->messageProvider->getMessages();
5960
$messageResponse = array_reduce(
6061
$messages->getItems(),
6162
function (array $result, MessageInterface $message) {

app/code/Magento/Theme/CustomerData/MessageServiceInterface.php renamed to app/code/Magento/Theme/CustomerData/MessagesProviderInterface.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
namespace Magento\Theme\CustomerData;
99

10-
interface MessageServiceInterface
10+
use Magento\Framework\Message\Collection;
11+
12+
interface MessagesProviderInterface
1113
{
1214
/**
1315
* Get the messages stored in session before session clear
1416
*
15-
* @return object
17+
* @return Collection
1618
*/
17-
public function getMessages();
19+
public function getMessages(): Collection;
1820
}

app/code/Magento/Theme/Test/Unit/CustomerData/MessagesTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Framework\Message\MessageInterface;
1313
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
1414
use Magento\Theme\CustomerData\Messages;
15-
use Magento\Theme\CustomerData\MessageServiceInterface;
15+
use Magento\Theme\CustomerData\MessagesProviderInterface;
1616
use PHPUnit\Framework\MockObject\MockObject;
1717
use PHPUnit\Framework\TestCase;
1818

@@ -24,9 +24,9 @@ class MessagesTest extends TestCase
2424
protected $messageManager;
2525

2626
/**
27-
* @var MessageServiceInterface|MockObject
27+
* @var MessagesProviderInterface|MockObject
2828
*/
29-
private $messageService;
29+
private $messageProvider;
3030

3131
/**
3232
* @var InterpretationStrategyInterface|MockObject
@@ -42,12 +42,12 @@ protected function setUp(): void
4242
{
4343
$this->messageManager = $this->getMockBuilder(ManagerInterface::class)
4444
->getMock();
45-
$this->messageService = $this->getMockBuilder(MessageServiceInterface::class)
45+
$this->messageProvider = $this->getMockBuilder(MessagesProviderInterface::class)
4646
->getMock();
4747
$this->messageInterpretationStrategy = $this->createMock(
4848
InterpretationStrategyInterface::class
4949
);
50-
$this->object = new Messages($this->messageManager, $this->messageInterpretationStrategy, $this->messageService);
50+
$this->object = new Messages($this->messageManager, $this->messageInterpretationStrategy, $this->messageProvider);
5151
}
5252

5353
public function testGetSectionData()
@@ -67,7 +67,7 @@ public function testGetSectionData()
6767
->method('interpret')
6868
->with($msg)
6969
->willReturn($msgText);
70-
$this->messageService->expects($this->once())
70+
$this->messageProvider->expects($this->once())
7171
->method('getMessages')
7272
->willReturn($msgCollection);
7373
$msgCollection->expects($this->once())

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +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"/>
22+
<preference for="Magento\Theme\CustomerData\MessagesProviderInterface" type="Magento\Theme\CustomerData\MessageProvider"/>
2323
<type name="Magento\Theme\Model\Config">
2424
<arguments>
2525
<argument name="configCache" xsi:type="object">Magento\Framework\App\Cache\Type\Config</argument>

0 commit comments

Comments
 (0)