Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CleanExpiredQuotes.php
Go to the documentation of this file.
1 <?php
7 
9 
14 {
15  const LIFETIME = 86400;
16 
20  protected $storesConfig;
21 
26 
30  protected $expireQuotesFilterFields = [];
31 
36  public function __construct(
38  \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory $collectionFactory
39  ) {
40  $this->storesConfig = $storesConfig;
41  $this->quoteCollectionFactory = $collectionFactory;
42  }
43 
49  public function execute()
50  {
51  $lifetimes = $this->storesConfig->getStoresConfigByPath('checkout/cart/delete_quote_after');
52  foreach ($lifetimes as $storeId => $lifetime) {
53  $lifetime *= self::LIFETIME;
54 
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  $quotes->addFieldToFilter('is_active', 0);
61 
62  foreach ($this->getExpireQuotesAdditionalFilterFields() as $field => $condition) {
63  $quotes->addFieldToFilter($field, $condition);
64  }
65 
66  $quotes->walk('delete');
67  }
68  }
69 
76  {
78  }
79 
87  {
88  $this->expireQuotesFilterFields = $fields;
89  }
90 }
__construct(StoresConfig $storesConfig, \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory $collectionFactory)
$fields
Definition: details.phtml:14