Skip to content

Commit 3f49278

Browse files
ENGCOM-4679: Fix #12802 - allow to override preference over CartInterface and return correct object from QuoteRepository #22149
- Merge Pull Request #22149 from Bartlomiejsz/magento2:feature/fix_12802_quote_not_overridable - Merged commits: 1. 865d7df
2 parents 62ae101 + 865d7df commit 3f49278

File tree

2 files changed

+93
-67
lines changed

2 files changed

+93
-67
lines changed

app/code/Magento/Quote/Model/QuoteRepository.php

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,28 @@
55
*/
66
namespace Magento\Quote\Model;
77

8+
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
9+
use Magento\Framework\Api\Search\FilterGroup;
10+
use Magento\Framework\Api\SearchCriteria\CollectionProcessor;
811
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
12+
use Magento\Framework\Api\SearchCriteriaInterface;
913
use Magento\Framework\App\ObjectManager;
10-
use Magento\Framework\Api\SortOrder;
14+
use Magento\Framework\Exception\InputException;
1115
use Magento\Framework\Exception\NoSuchEntityException;
16+
use Magento\Quote\Api\CartRepositoryInterface;
1217
use Magento\Quote\Api\Data\CartInterface;
13-
use Magento\Quote\Model\Quote;
14-
use Magento\Store\Model\StoreManagerInterface;
15-
use Magento\Framework\Api\Search\FilterGroup;
16-
use Magento\Quote\Model\ResourceModel\Quote\Collection as QuoteCollection;
17-
use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory as QuoteCollectionFactory;
18-
use Magento\Framework\Exception\InputException;
19-
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
18+
use Magento\Quote\Api\Data\CartInterfaceFactory;
19+
use Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory;
2020
use Magento\Quote\Model\QuoteRepository\SaveHandler;
2121
use Magento\Quote\Model\QuoteRepository\LoadHandler;
22+
use Magento\Quote\Model\ResourceModel\Quote\Collection as QuoteCollection;
23+
use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory as QuoteCollectionFactory;
24+
use Magento\Store\Model\StoreManagerInterface;
2225

2326
/**
2427
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2528
*/
26-
class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
29+
class QuoteRepository implements CartRepositoryInterface
2730
{
2831
/**
2932
* @var Quote[]
@@ -37,6 +40,7 @@ class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
3740

3841
/**
3942
* @var QuoteFactory
43+
* @deprecated
4044
*/
4145
protected $quoteFactory;
4246

@@ -46,13 +50,13 @@ class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
4650
protected $storeManager;
4751

4852
/**
49-
* @var \Magento\Quote\Model\ResourceModel\Quote\Collection
53+
* @var QuoteCollection
5054
* @deprecated 100.2.0
5155
*/
5256
protected $quoteCollection;
5357

5458
/**
55-
* @var \Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory
59+
* @var CartSearchResultsInterfaceFactory
5660
*/
5761
protected $searchResultsDataFactory;
5862

@@ -77,39 +81,47 @@ class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
7781
private $collectionProcessor;
7882

7983
/**
80-
* @var \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory
84+
* @var QuoteCollectionFactory
8185
*/
8286
private $quoteCollectionFactory;
8387

88+
/**
89+
* @var CartInterfaceFactory
90+
*/
91+
private $cartFactory;
92+
8493
/**
8594
* Constructor
8695
*
8796
* @param QuoteFactory $quoteFactory
8897
* @param StoreManagerInterface $storeManager
89-
* @param \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection
90-
* @param \Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory $searchResultsDataFactory
98+
* @param QuoteCollection $quoteCollection
99+
* @param CartSearchResultsInterfaceFactory $searchResultsDataFactory
91100
* @param JoinProcessorInterface $extensionAttributesJoinProcessor
92101
* @param CollectionProcessorInterface|null $collectionProcessor
93-
* @param \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory|null $quoteCollectionFactory
102+
* @param QuoteCollectionFactory|null $quoteCollectionFactory
103+
* @param CartInterfaceFactory|null $cartFactory
94104
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
95105
*/
96106
public function __construct(
97107
QuoteFactory $quoteFactory,
98108
StoreManagerInterface $storeManager,
99-
\Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection,
100-
\Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory $searchResultsDataFactory,
109+
QuoteCollection $quoteCollection,
110+
CartSearchResultsInterfaceFactory $searchResultsDataFactory,
101111
JoinProcessorInterface $extensionAttributesJoinProcessor,
102112
CollectionProcessorInterface $collectionProcessor = null,
103-
\Magento\Quote\Model\ResourceModel\Quote\CollectionFactory $quoteCollectionFactory = null
113+
QuoteCollectionFactory $quoteCollectionFactory = null,
114+
CartInterfaceFactory $cartFactory = null
104115
) {
105116
$this->quoteFactory = $quoteFactory;
106117
$this->storeManager = $storeManager;
107118
$this->searchResultsDataFactory = $searchResultsDataFactory;
108119
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
109-
$this->collectionProcessor = $collectionProcessor ?: \Magento\Framework\App\ObjectManager::getInstance()
110-
->get(\Magento\Framework\Api\SearchCriteria\CollectionProcessor::class);
111-
$this->quoteCollectionFactory = $quoteCollectionFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
112-
->get(\Magento\Quote\Model\ResourceModel\Quote\CollectionFactory::class);
120+
$this->collectionProcessor = $collectionProcessor ?: ObjectManager::getInstance()
121+
->get(CollectionProcessor::class);
122+
$this->quoteCollectionFactory = $quoteCollectionFactory ?: ObjectManager::getInstance()
123+
->get(QuoteCollectionFactory::class);
124+
$this->cartFactory = $cartFactory ?: ObjectManager::getInstance()->get(CartInterfaceFactory::class);
113125
}
114126

115127
/**
@@ -166,7 +178,7 @@ public function getActiveForCustomer($customerId, array $sharedStoreIds = [])
166178
/**
167179
* {@inheritdoc}
168180
*/
169-
public function save(\Magento\Quote\Api\Data\CartInterface $quote)
181+
public function save(CartInterface $quote)
170182
{
171183
if ($quote->getId()) {
172184
$currentQuote = $this->get($quote->getId(), [$quote->getStoreId()]);
@@ -186,7 +198,7 @@ public function save(\Magento\Quote\Api\Data\CartInterface $quote)
186198
/**
187199
* {@inheritdoc}
188200
*/
189-
public function delete(\Magento\Quote\Api\Data\CartInterface $quote)
201+
public function delete(CartInterface $quote)
190202
{
191203
$quoteId = $quote->getId();
192204
$customerId = $quote->getCustomerId();
@@ -203,13 +215,13 @@ public function delete(\Magento\Quote\Api\Data\CartInterface $quote)
203215
* @param int $identifier
204216
* @param int[] $sharedStoreIds
205217
* @throws NoSuchEntityException
206-
* @return Quote
218+
* @return CartInterface
207219
*/
208220
protected function loadQuote($loadMethod, $loadField, $identifier, array $sharedStoreIds = [])
209221
{
210-
/** @var Quote $quote */
211-
$quote = $this->quoteFactory->create();
212-
if ($sharedStoreIds) {
222+
/** @var CartInterface $quote */
223+
$quote = $this->cartFactory->create();
224+
if ($sharedStoreIds && method_exists($quote, 'setSharedStoreIds')) {
213225
$quote->setSharedStoreIds($sharedStoreIds);
214226
}
215227
$quote->setStoreId($this->storeManager->getStore()->getId())->$loadMethod($identifier);
@@ -222,7 +234,7 @@ protected function loadQuote($loadMethod, $loadField, $identifier, array $shared
222234
/**
223235
* {@inheritdoc}
224236
*/
225-
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
237+
public function getList(SearchCriteriaInterface $searchCriteria)
226238
{
227239
$this->quoteCollection = $this->quoteCollectionFactory->create();
228240
/** @var \Magento\Quote\Api\Data\CartSearchResultsInterface $searchData */

0 commit comments

Comments
 (0)