Skip to content

Commit 4aa0461

Browse files
authored
ENGCOM-4855: [Backport] Fix #12802 - allow to override preference over CartInterface and return correct object from QuoteRepository #22549
2 parents c8b1bae + c299330 commit 4aa0461

File tree

2 files changed

+106
-74
lines changed

2 files changed

+106
-74
lines changed

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

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,33 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Quote\Model;
78

9+
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
10+
use Magento\Framework\Api\Search\FilterGroup;
11+
use Magento\Framework\Api\SearchCriteria\CollectionProcessor;
812
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
13+
use Magento\Framework\Api\SearchCriteriaInterface;
914
use Magento\Framework\App\ObjectManager;
10-
use Magento\Framework\Api\SortOrder;
15+
use Magento\Framework\Exception\InputException;
1116
use Magento\Framework\Exception\NoSuchEntityException;
17+
use Magento\Quote\Api\CartRepositoryInterface;
1218
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;
19+
use Magento\Quote\Api\Data\CartInterfaceFactory;
20+
use Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory;
2021
use Magento\Quote\Model\QuoteRepository\SaveHandler;
2122
use Magento\Quote\Model\QuoteRepository\LoadHandler;
23+
use Magento\Quote\Model\ResourceModel\Quote\Collection as QuoteCollection;
24+
use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory as QuoteCollectionFactory;
25+
use Magento\Store\Model\StoreManagerInterface;
2226

2327
/**
28+
* Quote repository.
29+
*
2430
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2531
*/
26-
class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
32+
class QuoteRepository implements CartRepositoryInterface
2733
{
2834
/**
2935
* @var Quote[]
@@ -37,6 +43,7 @@ class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
3743

3844
/**
3945
* @var QuoteFactory
46+
* @deprecated
4047
*/
4148
protected $quoteFactory;
4249

@@ -46,13 +53,13 @@ class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
4653
protected $storeManager;
4754

4855
/**
49-
* @var \Magento\Quote\Model\ResourceModel\Quote\Collection
56+
* @var QuoteCollection
5057
* @deprecated 100.2.0
5158
*/
5259
protected $quoteCollection;
5360

5461
/**
55-
* @var \Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory
62+
* @var CartSearchResultsInterfaceFactory
5663
*/
5764
protected $searchResultsDataFactory;
5865

@@ -77,43 +84,51 @@ class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
7784
private $collectionProcessor;
7885

7986
/**
80-
* @var \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory
87+
* @var QuoteCollectionFactory
8188
*/
8289
private $quoteCollectionFactory;
8390

91+
/**
92+
* @var CartInterfaceFactory
93+
*/
94+
private $cartFactory;
95+
8496
/**
8597
* Constructor
8698
*
8799
* @param QuoteFactory $quoteFactory
88100
* @param StoreManagerInterface $storeManager
89-
* @param \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection
90-
* @param \Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory $searchResultsDataFactory
101+
* @param QuoteCollection $quoteCollection
102+
* @param CartSearchResultsInterfaceFactory $searchResultsDataFactory
91103
* @param JoinProcessorInterface $extensionAttributesJoinProcessor
92104
* @param CollectionProcessorInterface|null $collectionProcessor
93-
* @param \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory|null $quoteCollectionFactory
105+
* @param QuoteCollectionFactory|null $quoteCollectionFactory
106+
* @param CartInterfaceFactory|null $cartFactory
94107
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
95108
*/
96109
public function __construct(
97110
QuoteFactory $quoteFactory,
98111
StoreManagerInterface $storeManager,
99-
\Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection,
100-
\Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory $searchResultsDataFactory,
112+
QuoteCollection $quoteCollection,
113+
CartSearchResultsInterfaceFactory $searchResultsDataFactory,
101114
JoinProcessorInterface $extensionAttributesJoinProcessor,
102115
CollectionProcessorInterface $collectionProcessor = null,
103-
\Magento\Quote\Model\ResourceModel\Quote\CollectionFactory $quoteCollectionFactory = null
116+
QuoteCollectionFactory $quoteCollectionFactory = null,
117+
CartInterfaceFactory $cartFactory = null
104118
) {
105119
$this->quoteFactory = $quoteFactory;
106120
$this->storeManager = $storeManager;
107121
$this->searchResultsDataFactory = $searchResultsDataFactory;
108122
$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);
123+
$this->collectionProcessor = $collectionProcessor ?: ObjectManager::getInstance()
124+
->get(CollectionProcessor::class);
125+
$this->quoteCollectionFactory = $quoteCollectionFactory ?: ObjectManager::getInstance()
126+
->get(QuoteCollectionFactory::class);
127+
$this->cartFactory = $cartFactory ?: ObjectManager::getInstance()->get(CartInterfaceFactory::class);
113128
}
114129

115130
/**
116-
* {@inheritdoc}
131+
* @inheritdoc
117132
*/
118133
public function get($cartId, array $sharedStoreIds = [])
119134
{
@@ -126,7 +141,7 @@ public function get($cartId, array $sharedStoreIds = [])
126141
}
127142

128143
/**
129-
* {@inheritdoc}
144+
* @inheritdoc
130145
*/
131146
public function getForCustomer($customerId, array $sharedStoreIds = [])
132147
{
@@ -140,7 +155,7 @@ public function getForCustomer($customerId, array $sharedStoreIds = [])
140155
}
141156

142157
/**
143-
* {@inheritdoc}
158+
* @inheritdoc
144159
*/
145160
public function getActive($cartId, array $sharedStoreIds = [])
146161
{
@@ -152,7 +167,7 @@ public function getActive($cartId, array $sharedStoreIds = [])
152167
}
153168

154169
/**
155-
* {@inheritdoc}
170+
* @inheritdoc
156171
*/
157172
public function getActiveForCustomer($customerId, array $sharedStoreIds = [])
158173
{
@@ -164,9 +179,9 @@ public function getActiveForCustomer($customerId, array $sharedStoreIds = [])
164179
}
165180

166181
/**
167-
* {@inheritdoc}
182+
* @inheritdoc
168183
*/
169-
public function save(\Magento\Quote\Api\Data\CartInterface $quote)
184+
public function save(CartInterface $quote)
170185
{
171186
if ($quote->getId()) {
172187
$currentQuote = $this->get($quote->getId(), [$quote->getStoreId()]);
@@ -184,9 +199,9 @@ public function save(\Magento\Quote\Api\Data\CartInterface $quote)
184199
}
185200

186201
/**
187-
* {@inheritdoc}
202+
* @inheritdoc
188203
*/
189-
public function delete(\Magento\Quote\Api\Data\CartInterface $quote)
204+
public function delete(CartInterface $quote)
190205
{
191206
$quoteId = $quote->getId();
192207
$customerId = $quote->getCustomerId();
@@ -203,13 +218,13 @@ public function delete(\Magento\Quote\Api\Data\CartInterface $quote)
203218
* @param int $identifier
204219
* @param int[] $sharedStoreIds
205220
* @throws NoSuchEntityException
206-
* @return Quote
221+
* @return CartInterface
207222
*/
208223
protected function loadQuote($loadMethod, $loadField, $identifier, array $sharedStoreIds = [])
209224
{
210-
/** @var Quote $quote */
211-
$quote = $this->quoteFactory->create();
212-
if ($sharedStoreIds) {
225+
/** @var CartInterface $quote */
226+
$quote = $this->cartFactory->create();
227+
if ($sharedStoreIds && method_exists($quote, 'setSharedStoreIds')) {
213228
$quote->setSharedStoreIds($sharedStoreIds);
214229
}
215230
$quote->setStoreId($this->storeManager->getStore()->getId())->$loadMethod($identifier);
@@ -220,9 +235,9 @@ protected function loadQuote($loadMethod, $loadField, $identifier, array $shared
220235
}
221236

222237
/**
223-
* {@inheritdoc}
238+
* @inheritdoc
224239
*/
225-
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
240+
public function getList(SearchCriteriaInterface $searchCriteria)
226241
{
227242
$this->quoteCollection = $this->quoteCollectionFactory->create();
228243
/** @var \Magento\Quote\Api\Data\CartSearchResultsInterface $searchData */
@@ -265,6 +280,7 @@ protected function addFilterGroupToCollection(FilterGroup $filterGroup, QuoteCol
265280

266281
/**
267282
* Get new SaveHandler dependency for application code.
283+
*
268284
* @return SaveHandler
269285
* @deprecated 100.1.0
270286
*/
@@ -277,6 +293,8 @@ private function getSaveHandler()
277293
}
278294

279295
/**
296+
* Get load handler instance.
297+
*
280298
* @return LoadHandler
281299
* @deprecated 100.1.0
282300
*/

0 commit comments

Comments
 (0)