10
10
use Magento \Customer \Api \Data \RegionInterfaceFactory ;
11
11
use Magento \Framework \App \ObjectManager ;
12
12
use Magento \Framework \Serialize \Serializer \Json ;
13
+ use Magento \Store \Model \StoreManagerInterface ;
13
14
14
15
/**
15
16
* Sales Quote address model
@@ -202,6 +203,11 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress implements
202
203
*/
203
204
protected $ _addressTotalFactory ;
204
205
206
+ /**
207
+ * @var \Magento\Quote\Model\Quote\Address\RateFactory
208
+ */
209
+ protected $ _addressRateFactory ;
210
+
205
211
/**
206
212
* @var \Magento\Customer\Api\Data\AddressInterfaceFactory
207
213
*/
@@ -242,6 +248,11 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress implements
242
248
*/
243
249
private $ serializer ;
244
250
251
+ /**
252
+ * @var StoreManagerInterface
253
+ */
254
+ private $ storeManager ;
255
+
245
256
/**
246
257
* @param \Magento\Framework\Model\Context $context
247
258
* @param \Magento\Framework\Registry $registry
@@ -259,7 +270,7 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress implements
259
270
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
260
271
* @param Address\ItemFactory $addressItemFactory
261
272
* @param \Magento\Quote\Model\ResourceModel\Quote\Address\Item\CollectionFactory $itemCollectionFactory
262
- * @param Address\RateFactory $addressRateFactory
273
+ * @param \Magento\Quote\Model\Quote\ Address\RateFactory $addressRateFactory
263
274
* @param Address\RateCollectorInterfaceFactory $rateCollector
264
275
* @param \Magento\Quote\Model\ResourceModel\Quote\Address\Rate\CollectionFactory $rateCollectionFactory
265
276
* @param Address\RateRequestFactory $rateRequestFactory
@@ -276,6 +287,7 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress implements
276
287
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
277
288
* @param array $data
278
289
* @param Json $serializer
290
+ * @param StoreManagerInterface $storeManager
279
291
*
280
292
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
281
293
*/
@@ -312,7 +324,8 @@ public function __construct(
312
324
\Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
313
325
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
314
326
array $ data = [],
315
- Json $ serializer = null
327
+ Json $ serializer = null ,
328
+ StoreManagerInterface $ storeManager = null
316
329
) {
317
330
$ this ->_scopeConfig = $ scopeConfig ;
318
331
$ this ->_addressItemFactory = $ addressItemFactory ;
@@ -332,6 +345,7 @@ public function __construct(
332
345
$ this ->totalsCollector = $ totalsCollector ;
333
346
$ this ->totalsReader = $ totalsReader ;
334
347
$ this ->serializer = $ serializer ?: ObjectManager::getInstance ()->get (Json::class);
348
+ $ this ->storeManager = $ storeManager ?: ObjectManager::getInstance ()->get (StoreManagerInterface::class);
335
349
parent ::__construct (
336
350
$ context ,
337
351
$ registry ,
@@ -990,16 +1004,16 @@ public function requestShippingRates(\Magento\Quote\Model\Quote\Item\AbstractIte
990
1004
$ request ->setFreeMethodWeight ($ item ? 0 : $ this ->getFreeMethodWeight ());
991
1005
992
1006
/**
993
- * Store and website identifiers need specify from quote
1007
+ * Store and website identifiers specified from StoreManager
994
1008
*/
995
- $ request ->setStoreId ($ this ->getQuote () ->getStore ()->getId ());
996
- $ request ->setWebsiteId ($ this ->getQuote ()-> getStore ()->getWebsiteId ());
1009
+ $ request ->setStoreId ($ this ->storeManager ->getStore ()->getId ());
1010
+ $ request ->setWebsiteId ($ this ->storeManager -> getWebsite ()->getId ());
997
1011
$ request ->setFreeShipping ($ this ->getFreeShipping ());
998
1012
/**
999
1013
* Currencies need to convert in free shipping
1000
1014
*/
1001
- $ request ->setBaseCurrency ($ this ->getQuote () ->getStore ()->getBaseCurrency ());
1002
- $ request ->setPackageCurrency ($ this ->getQuote () ->getStore ()->getCurrentCurrency ());
1015
+ $ request ->setBaseCurrency ($ this ->storeManager ->getStore ()->getBaseCurrency ());
1016
+ $ request ->setPackageCurrency ($ this ->storeManager ->getStore ()->getCurrentCurrency ());
1003
1017
$ request ->setLimitCarrier ($ this ->getLimitCarrier ());
1004
1018
$ baseSubtotalInclTax = $ this ->getBaseSubtotalTotalInclTax ();
1005
1019
$ request ->setBaseSubtotalInclTax ($ baseSubtotalInclTax );
@@ -1021,11 +1035,10 @@ public function requestShippingRates(\Magento\Quote\Model\Quote\Item\AbstractIte
1021
1035
$ item ->setBaseShippingAmount ($ rate ->getPrice ());
1022
1036
} else {
1023
1037
1024
- /** @var \Magento\Quote\Model\Quote $quote */
1025
- $ quote = $ this ->getQuote ();
1026
- $ amountPrice = $ quote ->getStore ()
1027
- ->getBaseCurrency ()
1028
- ->convert ($ rate ->getPrice (), $ quote ->getQuoteCurrencyCode ());
1038
+ /** @var \Magento\Store\Api\Data\StoreInterface */
1039
+ $ store = $ this ->storeManager ->getStore ();
1040
+ $ amountPrice = $ store ->getBaseCurrency ()
1041
+ ->convert ($ rate ->getPrice (), $ store ->getCurrentCurrencyCode ());
1029
1042
$ this ->setBaseShippingAmount ($ rate ->getPrice ());
1030
1043
$ this ->setShippingAmount ($ amountPrice );
1031
1044
}
0 commit comments