-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4830 from magento-chaika/Chaika-PR-2019-09-26
Chaika-PR-2019-09-26
- Loading branch information
Showing
7 changed files
with
125 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
app/code/Magento/Sales/Model/ResourceModel/Collection/ExpiredQuotesCollection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Sales\Model\ResourceModel\Collection; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; | ||
use Magento\Quote\Model\ResourceModel\Quote\Collection; | ||
use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory; | ||
use Magento\Store\Api\Data\StoreInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
/** | ||
* Class ExpiredQuotesCollection | ||
*/ | ||
class ExpiredQuotesCollection | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $secondsInDay = 86400; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $quoteLifetime = 'checkout/cart/delete_quote_after'; | ||
|
||
/** | ||
* @var CollectionFactory | ||
*/ | ||
private $quoteCollectionFactory; | ||
|
||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @param ScopeConfigInterface $config | ||
* @param CollectionFactory $collectionFactory | ||
*/ | ||
public function __construct( | ||
ScopeConfigInterface $config, | ||
CollectionFactory $collectionFactory | ||
) { | ||
$this->config = $config; | ||
$this->quoteCollectionFactory = $collectionFactory; | ||
} | ||
|
||
/** | ||
* Gets expired quotes | ||
* | ||
* Quote is considered expired if the latest update date | ||
* of the quote is greater than lifetime threshold | ||
* | ||
* @param StoreInterface $store | ||
* @return AbstractCollection | ||
*/ | ||
public function getExpiredQuotes(StoreInterface $store): AbstractCollection | ||
{ | ||
$lifetime = $this->config->getValue( | ||
$this->quoteLifetime, | ||
ScopeInterface::SCOPE_STORE, | ||
$store->getCode() | ||
); | ||
$lifetime *= $this->secondsInDay; | ||
|
||
/** @var $quotes Collection */ | ||
$quotes = $this->quoteCollectionFactory->create(); | ||
$quotes->addFieldToFilter('store_id', $store->getId()); | ||
$quotes->addFieldToFilter('updated_at', ['to' => date("Y-m-d", time() - $lifetime)]); | ||
|
||
return $quotes; | ||
} | ||
} |
84 changes: 0 additions & 84 deletions
84
app/code/Magento/Sales/Test/Unit/Cron/CleanExpiredQuotesTest.php
This file was deleted.
Oops, something went wrong.