1212use Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface ;
1313use Magento \Framework \Api \SearchCriteriaInterface ;
1414use Magento \Framework \App \ObjectManager ;
15+ use Magento \Framework \App \RequestSafetyInterface ;
1516use Magento \Framework \Exception \InputException ;
1617use Magento \Framework \Exception \NoSuchEntityException ;
1718use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
@@ -96,6 +97,11 @@ class QuoteRepository implements CartRepositoryInterface, ResetAfterRequestInter
9697 */
9798 private $ cartFactory ;
9899
100+ /**
101+ * @var RequestSafetyInterface
102+ */
103+ private $ requestSafety ;
104+
99105 /**
100106 * Constructor
101107 *
@@ -107,6 +113,7 @@ class QuoteRepository implements CartRepositoryInterface, ResetAfterRequestInter
107113 * @param CollectionProcessorInterface|null $collectionProcessor
108114 * @param QuoteCollectionFactory|null $quoteCollectionFactory
109115 * @param CartInterfaceFactory|null $cartFactory
116+ * @param RequestSafetyInterface|null $requestSafety
110117 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
111118 */
112119 public function __construct (
@@ -117,7 +124,8 @@ public function __construct(
117124 JoinProcessorInterface $ extensionAttributesJoinProcessor ,
118125 CollectionProcessorInterface $ collectionProcessor = null ,
119126 QuoteCollectionFactory $ quoteCollectionFactory = null ,
120- CartInterfaceFactory $ cartFactory = null
127+ CartInterfaceFactory $ cartFactory = null ,
128+ RequestSafetyInterface $ requestSafety = null
121129 ) {
122130 $ this ->quoteFactory = $ quoteFactory ;
123131 $ this ->storeManager = $ storeManager ;
@@ -128,6 +136,7 @@ public function __construct(
128136 $ this ->quoteCollectionFactory = $ quoteCollectionFactory ?: ObjectManager::getInstance ()
129137 ->get (QuoteCollectionFactory::class);
130138 $ this ->cartFactory = $ cartFactory ?: ObjectManager::getInstance ()->get (CartInterfaceFactory::class);
139+ $ this ->requestSafety = $ requestSafety ?: ObjectManager::getInstance ()->get (RequestSafetyInterface::class);
131140 }
132141
133142 /**
@@ -194,7 +203,7 @@ public function getActive($cartId, array $sharedStoreIds = [])
194203 */
195204 private function validateCachedActiveQuote (int $ cartId ): void
196205 {
197- if (isset ($ this ->quotesById [$ cartId ])) {
206+ if (isset ($ this ->quotesById [$ cartId ]) && ! $ this -> requestSafety -> isSafeMethod () ) {
198207 $ quote = $ this ->cartFactory ->create ();
199208 if (is_callable ([$ quote , 'setSharedStoreIds ' ])) {
200209 $ quote ->setSharedStoreIds (['* ' ]);
@@ -228,7 +237,7 @@ public function getActiveForCustomer($customerId, array $sharedStoreIds = [])
228237 */
229238 private function validateCachedCustomerActiveQuote (int $ customerId ): void
230239 {
231- if (isset ($ this ->quotesByCustomerId [$ customerId ])) {
240+ if (isset ($ this ->quotesByCustomerId [$ customerId ]) && ! $ this -> requestSafety -> isSafeMethod () ) {
232241 $ quoteId = $ this ->quotesByCustomerId [$ customerId ]->getId ();
233242 $ quote = $ this ->cartFactory ->create ();
234243 if (is_callable ([$ quote , 'setSharedStoreIds ' ])) {
0 commit comments