9
9
namespace Magento \Persistent \Observer ;
10
10
11
11
use Magento \Framework \Event \ObserverInterface ;
12
+ use Magento \Framework \Exception \NoSuchEntityException ;
13
+ use Magento \Quote \Api \CartRepositoryInterface ;
14
+ use Magento \Quote \Api \Data \CartInterface ;
12
15
use Magento \Quote \Model \Quote ;
13
16
14
17
/**
@@ -77,6 +80,11 @@ class CheckExpirePersistentQuoteObserver implements ObserverInterface
77
80
*/
78
81
private $ quote ;
79
82
83
+ /**
84
+ * @var CartRepositoryInterface
85
+ */
86
+ private $ quoteRepository ;
87
+
80
88
/**
81
89
* @param \Magento\Persistent\Helper\Session $persistentSession
82
90
* @param \Magento\Persistent\Helper\Data $persistentData
@@ -85,6 +93,7 @@ class CheckExpirePersistentQuoteObserver implements ObserverInterface
85
93
* @param \Magento\Customer\Model\Session $customerSession
86
94
* @param \Magento\Checkout\Model\Session $checkoutSession
87
95
* @param \Magento\Framework\App\RequestInterface $request
96
+ * @param CartRepositoryInterface $quoteRepository
88
97
*/
89
98
public function __construct (
90
99
\Magento \Persistent \Helper \Session $ persistentSession ,
@@ -93,7 +102,8 @@ public function __construct(
93
102
\Magento \Framework \Event \ManagerInterface $ eventManager ,
94
103
\Magento \Customer \Model \Session $ customerSession ,
95
104
\Magento \Checkout \Model \Session $ checkoutSession ,
96
- \Magento \Framework \App \RequestInterface $ request
105
+ \Magento \Framework \App \RequestInterface $ request ,
106
+ CartRepositoryInterface $ quoteRepository
97
107
) {
98
108
$ this ->_persistentSession = $ persistentSession ;
99
109
$ this ->quoteManager = $ quoteManager ;
@@ -102,6 +112,7 @@ public function __construct(
102
112
$ this ->_eventManager = $ eventManager ;
103
113
$ this ->_persistentData = $ persistentData ;
104
114
$ this ->request = $ request ;
115
+ $ this ->quoteRepository = $ quoteRepository ;
105
116
}
106
117
107
118
/**
@@ -146,7 +157,9 @@ public function execute(\Magento\Framework\Event\Observer $observer)
146
157
private function isPersistentQuoteOutdated (): bool
147
158
{
148
159
if (!$ this ->_persistentData ->isEnabled () && !$ this ->_customerSession ->isLoggedIn ()
149
- && $ this ->_checkoutSession ->getQuoteId ()) {
160
+ && $ this ->_checkoutSession ->getQuoteId ()
161
+ && $ this ->isActiveQuote ()
162
+ ) {
150
163
return (bool )$ this ->getQuote ()->getIsPersistent ();
151
164
}
152
165
return false ;
@@ -175,6 +188,21 @@ private function getQuote(): Quote
175
188
return $ this ->quote ;
176
189
}
177
190
191
+ /**
192
+ * Check if quote is active.
193
+ *
194
+ * @return bool
195
+ */
196
+ private function isActiveQuote (): bool
197
+ {
198
+ try {
199
+ $ this ->quoteRepository ->getActive ($ this ->_checkoutSession ->getQuoteId ());
200
+ return true ;
201
+ } catch (NoSuchEntityException $ e ) {
202
+ return false ;
203
+ }
204
+ }
205
+
178
206
/**
179
207
* Check current request is coming from onepage checkout page.
180
208
*
0 commit comments