Skip to content

Commit c5883e1

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

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

app/code/Magento/Catalog/view/frontend/web/js/storage-manager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ define([
240240
ids: data,
241241
'type_id': typeId
242242
}
243-
}, params).done(this.requestHandler.bind(this, name));
243+
}, params)
244+
.done(this.requestHandler.bind(this, name))
245+
.always(this.requestSent = 1);
244246
}
245247
});
246248
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
<createData entity="_defaultProduct" stepKey="createSimpleProduct">
2626
<requiredEntity createDataKey="createCategory"/>
2727
</createData>
28-
<magentoCron stepKey="runCronReindex" groups="index"/>
28+
<!--Reindex and flush cache-->
29+
<magentoCLI command="cron:run --group=index" stepKey="runCronReindex"/>
2930
</before>
3031
<after>
3132
<deleteData createDataKey="createSimpleProduct" stepKey="deleteProduct"/>
3233
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
3334
<magentoCLI command="config:set {{DisableSynchronizeWidgetProductsWithBackendStorage.path}} {{DisableSynchronizeWidgetProductsWithBackendStorage.value}}" stepKey="setDisableSynchronizeWidgetProductsWithBackendStorage"/>
3435
</after>
3536

37+
<waitForPageLoad time="60" stepKey="waitForPageLoad"/>
3638
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openProductPage">
3739
<argument name="product" value="$$createSimpleProduct$$"/>
3840
</actionGroup>

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

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
namespace Magento\Theme\CustomerData;
88

9+
use Magento\Catalog\Model\Product\ProductFrontendAction\Synchronizer;
910
use Magento\Customer\CustomerData\SectionSourceInterface;
11+
use Magento\Framework\App\Config;
1012
use Magento\Framework\App\RequestInterface;
11-
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\App\ObjectManager;
1214
use Magento\Framework\Message\ManagerInterface as MessageManager;
1315
use Magento\Framework\Message\MessageInterface;
1416
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
@@ -35,30 +37,39 @@ class Messages implements SectionSourceInterface
3537
*/
3638
private $request;
3739

40+
/**
41+
* @var Config
42+
*/
43+
private $appConfig;
44+
3845
/**
3946
* Constructor
4047
*
4148
* @param MessageManager $messageManager
4249
* @param InterpretationStrategyInterface $interpretationStrategy
4350
* @param RequestInterface $request
51+
* @param Config $appConfig
4452
*/
4553
public function __construct(
4654
MessageManager $messageManager,
4755
InterpretationStrategyInterface $interpretationStrategy,
48-
?RequestInterface $request = null
56+
?RequestInterface $request = null,
57+
?Config $appConfig = null
4958
) {
5059
$this->messageManager = $messageManager;
5160
$this->interpretationStrategy = $interpretationStrategy;
52-
$this->request = $request ?: \Magento\Framework\App\ObjectManager::getInstance()->get(RequestInterface::class);
61+
$this->request = $request ?: ObjectManager::getInstance()->get(RequestInterface::class);
62+
$this->appConfig = $appConfig ?: ObjectManager::getInstance()->get(Config::class);
5363
}
5464

5565
/**
5666
* @inheritdoc
57-
* @throws LocalizedException
5867
*/
5968
public function getSectionData()
6069
{
61-
$messages = $this->messageManager->getMessages(true);
70+
$forceNewSectionTimestampFlg = $this->sectionTimestampFlag();
71+
72+
$messages = $this->messageManager->getMessages($forceNewSectionTimestampFlg);
6273
$messageResponse = array_reduce(
6374
$messages->getItems(),
6475
function (array $result, MessageInterface $message) {
@@ -70,16 +81,29 @@ function (array $result, MessageInterface $message) {
7081
},
7182
[]
7283
);
84+
return [
85+
'messages' => $messageResponse
86+
];
87+
}
7388

74-
$forceNewSectionTimestamp = $this->request->getParam('force_new_section_timestamp')
75-
?? $this->request->getParam('force_new_section_timestamp');
89+
/**
90+
* Verify flag value for synchronizing product actions with backend or not.
91+
*
92+
* @return boolean
93+
*/
94+
private function sectionTimestampFlag(): bool
95+
{
96+
$forceNewSectionTimestampFlg = true;
7697

77-
if ('true' === $forceNewSectionTimestamp && empty($messageResponse)) {
78-
throw new LocalizedException(__('Session messages already cleared.'));
79-
}
98+
if ((bool) $this->appConfig->getValue(Synchronizer::ALLOW_SYNC_WITH_BACKEND_PATH)) {
99+
$forceNewSectionTimestampFlg = false;
100+
$forceNewSectionTimestamp = $this->request->getParam('force_new_section_timestamp')
101+
?? $this->request->getParam('force_new_section_timestamp');
80102

81-
return [
82-
'messages' => $messageResponse,
83-
];
103+
if ('true' === $forceNewSectionTimestamp) {
104+
$forceNewSectionTimestampFlg = true;
105+
}
106+
}
107+
return $forceNewSectionTimestampFlg;
84108
}
85109
}

0 commit comments

Comments
 (0)