Skip to content

Commit 8a450c8

Browse files
committed
Merge remote-tracking branch 'origin/MC-33138' into 2.4-develop-pr22
2 parents a209a3e + fcd1b58 commit 8a450c8

File tree

2 files changed

+95
-52
lines changed

2 files changed

+95
-52
lines changed

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

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

8+
use Magento\Customer\Api\AddressRepositoryInterface;
99
use Magento\Customer\Api\Data\AddressInterfaceFactory;
1010
use Magento\Customer\Model\Session as CustomerSession;
11+
use Magento\Framework\Api\ExtensibleDataInterface;
1112
use Magento\Framework\App\ObjectManager;
1213
use Magento\Framework\Exception\CouldNotSaveException;
1314
use Magento\Framework\Exception\InputException;
1415
use Magento\Framework\Exception\NoSuchEntityException;
1516
use Magento\Framework\Exception\StateException;
1617
use Magento\Framework\Reflection\DataObjectProcessor;
18+
use Magento\Quote\Api\CartRepositoryInterface;
1719
use Magento\Quote\Api\Data\AddressInterface;
1820
use Magento\Quote\Api\Data\EstimateAddressInterface;
21+
use Magento\Quote\Api\Data\ShippingMethodInterface;
1922
use Magento\Quote\Api\ShipmentEstimationInterface;
23+
use Magento\Quote\Model\Cart\ShippingMethodConverter;
24+
use Magento\Quote\Model\Quote\Address;
25+
use Magento\Quote\Model\Quote\Address\Rate;
26+
use Magento\Quote\Model\Quote\TotalsCollector;
2027
use Magento\Quote\Model\ResourceModel\Quote\Address as QuoteAddressResource;
2128

2229
/**
@@ -33,21 +40,21 @@ class ShippingMethodManagement implements
3340
/**
3441
* Quote repository.
3542
*
36-
* @var \Magento\Quote\Api\CartRepositoryInterface
43+
* @var CartRepositoryInterface
3744
*/
3845
protected $quoteRepository;
3946

4047
/**
4148
* Shipping method converter
4249
*
43-
* @var \Magento\Quote\Model\Cart\ShippingMethodConverter
50+
* @var ShippingMethodConverter
4451
*/
4552
protected $converter;
4653

4754
/**
4855
* Customer Address repository
4956
*
50-
* @var \Magento\Customer\Api\AddressRepositoryInterface
57+
* @var AddressRepositoryInterface
5158
*/
5259
protected $addressRepository;
5360

@@ -57,7 +64,7 @@ class ShippingMethodManagement implements
5764
protected $totalsCollector;
5865

5966
/**
60-
* @var \Magento\Framework\Reflection\DataObjectProcessor $dataProcessor
67+
* @var DataObjectProcessor $dataProcessor
6168
*/
6269
private $dataProcessor;
6370

@@ -79,19 +86,19 @@ class ShippingMethodManagement implements
7986
/**
8087
* Constructor
8188
*
82-
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
89+
* @param CartRepositoryInterface $quoteRepository
8390
* @param Cart\ShippingMethodConverter $converter
84-
* @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository
91+
* @param AddressRepositoryInterface $addressRepository
8592
* @param Quote\TotalsCollector $totalsCollector
8693
* @param AddressInterfaceFactory|null $addressFactory
8794
* @param QuoteAddressResource|null $quoteAddressResource
8895
* @param CustomerSession|null $customerSession
8996
*/
9097
public function __construct(
91-
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
98+
CartRepositoryInterface $quoteRepository,
9299
Cart\ShippingMethodConverter $converter,
93-
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository,
94-
\Magento\Quote\Model\Quote\TotalsCollector $totalsCollector,
100+
AddressRepositoryInterface $addressRepository,
101+
TotalsCollector $totalsCollector,
95102
AddressInterfaceFactory $addressFactory = null,
96103
QuoteAddressResource $quoteAddressResource = null,
97104
CustomerSession $customerSession = null
@@ -112,10 +119,10 @@ public function __construct(
112119
*/
113120
public function get($cartId)
114121
{
115-
/** @var \Magento\Quote\Model\Quote $quote */
122+
/** @var Quote $quote */
116123
$quote = $this->quoteRepository->getActive($cartId);
117124

118-
/** @var \Magento\Quote\Model\Quote\Address $shippingAddress */
125+
/** @var Address $shippingAddress */
119126
$shippingAddress = $quote->getShippingAddress();
120127
if (!$shippingAddress->getCountryId()) {
121128
throw new StateException(__('The shipping address is missing. Set the address and try again.'));
@@ -127,7 +134,7 @@ public function get($cartId)
127134
}
128135

129136
$shippingAddress->collectShippingRates();
130-
/** @var \Magento\Quote\Model\Quote\Address\Rate $shippingRate */
137+
/** @var Rate $shippingRate */
131138
$shippingRate = $shippingAddress->getShippingRateByCode($shippingMethod);
132139
if (!$shippingRate) {
133140
return null;
@@ -142,7 +149,7 @@ public function getList($cartId)
142149
{
143150
$output = [];
144151

145-
/** @var \Magento\Quote\Model\Quote $quote */
152+
/** @var Quote $quote */
146153
$quote = $this->quoteRepository->getActive($cartId);
147154

148155
// no methods applicable for empty carts or carts with virtual products
@@ -169,7 +176,7 @@ public function getList($cartId)
169176
*/
170177
public function set($cartId, $carrierCode, $methodCode)
171178
{
172-
/** @var \Magento\Quote\Model\Quote $quote */
179+
/** @var Quote $quote */
173180
$quote = $this->quoteRepository->getActive($cartId);
174181
try {
175182
$this->apply($cartId, $carrierCode, $methodCode);
@@ -199,7 +206,7 @@ public function set($cartId, $carrierCode, $methodCode)
199206
*/
200207
public function apply($cartId, $carrierCode, $methodCode)
201208
{
202-
/** @var \Magento\Quote\Model\Quote $quote */
209+
/** @var Quote $quote */
203210
$quote = $this->quoteRepository->getActive($cartId);
204211
if (0 == $quote->getItemsCount()) {
205212
throw new InputException(
@@ -223,9 +230,9 @@ public function apply($cartId, $carrierCode, $methodCode)
223230
/**
224231
* @inheritDoc
225232
*/
226-
public function estimateByAddress($cartId, \Magento\Quote\Api\Data\EstimateAddressInterface $address)
233+
public function estimateByAddress($cartId, EstimateAddressInterface $address)
227234
{
228-
/** @var \Magento\Quote\Model\Quote $quote */
235+
/** @var Quote $quote */
229236
$quote = $this->quoteRepository->getActive($cartId);
230237

231238
// no methods applicable for empty carts or carts with virtual products
@@ -241,7 +248,7 @@ public function estimateByAddress($cartId, \Magento\Quote\Api\Data\EstimateAddre
241248
*/
242249
public function estimateByExtendedAddress($cartId, AddressInterface $address)
243250
{
244-
/** @var \Magento\Quote\Model\Quote $quote */
251+
/** @var Quote $quote */
245252
$quote = $this->quoteRepository->getActive($cartId);
246253

247254
// no methods applicable for empty carts or carts with virtual products
@@ -256,7 +263,7 @@ public function estimateByExtendedAddress($cartId, AddressInterface $address)
256263
*/
257264
public function estimateByAddressId($cartId, $addressId)
258265
{
259-
/** @var \Magento\Quote\Model\Quote $quote */
266+
/** @var Quote $quote */
260267
$quote = $this->quoteRepository->getActive($cartId);
261268

262269
// no methods applicable for empty carts or carts with virtual products
@@ -276,13 +283,13 @@ public function estimateByAddressId($cartId, $addressId)
276283
* @param string $postcode
277284
* @param int $regionId
278285
* @param string $region
279-
* @param \Magento\Framework\Api\ExtensibleDataInterface|null $address
280-
* @return \Magento\Quote\Api\Data\ShippingMethodInterface[] An array of shipping methods.
286+
* @param ExtensibleDataInterface|null $address
287+
* @return ShippingMethodInterface[] An array of shipping methods.
281288
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
282289
* @deprecated 100.2.0
283290
*/
284291
protected function getEstimatedRates(
285-
\Magento\Quote\Model\Quote $quote,
292+
Quote $quote,
286293
$country,
287294
$postcode,
288295
$regionId,
@@ -301,9 +308,9 @@ protected function getEstimatedRates(
301308
/**
302309
* Get list of available shipping methods
303310
*
304-
* @param \Magento\Quote\Model\Quote $quote
305-
* @param \Magento\Framework\Api\ExtensibleDataInterface $address
306-
* @return \Magento\Quote\Api\Data\ShippingMethodInterface[]
311+
* @param Quote $quote
312+
* @param ExtensibleDataInterface $address
313+
* @return ShippingMethodInterface[]
307314
*/
308315
private function getShippingMethods(Quote $quote, $address)
309316
{
@@ -334,27 +341,31 @@ private function getShippingMethods(Quote $quote, $address)
334341
/**
335342
* Get transform address interface into Array
336343
*
337-
* @param \Magento\Framework\Api\ExtensibleDataInterface $address
344+
* @param ExtensibleDataInterface $address
338345
* @return array
339346
*/
340347
private function extractAddressData($address)
341348
{
342349
$className = \Magento\Customer\Api\Data\AddressInterface::class;
343-
if ($address instanceof \Magento\Quote\Api\Data\AddressInterface) {
344-
$className = \Magento\Quote\Api\Data\AddressInterface::class;
350+
if ($address instanceof AddressInterface) {
351+
$className = AddressInterface::class;
345352
} elseif ($address instanceof EstimateAddressInterface) {
346353
$className = EstimateAddressInterface::class;
347354
}
348-
return $this->getDataObjectProcessor()->buildOutputDataArray(
355+
356+
$addressData = $this->getDataObjectProcessor()->buildOutputDataArray(
349357
$address,
350358
$className
351359
);
360+
unset($addressData[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
361+
362+
return $addressData;
352363
}
353364

354365
/**
355366
* Gets the data object processor
356367
*
357-
* @return \Magento\Framework\Reflection\DataObjectProcessor
368+
* @return DataObjectProcessor
358369
* @deprecated 100.2.0
359370
*/
360371
private function getDataObjectProcessor()

0 commit comments

Comments
 (0)