5
5
*/
6
6
namespace Magento \Sales \Cron ;
7
7
8
- use Magento \Store \Model \StoresConfig ;
8
+ use Magento \Quote \Model \ResourceModel \Quote \Collection ;
9
+ use Magento \Sales \Helper \ExpiredQuotesCollection ;
10
+ use Magento \Store \Model \StoreManagerInterface ;
9
11
10
12
/**
11
13
* Class CleanExpiredQuotes
12
14
*/
13
15
class CleanExpiredQuotes
14
16
{
15
- const LIFETIME = 86400 ;
16
-
17
- /**
18
- * @var StoresConfig
19
- */
20
- protected $ storesConfig ;
21
-
22
17
/**
23
- * @var \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory
18
+ * @var ExpiredQuotesCollection
24
19
*/
25
- protected $ quoteCollectionFactory ;
20
+ private $ expiredQuotesCollection ;
26
21
27
22
/**
28
- * @var array
23
+ * @var StoreManagerInterface
29
24
*/
30
- protected $ expireQuotesFilterFields = [] ;
25
+ private $ storeManager ;
31
26
32
27
/**
33
- * @param StoresConfig $storesConfig
34
- * @param \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory $collectionFactory
28
+ * @param StoreManagerInterface $storeManager
29
+ * @param ExpiredQuotesCollection $expiredQuotesCollection
35
30
*/
36
31
public function __construct (
37
- StoresConfig $ storesConfig ,
38
- \ Magento \ Quote \ Model \ ResourceModel \ Quote \ CollectionFactory $ collectionFactory
32
+ StoreManagerInterface $ storeManager ,
33
+ ExpiredQuotesCollection $ expiredQuotesCollection
39
34
) {
40
- $ this ->storesConfig = $ storesConfig ;
41
- $ this ->quoteCollectionFactory = $ collectionFactory ;
35
+ $ this ->storeManager = $ storeManager ;
36
+ $ this ->expiredQuotesCollection = $ expiredQuotesCollection ;
42
37
}
43
38
44
39
/**
@@ -48,42 +43,11 @@ public function __construct(
48
43
*/
49
44
public function execute ()
50
45
{
51
- $ lifetimes = $ this ->storesConfig ->getStoresConfigByPath ('checkout/cart/delete_quote_after ' );
52
- foreach ($ lifetimes as $ storeId => $ lifetime ) {
53
- $ lifetime *= self ::LIFETIME ;
54
-
55
- /** @var $quotes \Magento\Quote\Model\ResourceModel\Quote\Collection */
56
- $ quotes = $ this ->quoteCollectionFactory ->create ();
57
-
58
- $ quotes ->addFieldToFilter ('store_id ' , $ storeId );
59
- $ quotes ->addFieldToFilter ('updated_at ' , ['to ' => date ("Y-m-d " , time () - $ lifetime )]);
60
-
61
- foreach ($ this ->getExpireQuotesAdditionalFilterFields () as $ field => $ condition ) {
62
- $ quotes ->addFieldToFilter ($ field , $ condition );
63
- }
64
-
46
+ $ stores = $ this ->storeManager ->getStores (true );
47
+ foreach ($ stores as $ store ) {
48
+ /** @var $quotes Collection */
49
+ $ quotes = $ this ->expiredQuotesCollection ->getExpiredQuotes ($ store );
65
50
$ quotes ->walk ('delete ' );
66
51
}
67
52
}
68
-
69
- /**
70
- * Retrieve expire quotes additional fields to filter
71
- *
72
- * @return array
73
- */
74
- protected function getExpireQuotesAdditionalFilterFields ()
75
- {
76
- return $ this ->expireQuotesFilterFields ;
77
- }
78
-
79
- /**
80
- * Set expire quotes additional fields to filter
81
- *
82
- * @param array $fields
83
- * @return void
84
- */
85
- public function setExpireQuotesAdditionalFilterFields (array $ fields )
86
- {
87
- $ this ->expireQuotesFilterFields = $ fields ;
88
- }
89
53
}
0 commit comments