3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
-
7
6
namespace Magento \Quote \Model ;
8
7
8
+ use Magento \Customer \Api \AddressRepositoryInterface ;
9
9
use Magento \Customer \Api \Data \AddressInterfaceFactory ;
10
10
use Magento \Customer \Model \Session as CustomerSession ;
11
+ use Magento \Framework \Api \ExtensibleDataInterface ;
11
12
use Magento \Framework \App \ObjectManager ;
12
13
use Magento \Framework \Exception \CouldNotSaveException ;
13
14
use Magento \Framework \Exception \InputException ;
14
15
use Magento \Framework \Exception \NoSuchEntityException ;
15
16
use Magento \Framework \Exception \StateException ;
16
17
use Magento \Framework \Reflection \DataObjectProcessor ;
18
+ use Magento \Quote \Api \CartRepositoryInterface ;
17
19
use Magento \Quote \Api \Data \AddressInterface ;
18
20
use Magento \Quote \Api \Data \EstimateAddressInterface ;
21
+ use Magento \Quote \Api \Data \ShippingMethodInterface ;
19
22
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 ;
20
27
use Magento \Quote \Model \ResourceModel \Quote \Address as QuoteAddressResource ;
21
28
22
29
/**
@@ -33,21 +40,21 @@ class ShippingMethodManagement implements
33
40
/**
34
41
* Quote repository.
35
42
*
36
- * @var \Magento\Quote\Api\ CartRepositoryInterface
43
+ * @var CartRepositoryInterface
37
44
*/
38
45
protected $ quoteRepository ;
39
46
40
47
/**
41
48
* Shipping method converter
42
49
*
43
- * @var \Magento\Quote\Model\Cart\ ShippingMethodConverter
50
+ * @var ShippingMethodConverter
44
51
*/
45
52
protected $ converter ;
46
53
47
54
/**
48
55
* Customer Address repository
49
56
*
50
- * @var \Magento\Customer\Api\ AddressRepositoryInterface
57
+ * @var AddressRepositoryInterface
51
58
*/
52
59
protected $ addressRepository ;
53
60
@@ -57,7 +64,7 @@ class ShippingMethodManagement implements
57
64
protected $ totalsCollector ;
58
65
59
66
/**
60
- * @var \Magento\Framework\Reflection\ DataObjectProcessor $dataProcessor
67
+ * @var DataObjectProcessor $dataProcessor
61
68
*/
62
69
private $ dataProcessor ;
63
70
@@ -79,19 +86,19 @@ class ShippingMethodManagement implements
79
86
/**
80
87
* Constructor
81
88
*
82
- * @param \Magento\Quote\Api\ CartRepositoryInterface $quoteRepository
89
+ * @param CartRepositoryInterface $quoteRepository
83
90
* @param Cart\ShippingMethodConverter $converter
84
- * @param \Magento\Customer\Api\ AddressRepositoryInterface $addressRepository
91
+ * @param AddressRepositoryInterface $addressRepository
85
92
* @param Quote\TotalsCollector $totalsCollector
86
93
* @param AddressInterfaceFactory|null $addressFactory
87
94
* @param QuoteAddressResource|null $quoteAddressResource
88
95
* @param CustomerSession|null $customerSession
89
96
*/
90
97
public function __construct (
91
- \ Magento \ Quote \ Api \ CartRepositoryInterface $ quoteRepository ,
98
+ CartRepositoryInterface $ quoteRepository ,
92
99
Cart \ShippingMethodConverter $ converter ,
93
- \ Magento \ Customer \ Api \ AddressRepositoryInterface $ addressRepository ,
94
- \ Magento \ Quote \ Model \ Quote \ TotalsCollector $ totalsCollector ,
100
+ AddressRepositoryInterface $ addressRepository ,
101
+ TotalsCollector $ totalsCollector ,
95
102
AddressInterfaceFactory $ addressFactory = null ,
96
103
QuoteAddressResource $ quoteAddressResource = null ,
97
104
CustomerSession $ customerSession = null
@@ -112,10 +119,10 @@ public function __construct(
112
119
*/
113
120
public function get ($ cartId )
114
121
{
115
- /** @var \Magento\Quote\Model\ Quote $quote */
122
+ /** @var Quote $quote */
116
123
$ quote = $ this ->quoteRepository ->getActive ($ cartId );
117
124
118
- /** @var \Magento\Quote\Model\Quote\ Address $shippingAddress */
125
+ /** @var Address $shippingAddress */
119
126
$ shippingAddress = $ quote ->getShippingAddress ();
120
127
if (!$ shippingAddress ->getCountryId ()) {
121
128
throw new StateException (__ ('The shipping address is missing. Set the address and try again. ' ));
@@ -127,7 +134,7 @@ public function get($cartId)
127
134
}
128
135
129
136
$ shippingAddress ->collectShippingRates ();
130
- /** @var \Magento\Quote\Model\Quote\Address\ Rate $shippingRate */
137
+ /** @var Rate $shippingRate */
131
138
$ shippingRate = $ shippingAddress ->getShippingRateByCode ($ shippingMethod );
132
139
if (!$ shippingRate ) {
133
140
return null ;
@@ -142,7 +149,7 @@ public function getList($cartId)
142
149
{
143
150
$ output = [];
144
151
145
- /** @var \Magento\Quote\Model\ Quote $quote */
152
+ /** @var Quote $quote */
146
153
$ quote = $ this ->quoteRepository ->getActive ($ cartId );
147
154
148
155
// no methods applicable for empty carts or carts with virtual products
@@ -169,7 +176,7 @@ public function getList($cartId)
169
176
*/
170
177
public function set ($ cartId , $ carrierCode , $ methodCode )
171
178
{
172
- /** @var \Magento\Quote\Model\ Quote $quote */
179
+ /** @var Quote $quote */
173
180
$ quote = $ this ->quoteRepository ->getActive ($ cartId );
174
181
try {
175
182
$ this ->apply ($ cartId , $ carrierCode , $ methodCode );
@@ -199,7 +206,7 @@ public function set($cartId, $carrierCode, $methodCode)
199
206
*/
200
207
public function apply ($ cartId , $ carrierCode , $ methodCode )
201
208
{
202
- /** @var \Magento\Quote\Model\ Quote $quote */
209
+ /** @var Quote $quote */
203
210
$ quote = $ this ->quoteRepository ->getActive ($ cartId );
204
211
if (0 == $ quote ->getItemsCount ()) {
205
212
throw new InputException (
@@ -223,9 +230,9 @@ public function apply($cartId, $carrierCode, $methodCode)
223
230
/**
224
231
* @inheritDoc
225
232
*/
226
- public function estimateByAddress ($ cartId , \ Magento \ Quote \ Api \ Data \ EstimateAddressInterface $ address )
233
+ public function estimateByAddress ($ cartId , EstimateAddressInterface $ address )
227
234
{
228
- /** @var \Magento\Quote\Model\ Quote $quote */
235
+ /** @var Quote $quote */
229
236
$ quote = $ this ->quoteRepository ->getActive ($ cartId );
230
237
231
238
// no methods applicable for empty carts or carts with virtual products
@@ -241,7 +248,7 @@ public function estimateByAddress($cartId, \Magento\Quote\Api\Data\EstimateAddre
241
248
*/
242
249
public function estimateByExtendedAddress ($ cartId , AddressInterface $ address )
243
250
{
244
- /** @var \Magento\Quote\Model\ Quote $quote */
251
+ /** @var Quote $quote */
245
252
$ quote = $ this ->quoteRepository ->getActive ($ cartId );
246
253
247
254
// no methods applicable for empty carts or carts with virtual products
@@ -256,7 +263,7 @@ public function estimateByExtendedAddress($cartId, AddressInterface $address)
256
263
*/
257
264
public function estimateByAddressId ($ cartId , $ addressId )
258
265
{
259
- /** @var \Magento\Quote\Model\ Quote $quote */
266
+ /** @var Quote $quote */
260
267
$ quote = $ this ->quoteRepository ->getActive ($ cartId );
261
268
262
269
// no methods applicable for empty carts or carts with virtual products
@@ -276,13 +283,13 @@ public function estimateByAddressId($cartId, $addressId)
276
283
* @param string $postcode
277
284
* @param int $regionId
278
285
* @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.
281
288
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
282
289
* @deprecated 100.1.6
283
290
*/
284
291
protected function getEstimatedRates (
285
- \ Magento \ Quote \ Model \ Quote $ quote ,
292
+ Quote $ quote ,
286
293
$ country ,
287
294
$ postcode ,
288
295
$ regionId ,
@@ -301,9 +308,9 @@ protected function getEstimatedRates(
301
308
/**
302
309
* Get list of available shipping methods
303
310
*
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[]
307
314
*/
308
315
private function getShippingMethods (Quote $ quote , $ address )
309
316
{
@@ -334,27 +341,30 @@ private function getShippingMethods(Quote $quote, $address)
334
341
/**
335
342
* Get transform address interface into Array
336
343
*
337
- * @param \Magento\Framework\Api\ ExtensibleDataInterface $address
344
+ * @param ExtensibleDataInterface $address
338
345
* @return array
339
346
*/
340
347
private function extractAddressData ($ address )
341
348
{
342
349
$ 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;
345
352
} elseif ($ address instanceof EstimateAddressInterface) {
346
353
$ className = EstimateAddressInterface::class;
347
354
}
348
- return $ this ->getDataObjectProcessor ()->buildOutputDataArray (
355
+ $ addressData = $ this ->getDataObjectProcessor ()->buildOutputDataArray (
349
356
$ address ,
350
357
$ className
351
358
);
359
+ unset($ addressData [ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY ]);
360
+
361
+ return $ addressData ;
352
362
}
353
363
354
364
/**
355
365
* Gets the data object processor
356
366
*
357
- * @return \Magento\Framework\Reflection\ DataObjectProcessor
367
+ * @return DataObjectProcessor
358
368
* @deprecated 101.0.0
359
369
*/
360
370
private function getDataObjectProcessor ()
0 commit comments