12
12
use Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface ;
13
13
use Magento \Framework \Api \SearchCriteriaInterface ;
14
14
use Magento \Framework \App \ObjectManager ;
15
+ use Magento \Framework \App \RequestSafetyInterface ;
15
16
use Magento \Framework \Exception \InputException ;
16
17
use Magento \Framework \Exception \NoSuchEntityException ;
17
18
use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
@@ -96,6 +97,11 @@ class QuoteRepository implements CartRepositoryInterface, ResetAfterRequestInter
96
97
*/
97
98
private $ cartFactory ;
98
99
100
+ /**
101
+ * @var RequestSafetyInterface
102
+ */
103
+ private $ requestSafety ;
104
+
99
105
/**
100
106
* Constructor
101
107
*
@@ -107,6 +113,7 @@ class QuoteRepository implements CartRepositoryInterface, ResetAfterRequestInter
107
113
* @param CollectionProcessorInterface|null $collectionProcessor
108
114
* @param QuoteCollectionFactory|null $quoteCollectionFactory
109
115
* @param CartInterfaceFactory|null $cartFactory
116
+ * @param RequestSafetyInterface|null $requestSafety
110
117
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
111
118
*/
112
119
public function __construct (
@@ -117,7 +124,8 @@ public function __construct(
117
124
JoinProcessorInterface $ extensionAttributesJoinProcessor ,
118
125
CollectionProcessorInterface $ collectionProcessor = null ,
119
126
QuoteCollectionFactory $ quoteCollectionFactory = null ,
120
- CartInterfaceFactory $ cartFactory = null
127
+ CartInterfaceFactory $ cartFactory = null ,
128
+ RequestSafetyInterface $ requestSafety = null
121
129
) {
122
130
$ this ->quoteFactory = $ quoteFactory ;
123
131
$ this ->storeManager = $ storeManager ;
@@ -128,6 +136,7 @@ public function __construct(
128
136
$ this ->quoteCollectionFactory = $ quoteCollectionFactory ?: ObjectManager::getInstance ()
129
137
->get (QuoteCollectionFactory::class);
130
138
$ this ->cartFactory = $ cartFactory ?: ObjectManager::getInstance ()->get (CartInterfaceFactory::class);
139
+ $ this ->requestSafety = $ requestSafety ?: ObjectManager::getInstance ()->get (RequestSafetyInterface::class);
131
140
}
132
141
133
142
/**
@@ -194,7 +203,7 @@ public function getActive($cartId, array $sharedStoreIds = [])
194
203
*/
195
204
private function validateCachedActiveQuote (int $ cartId ): void
196
205
{
197
- if (isset ($ this ->quotesById [$ cartId ])) {
206
+ if (isset ($ this ->quotesById [$ cartId ]) && ! $ this -> requestSafety -> isSafeMethod () ) {
198
207
$ quote = $ this ->cartFactory ->create ();
199
208
if (is_callable ([$ quote , 'setSharedStoreIds ' ])) {
200
209
$ quote ->setSharedStoreIds (['* ' ]);
@@ -228,7 +237,7 @@ public function getActiveForCustomer($customerId, array $sharedStoreIds = [])
228
237
*/
229
238
private function validateCachedCustomerActiveQuote (int $ customerId ): void
230
239
{
231
- if (isset ($ this ->quotesByCustomerId [$ customerId ])) {
240
+ if (isset ($ this ->quotesByCustomerId [$ customerId ]) && ! $ this -> requestSafety -> isSafeMethod () ) {
232
241
$ quoteId = $ this ->quotesByCustomerId [$ customerId ]->getId ();
233
242
$ quote = $ this ->cartFactory ->create ();
234
243
if (is_callable ([$ quote , 'setSharedStoreIds ' ])) {
0 commit comments