Skip to content

Commit ece763f

Browse files
author
Oleksii Korshenko
authored
Merge pull request #361 from magento-mpi/MPI-PR-2.0
Fixed issue: - MAGETWO-57098: [Backport] Issue with fetching shipping charges based on city for 2.0.x
2 parents 0b8db7e + 6cf8f13 commit ece763f

File tree

16 files changed

+560
-215
lines changed

16 files changed

+560
-215
lines changed

app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,25 @@ define(
116116

117117
addressToEstimationAddress: function (address) {
118118
var estimatedAddressData = {
119-
country_id: address.countryId,
120-
region: address.region,
121-
region_id: address.regionId,
122-
postcode: address.postcode
119+
'street': address.street,
120+
'city': address.city,
121+
'region_id': address.regionId,
122+
'region': address.region,
123+
'country_id': address.countryId,
124+
'postcode': address.postcode,
125+
'email': address.email,
126+
'customer_id': address.customerId,
127+
'firstname': address.firstname,
128+
'lastname': address.lastname,
129+
'middlename': address.middlename,
130+
'prefix': address.prefix,
131+
'suffix': address.suffix,
132+
'vat_id': address.vatId,
133+
'company': address.company,
134+
'telephone': address.telephone,
135+
'fax': address.fax,
136+
'custom_attributes': address.customAttributes
137+
123138
};
124139
return this.formAddressDataToQuoteAddress(estimatedAddressData);
125140
}

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rate-processor/new-address.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,25 @@ define(
2525
serviceUrl = resourceUrlManager.getUrlForEstimationShippingMethodsForNewAddress(quote),
2626
payload = JSON.stringify({
2727
address: {
28-
country_id: address.countryId,
29-
region_id: address.regionId,
30-
region: address.region,
31-
postcode: address.postcode
28+
'street': address.street,
29+
'city': address.city,
30+
'region_id': address.regionId,
31+
'region': address.region,
32+
'country_id': address.countryId,
33+
'postcode': address.postcode,
34+
'email': address.email,
35+
'customer_id': address.customerId,
36+
'firstname': address.firstname,
37+
'lastname': address.lastname,
38+
'middlename': address.middlename,
39+
'prefix': address.prefix,
40+
'suffix': address.suffix,
41+
'vat_id': address.vatId,
42+
'company': address.company,
43+
'telephone': address.telephone,
44+
'fax': address.fax,
45+
'custom_attributes': address.customAttributes,
46+
'save_in_address_book': address.saveInAddressBook
3247
}
3348
}
3449
);

app/code/Magento/Dhl/view/frontend/web/js/model/shipping-rates-validation-rules.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ define(
1515
},
1616
'country_id': {
1717
'required': true
18+
},
19+
'city': {
20+
'required': true
1821
}
1922
};
2023
}

app/code/Magento/Fedex/Model/Carrier.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ public function setRequest(RateRequest $request)
331331
} else {
332332
}
333333

334+
if ($request->getDestCity()) {
335+
$r->setDestCity($request->getDestCity());
336+
}
337+
334338
$weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
335339
$r->setWeight($weight);
336340
if ($request->getFreeMethodWeight() != $request->getPackageWeight()) {
@@ -425,6 +429,10 @@ protected function _formRateRequest($purpose)
425429
],
426430
];
427431

432+
if ($r->getDestCity()) {
433+
$ratesRequest['RequestedShipment']['Recipient']['Address']['City'] = $r->getDestCity();
434+
}
435+
428436
if ($purpose == self::RATE_REQUEST_GENERAL) {
429437
$ratesRequest['RequestedShipment']['RequestedPackageLineItems'][0]['InsuredValue'] = [
430438
'Amount' => $r->getValue(),

app/code/Magento/Fedex/Test/Unit/Model/CarrierTest.php

Lines changed: 90 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
*/
66
namespace Magento\Fedex\Test\Unit\Model;
77

8-
use Magento\Quote\Model\Quote\Address\RateRequest;
9-
use Magento\Framework\DataObject;
8+
use Magento\Fedex\Model\Carrier;
109
use Magento\Framework\Xml\Security;
10+
use Magento\Quote\Model\Quote\Address\RateRequest;
1111

1212
/**
1313
* Class CarrierTest
1414
* @package Magento\Fedex\Model
1515
* TODO refactor me
16+
*
17+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1618
*/
1719
class CarrierTest extends \PHPUnit_Framework_TestCase
1820
{
@@ -46,92 +48,129 @@ class CarrierTest extends \PHPUnit_Framework_TestCase
4648
/**
4749
* @return void
4850
*/
49-
public function setUp()
51+
protected function setUp()
5052
{
5153
$this->scope = $this->getMockBuilder(
52-
'\Magento\Framework\App\Config\ScopeConfigInterface'
54+
\Magento\Framework\App\Config\ScopeConfigInterface::class
5355
)->disableOriginalConstructor()->getMock();
5456

55-
$this->scope->expects(
56-
$this->any()
57-
)->method(
58-
'getValue'
59-
)->will(
60-
$this->returnCallback([$this, 'scopeConfiggetValue'])
61-
);
62-
57+
$this->scope->expects($this->any())->method('getValue')->willReturnCallback([$this, 'scopeConfiggetValue']);
6358
$country = $this->getMock(
64-
'Magento\Directory\Model\Country',
59+
\Magento\Directory\Model\Country::class,
6560
['load', 'getData', '__wakeup'],
6661
[],
6762
'',
6863
false
6964
);
7065
$country->expects($this->any())->method('load')->will($this->returnSelf());
71-
$countryFactory = $this->getMock('Magento\Directory\Model\CountryFactory', ['create'], [], '', false);
66+
$countryFactory = $this->getMock(\Magento\Directory\Model\CountryFactory::class, ['create'], [], '', false);
7267
$countryFactory->expects($this->any())->method('create')->will($this->returnValue($country));
7368

74-
$rate = $this->getMock('Magento\Shipping\Model\Rate\Result', ['getError'], [], '', false);
75-
$rateFactory = $this->getMock('Magento\Shipping\Model\Rate\ResultFactory', ['create'], [], '', false);
69+
$rate = $this->getMock(\Magento\Shipping\Model\Rate\Result::class, ['getError'], [], '', false);
70+
$rateFactory = $this->getMock(\Magento\Shipping\Model\Rate\ResultFactory::class, ['create'], [], '', false);
7671
$rateFactory->expects($this->any())->method('create')->will($this->returnValue($rate));
77-
78-
$this->error = $this->getMockBuilder('\Magento\Quote\Model\Quote\Address\RateResult\Error')
79-
->setMethods(['setCarrier', 'setCarrierTitle', 'setErrorMessage'])
80-
->getMock();
81-
$this->errorFactory = $this->getMockBuilder('Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory')
82-
->disableOriginalConstructor()
83-
->setMethods(['create'])
84-
->getMock();
72+
$this->error = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address\RateResult\Error::class)
73+
->setMethods(['setCarrier', 'setCarrierTitle', 'setErrorMessage'])->getMock();
74+
$this->errorFactory = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory::class)
75+
->disableOriginalConstructor()->setMethods(['create'])->getMock();
8576
$this->errorFactory->expects($this->any())->method('create')->willReturn($this->error);
8677

87-
$store = $this->getMock('Magento\Store\Model\Store', ['getBaseCurrencyCode', '__wakeup'], [], '', false);
88-
$storeManager = $this->getMockForAbstractClass('Magento\Store\Model\StoreManagerInterface');
78+
$store = $this->getMock(\Magento\Store\Model\Store::class, ['getBaseCurrencyCode', '__wakeup'], [], '', false);
79+
$storeManager = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class);
8980
$storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
90-
$priceCurrency = $this->getMockBuilder('Magento\Framework\Pricing\PriceCurrencyInterface')->getMock();
81+
$priceCurrency = $this->getMockBuilder(\Magento\Framework\Pricing\PriceCurrencyInterface::class)->getMock();
9182

9283
$rateMethod = $this->getMock(
93-
'Magento\Quote\Model\Quote\Address\RateResult\Method',
84+
\Magento\Quote\Model\Quote\Address\RateResult\Method::class,
9485
null,
9586
['priceCurrency' => $priceCurrency]
9687
);
9788
$rateMethodFactory = $this->getMock(
98-
'Magento\Quote\Model\Quote\Address\RateResult\MethodFactory',
89+
\Magento\Quote\Model\Quote\Address\RateResult\MethodFactory::class,
9990
['create'],
10091
[],
10192
'',
10293
false
10394
);
10495
$rateMethodFactory->expects($this->any())->method('create')->will($this->returnValue($rateMethod));
10596
$this->_model = $this->getMock(
106-
'Magento\Fedex\Model\Carrier',
97+
\Magento\Fedex\Model\Carrier::class,
10798
['_getCachedQuotes', '_debug'],
10899
[
109100
'scopeConfig' => $this->scope,
110101
'rateErrorFactory' => $this->errorFactory,
111-
'logger' => $this->getMock('Psr\Log\LoggerInterface'),
102+
'logger' => $this->getMock(\Psr\Log\LoggerInterface::class),
112103
'xmlSecurity' => new Security(),
113-
'xmlElFactory' => $this->getMock('Magento\Shipping\Model\Simplexml\ElementFactory', [], [], '', false),
104+
'xmlElFactory' => $this->getMock(
105+
\Magento\Shipping\Model\Simplexml\ElementFactory::class,
106+
[],
107+
[],
108+
'',
109+
false
110+
),
114111
'rateFactory' => $rateFactory,
115112
'rateMethodFactory' => $rateMethodFactory,
116-
'trackFactory' => $this->getMock('Magento\Shipping\Model\Tracking\ResultFactory', [], [], '', false),
113+
'trackFactory' => $this->getMock(
114+
\Magento\Shipping\Model\Tracking\ResultFactory::class,
115+
[],
116+
[],
117+
'',
118+
false
119+
),
117120
'trackErrorFactory' =>
118-
$this->getMock('Magento\Shipping\Model\Tracking\Result\ErrorFactory', [], [], '', false),
121+
$this->getMock(\Magento\Shipping\Model\Tracking\Result\ErrorFactory::class, [], [], '', false),
119122
'trackStatusFactory' =>
120-
$this->getMock('Magento\Shipping\Model\Tracking\Result\StatusFactory', [], [], '', false),
121-
'regionFactory' => $this->getMock('Magento\Directory\Model\RegionFactory', [], [], '', false),
123+
$this->getMock(\Magento\Shipping\Model\Tracking\Result\StatusFactory::class, [], [], '', false),
124+
'regionFactory' => $this->getMock(\Magento\Directory\Model\RegionFactory::class, [], [], '', false),
122125
'countryFactory' => $countryFactory,
123-
'currencyFactory' => $this->getMock('Magento\Directory\Model\CurrencyFactory', [], [], '', false),
124-
'directoryData' => $this->getMock('Magento\Directory\Helper\Data', [], [], '', false),
125-
'stockRegistry' => $this->getMock('Magento\CatalogInventory\Model\StockRegistry', [], [], '', false),
126+
'currencyFactory' => $this->getMock(\Magento\Directory\Model\CurrencyFactory::class, [], [], '', false),
127+
'directoryData' => $this->getMock(\Magento\Directory\Helper\Data::class, [], [], '', false),
128+
'stockRegistry' => $this->getMock(
129+
\Magento\CatalogInventory\Model\StockRegistry::class,
130+
[],
131+
[],
132+
'',
133+
false
134+
),
126135
'storeManager' => $storeManager,
127-
'configReader' => $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false),
136+
'configReader' => $this->getMock(\Magento\Framework\Module\Dir\Reader::class, [], [], '', false),
128137
'productCollectionFactory' =>
129-
$this->getMock('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory', [], [], '', false),
138+
$this->getMock(
139+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class,
140+
[],
141+
[],
142+
'',
143+
false
144+
),
130145
'data' => []
131146
]
132147
);
133148
}
134149

150+
public function testSetRequestWithoutCity()
151+
{
152+
$requestMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address\RateRequest::class)
153+
->disableOriginalConstructor()
154+
->setMethods(['getDestCity'])
155+
->getMock();
156+
$requestMock->expects($this->once())
157+
->method('getDestCity')
158+
->willReturn(null);
159+
$this->_model->setRequest($requestMock);
160+
}
161+
162+
public function testSetRequestWithCity()
163+
{
164+
$requestMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address\RateRequest::class)
165+
->disableOriginalConstructor()
166+
->setMethods(['getDestCity'])
167+
->getMock();
168+
$requestMock->expects($this->exactly(2))
169+
->method('getDestCity')
170+
->willReturn('Small Town');
171+
$this->_model->setRequest($requestMock);
172+
}
173+
135174
/**
136175
* Callback function, emulates getValue function
137176
* @param $path
@@ -178,7 +217,16 @@ public function testCollectRatesRateAmountOriginBased($amount, $rateType, $expec
178217
$this->_model->expects($this->any())->method('_getCachedQuotes')->will(
179218
$this->returnValue(serialize($response))
180219
);
181-
$request = $this->getMock('Magento\Quote\Model\Quote\Address\RateRequest', [], [], '', false);
220+
$request = $this->getMock(
221+
\Magento\Quote\Model\Quote\Address\RateRequest::class,
222+
['getDestCity'],
223+
[],
224+
'',
225+
false
226+
);
227+
$request->expects($this->exactly(2))
228+
->method('getDestCity')
229+
->willReturn('Wonderful City');
182230
foreach ($this->_model->collectRates($request)->getAllRates() as $allRates) {
183231
$this->assertEquals($expected, $allRates->getData('cost'));
184232
}

app/code/Magento/Fedex/view/frontend/web/js/model/shipping-rates-validation-rules.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ define(
1515
},
1616
'country_id': {
1717
'required': true
18+
},
19+
'city': {
20+
'required': true
1821
}
1922
};
2023
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Quote\Api;
7+
8+
/**
9+
* Interface GuestShipmentEstimationInterface
10+
* @api
11+
*/
12+
interface GuestShipmentEstimationInterface extends ShipmentEstimationInterface
13+
{
14+
15+
}

app/code/Magento/Quote/Api/GuestShippingMethodManagementInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function getList($cartId);
2727
* @param string $cartId The shopping cart ID.
2828
* @param \Magento\Quote\Api\Data\EstimateAddressInterface $address The estimate address
2929
* @return \Magento\Quote\Api\Data\ShippingMethodInterface[] An array of shipping methods.
30+
* @deprecated
3031
*/
3132
public function estimateByAddress($cartId, \Magento\Quote\Api\Data\EstimateAddressInterface $address);
3233
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Quote\Api;
7+
8+
use Magento\Quote\Api\Data\AddressInterface;
9+
10+
/**
11+
* Interface ShipmentManagementInterface
12+
* @api
13+
*/
14+
interface ShipmentEstimationInterface
15+
{
16+
/**
17+
* Estimate shipping by address and return list of available shipping methods
18+
* @param mixed $cartId
19+
* @param AddressInterface $address
20+
* @return \Magento\Quote\Api\Data\ShippingMethodInterface[] An array of shipping methods
21+
*/
22+
public function estimateByExtendedAddress($cartId, AddressInterface $address);
23+
}

app/code/Magento/Quote/Api/ShippingMethodManagementInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface ShippingMethodManagementInterface
1717
* @param int $cartId The shopping cart ID.
1818
* @param \Magento\Quote\Api\Data\EstimateAddressInterface $address The estimate address
1919
* @return \Magento\Quote\Api\Data\ShippingMethodInterface[] An array of shipping methods.
20+
* @deprecated
2021
*/
2122
public function estimateByAddress($cartId, \Magento\Quote\Api\Data\EstimateAddressInterface $address);
2223

0 commit comments

Comments
 (0)