6
6
namespace Magento \Persistent \Observer ;
7
7
8
8
use Magento \Framework \Event \ObserverInterface ;
9
+ use Magento \Framework \Exception \NoSuchEntityException ;
10
+ use Magento \Quote \Api \CartRepositoryInterface ;
11
+ use Magento \Quote \Api \Data \CartInterface ;
9
12
use Magento \Quote \Model \Quote ;
10
13
11
14
/**
@@ -74,6 +77,11 @@ class CheckExpirePersistentQuoteObserver implements ObserverInterface
74
77
*/
75
78
private $ quote ;
76
79
80
+ /**
81
+ * @var CartRepositoryInterface
82
+ */
83
+ private $ quoteRepository ;
84
+
77
85
/**
78
86
* @param \Magento\Persistent\Helper\Session $persistentSession
79
87
* @param \Magento\Persistent\Helper\Data $persistentData
@@ -82,6 +90,7 @@ class CheckExpirePersistentQuoteObserver implements ObserverInterface
82
90
* @param \Magento\Customer\Model\Session $customerSession
83
91
* @param \Magento\Checkout\Model\Session $checkoutSession
84
92
* @param \Magento\Framework\App\RequestInterface $request
93
+ * @param CartRepositoryInterface $quoteRepository
85
94
*/
86
95
public function __construct (
87
96
\Magento \Persistent \Helper \Session $ persistentSession ,
@@ -90,7 +99,8 @@ public function __construct(
90
99
\Magento \Framework \Event \ManagerInterface $ eventManager ,
91
100
\Magento \Customer \Model \Session $ customerSession ,
92
101
\Magento \Checkout \Model \Session $ checkoutSession ,
93
- \Magento \Framework \App \RequestInterface $ request
102
+ \Magento \Framework \App \RequestInterface $ request ,
103
+ CartRepositoryInterface $ quoteRepository
94
104
) {
95
105
$ this ->_persistentSession = $ persistentSession ;
96
106
$ this ->quoteManager = $ quoteManager ;
@@ -99,6 +109,7 @@ public function __construct(
99
109
$ this ->_eventManager = $ eventManager ;
100
110
$ this ->_persistentData = $ persistentData ;
101
111
$ this ->request = $ request ;
112
+ $ this ->quoteRepository = $ quoteRepository ;
102
113
}
103
114
104
115
/**
@@ -146,9 +157,11 @@ public function execute(\Magento\Framework\Event\Observer $observer)
146
157
*/
147
158
private function isPersistentQuoteOutdated (): bool
148
159
{
149
- if ((! $ this ->_persistentData ->isEnabled () || ! $ this ->_persistentData ->isShoppingCartPersist ())
160
+ if (!( $ this ->_persistentData ->isEnabled () && $ this ->_persistentData ->isShoppingCartPersist ())
150
161
&& !$ this ->_customerSession ->isLoggedIn ()
151
- && $ this ->_checkoutSession ->getQuoteId ()) {
162
+ && $ this ->_checkoutSession ->getQuoteId ()
163
+ && $ this ->isActiveQuote ()
164
+ ) {
152
165
return (bool )$ this ->getQuote ()->getIsPersistent ();
153
166
}
154
167
return false ;
@@ -181,6 +194,21 @@ private function getQuote(): Quote
181
194
return $ this ->quote ;
182
195
}
183
196
197
+ /**
198
+ * Check if quote is active.
199
+ *
200
+ * @return bool
201
+ */
202
+ private function isActiveQuote (): bool
203
+ {
204
+ try {
205
+ $ this ->quoteRepository ->getActive ($ this ->_checkoutSession ->getQuoteId ());
206
+ return true ;
207
+ } catch (NoSuchEntityException $ e ) {
208
+ return false ;
209
+ }
210
+ }
211
+
184
212
/**
185
213
* Check current request is coming from onepage checkout page.
186
214
*
0 commit comments