-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple conditions for expired quotes collection #24821
Closed
p-bystritsky
wants to merge
1
commit into
magento:2.3-develop
from
p-bystritsky:allow-multiple-conditions-expired-quotes
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
app/code/Magento/Sales/Model/ExpireQuotesFilterFieldsProvider.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,38 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Sales\Model; | ||
|
||
/** | ||
* Provides expire quotes filter fields. | ||
*/ | ||
class ExpireQuotesFilterFieldsProvider | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $expireQuotesFilterFields; | ||
|
||
/** | ||
* @param array $expireQuotesFilterFields | ||
*/ | ||
public function __construct( | ||
array $expireQuotesFilterFields = [] | ||
) { | ||
$this->expireQuotesFilterFields = $expireQuotesFilterFields; | ||
} | ||
|
||
/** | ||
* Get expire quotes filter fields. | ||
* | ||
* @return array | ||
*/ | ||
public function getFields(): array | ||
{ | ||
return $this->expireQuotesFilterFields; | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
dev/tests/integration/testsuite/Magento/Sales/Cron/CleanExpiredQuotesTest.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,65 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Sales\Cron; | ||
|
||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\Quote\Model\QuoteRepository; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
/** | ||
* Test for Magento\Sales\Cron\CleanExpiredQuotes class. | ||
* | ||
* @magentoAppIsolation enabled | ||
* @magentoDbIsolation enabled | ||
*/ | ||
class CleanExpiredQuotesTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var CleanExpiredQuotes | ||
*/ | ||
private $cleanExpiredQuotes; | ||
|
||
/** | ||
* @var QuoteRepository | ||
*/ | ||
private $quoteRepository; | ||
|
||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
private $searchCriteriaBuilder; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
$this->cleanExpiredQuotes = $objectManager->get(CleanExpiredQuotes::class); | ||
$this->quoteRepository = $objectManager->get(QuoteRepository::class); | ||
$this->searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class); | ||
} | ||
|
||
/** | ||
* Check if outdated quotes are deleted. | ||
* | ||
* @magentoConfigFixture default_store checkout/cart/delete_quote_after -365 | ||
* @magentoDataFixture Magento/Sales/_files/quotes.php | ||
*/ | ||
public function testExecute() | ||
{ | ||
$this->cleanExpiredQuotes->execute(); | ||
$searchCriteria = $this->searchCriteriaBuilder->create(); | ||
$totalCount = $this->quoteRepository->getList($searchCriteria)->getTotalCount(); | ||
|
||
$this->assertEquals( | ||
1, | ||
$totalCount | ||
); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
dev/tests/integration/testsuite/Magento/Sales/_files/quotes.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,35 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Quote\Model\QuoteFactory; | ||
use Magento\Quote\Model\QuoteRepository; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\ObjectManager; | ||
|
||
require dirname(dirname(__DIR__)) . '/Store/_files/second_store.php'; | ||
|
||
/** @var $objectManager ObjectManager */ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
/** @var QuoteFactory $quoteFactory */ | ||
$quoteFactory = $objectManager->get(QuoteFactory::class); | ||
/** @var QuoteRepository $quoteRepository */ | ||
$quoteRepository = $objectManager->get(QuoteRepository::class); | ||
|
||
$quotes = [ | ||
'quote for first store' => [ | ||
'store' => 1, | ||
], | ||
'quote for second store' => [ | ||
'store' => 2, | ||
], | ||
]; | ||
|
||
foreach ($quotes as $quoteData) { | ||
$quote = $quoteFactory->create(); | ||
$quote->setStoreId($quoteData['store']); | ||
$quoteRepository->save($quote); | ||
} |
36 changes: 36 additions & 0 deletions
36
dev/tests/integration/testsuite/Magento/Sales/_files/quotes_rollback.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,36 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\Framework\Registry; | ||
use Magento\Quote\Model\QuoteRepository; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\ObjectManager; | ||
|
||
/** @var ObjectManager $objectManager */ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
|
||
/** @var Registry $registry */ | ||
$registry = $objectManager->get(Registry::class); | ||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', true); | ||
|
||
/** @var QuoteRepository $quoteRepository */ | ||
$quoteRepository = $objectManager->get(QuoteRepository::class); | ||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */ | ||
$searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class); | ||
$searchCriteria = $searchCriteriaBuilder->create(); | ||
$items = $quoteRepository->getList($searchCriteria) | ||
->getItems(); | ||
foreach ($items as $item) { | ||
$quoteRepository->delete($item); | ||
} | ||
|
||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', false); | ||
|
||
require dirname(dirname(__DIR__)) . '/Store/_files/second_store_rollback.php'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really believe that we need to have a separated class to collect the filters?
Or could we just add filters as array parameter to the
app/code/Magento/Sales/Model/ResourceModel/Collection/ExpiredQuotesCollection.php
?I can not come with real case when we need a new class.