Skip to content

Commit 3226227

Browse files
committed
ACP2E-23: [Magento Cloud] Error message in PDP disappearing quickly
1 parent b8dc62a commit 3226227

File tree

4 files changed

+33
-80
lines changed

4 files changed

+33
-80
lines changed

app/code/Magento/Customer/Test/Mftf/Test/StorefrontAddProductToCartVerifyThatErrorMessageShouldNotDisappearTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</annotations>
2020

2121
<before>
22-
<!-- Set in Stores > Configuration > Catalog > Catalog > > Recently Viewed/Compared Products > Synchronize Widget Products With Backend Storage = "Yes" -->
22+
<!-- Set in Stores > Configuration > Catalog > Catalog > Recently Viewed/Compared Products > Synchronize Widget Products With Backend Storage = "Yes" -->
2323
<magentoCLI command="config:set {{EnableSynchronizeWidgetProductsWithBackendStorage.path}} {{EnableSynchronizeWidgetProductsWithBackendStorage.value}}" stepKey="setEnableSynchronizeWidgetProductsWithBackendStorage"/>
2424
<createData entity="_defaultCategory" stepKey="createCategory"/>
2525
<createData entity="_defaultProduct" stepKey="createSimpleProduct">

app/code/Magento/Customer/view/frontend/web/js/customer-data-mixin.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,11 @@ define([
178178
var sectionId = 0,
179179
sectionDataIds = $.cookieStorage.get('section_data_ids') || {};
180180

181-
if ($.inArray('cart', _.keys(sections)) !== -1) {
182-
$.cookieStorage.set('pdp_qty_error', true);
183-
}
184-
185181
_.each(sections, function (sectionData, sectionName) {
186182
sectionId = sectionData['data_id'];
187183
sectionDataIds[sectionName] = sectionId;
188184
storage.set(sectionName, sectionData);
189185
storageInvalidation.remove(sectionName);
190-
191-
if (_.isEmpty(sectionData.messages) && $.cookieStorage.get('pdp_qty_error')) {
192-
return;
193-
}
194186
buffer.notify(sectionName, sectionData);
195187
});
196188
$.cookieStorage.set('section_data_ids', sectionDataIds);
@@ -440,12 +432,5 @@ define([
440432
}
441433
});
442434

443-
/**
444-
* Place code to be executed on completion of last outstanding ajax call here
445-
*/
446-
$(document).ajaxStop(function () {
447-
$.cookieStorage.set('pdp_qty_error', false);
448-
});
449-
450435
return customerData;
451436
});

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

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

99
use Magento\Customer\CustomerData\SectionSourceInterface;
10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Framework\Exception\LocalizedException;
1012
use Magento\Framework\Message\ManagerInterface as MessageManager;
1113
use Magento\Framework\Message\MessageInterface;
1214
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
@@ -28,38 +30,56 @@ class Messages implements SectionSourceInterface
2830
*/
2931
private $interpretationStrategy;
3032

33+
/**
34+
* @var RequestInterface
35+
*/
36+
private $request;
37+
3138
/**
3239
* Constructor
3340
*
3441
* @param MessageManager $messageManager
3542
* @param InterpretationStrategyInterface $interpretationStrategy
43+
* @param RequestInterface $request
3644
*/
3745
public function __construct(
3846
MessageManager $messageManager,
39-
InterpretationStrategyInterface $interpretationStrategy
47+
InterpretationStrategyInterface $interpretationStrategy,
48+
?RequestInterface $request = null
4049
) {
4150
$this->messageManager = $messageManager;
4251
$this->interpretationStrategy = $interpretationStrategy;
52+
$this->request = $request ?: \Magento\Framework\App\ObjectManager::getInstance()->get(RequestInterface::class);
4353
}
4454

4555
/**
4656
* @inheritdoc
57+
* @throws LocalizedException
4758
*/
4859
public function getSectionData()
4960
{
5061
$messages = $this->messageManager->getMessages(true);
62+
$messageResponse = array_reduce(
63+
$messages->getItems(),
64+
function (array $result, MessageInterface $message) {
65+
$result[] = [
66+
'type' => $message->getType(),
67+
'text' => $this->interpretationStrategy->interpret($message)
68+
];
69+
return $result;
70+
},
71+
[]
72+
);
73+
74+
$forceNewSectionTimestamp = $this->request->getParam('force_new_section_timestamp')
75+
?? $this->request->getParam('force_new_section_timestamp');
76+
77+
if ('true' === $forceNewSectionTimestamp && empty($messageResponse)) {
78+
throw new LocalizedException(__('Session messages already cleared.'));
79+
}
80+
5181
return [
52-
'messages' => array_reduce(
53-
$messages->getItems(),
54-
function (array $result, MessageInterface $message) {
55-
$result[] = [
56-
'type' => $message->getType(),
57-
'text' => $this->interpretationStrategy->interpret($message)
58-
];
59-
return $result;
60-
},
61-
[]
62-
),
82+
'messages' => $messageResponse,
6383
];
6484
}
6585
}

0 commit comments

Comments
 (0)