6
6
7
7
namespace Magento \Theme \CustomerData ;
8
8
9
+ use Magento \Catalog \Model \Product \ProductFrontendAction \Synchronizer ;
9
10
use Magento \Customer \CustomerData \SectionSourceInterface ;
11
+ use Magento \Framework \App \Config ;
10
12
use Magento \Framework \App \RequestInterface ;
11
- use Magento \Framework \Exception \ LocalizedException ;
13
+ use Magento \Framework \App \ ObjectManager ;
12
14
use Magento \Framework \Message \ManagerInterface as MessageManager ;
13
15
use Magento \Framework \Message \MessageInterface ;
14
16
use Magento \Framework \View \Element \Message \InterpretationStrategyInterface ;
@@ -35,30 +37,39 @@ class Messages implements SectionSourceInterface
35
37
*/
36
38
private $ request ;
37
39
40
+ /**
41
+ * @var Config
42
+ */
43
+ private $ appConfig ;
44
+
38
45
/**
39
46
* Constructor
40
47
*
41
48
* @param MessageManager $messageManager
42
49
* @param InterpretationStrategyInterface $interpretationStrategy
43
50
* @param RequestInterface $request
51
+ * @param Config $appConfig
44
52
*/
45
53
public function __construct (
46
54
MessageManager $ messageManager ,
47
55
InterpretationStrategyInterface $ interpretationStrategy ,
48
- ?RequestInterface $ request = null
56
+ ?RequestInterface $ request = null ,
57
+ ?Config $ appConfig = null
49
58
) {
50
59
$ this ->messageManager = $ messageManager ;
51
60
$ 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);
53
63
}
54
64
55
65
/**
56
66
* @inheritdoc
57
- * @throws LocalizedException
58
67
*/
59
68
public function getSectionData ()
60
69
{
61
- $ messages = $ this ->messageManager ->getMessages (true );
70
+ $ forceNewSectionTimestampFlg = $ this ->sectionTimestampFlag ();
71
+
72
+ $ messages = $ this ->messageManager ->getMessages ($ forceNewSectionTimestampFlg );
62
73
$ messageResponse = array_reduce (
63
74
$ messages ->getItems (),
64
75
function (array $ result , MessageInterface $ message ) {
@@ -70,16 +81,29 @@ function (array $result, MessageInterface $message) {
70
81
},
71
82
[]
72
83
);
84
+ return [
85
+ 'messages ' => $ messageResponse
86
+ ];
87
+ }
73
88
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 ;
76
97
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 ' );
80
102
81
- return [
82
- 'messages ' => $ messageResponse ,
83
- ];
103
+ if ('true ' === $ forceNewSectionTimestamp ) {
104
+ $ forceNewSectionTimestampFlg = true ;
105
+ }
106
+ }
107
+ return $ forceNewSectionTimestampFlg ;
84
108
}
85
109
}
0 commit comments