Skip to content

Commit 02b59e7

Browse files
rliukshynDmytro Yushkin
authored andcommitted
MAGETWO-57097: [Backport] Issue with fetching shipping charges based on city for 2.1.x
1 parent 86e5124 commit 02b59e7

File tree

4 files changed

+101
-39
lines changed

4 files changed

+101
-39
lines changed

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
@@ -16,6 +16,9 @@ define(
1616
},
1717
'country_id': {
1818
'required': true
19+
},
20+
'city': {
21+
'required': true
1922
}
2023
};
2124
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ public function setRequest(RateRequest $request)
338338
} else {
339339
}
340340

341+
if ($request->getDestCity()) {
342+
$r->setDestCity($request->getDestCity());
343+
}
344+
341345
$weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
342346
$r->setWeight($weight);
343347
if ($request->getFreeMethodWeight() != $request->getPackageWeight()) {
@@ -432,6 +436,10 @@ protected function _formRateRequest($purpose)
432436
],
433437
];
434438

439+
if ($r->getDestCity()) {
440+
$ratesRequest['RequestedShipment']['Recipient']['Address']['City'] = $r->getDestCity();
441+
}
442+
435443
if ($purpose == self::RATE_REQUEST_GENERAL) {
436444
$ratesRequest['RequestedShipment']['RequestedPackageLineItems'][0]['InsuredValue'] = [
437445
'Amount' => $r->getValue(),

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

Lines changed: 87 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* Class CarrierTest
1515
* @package Magento\Fedex\Model
1616
* TODO refactor me
17+
*
18+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1719
*/
1820
class CarrierTest extends \PHPUnit_Framework_TestCase
1921
{
@@ -50,89 +52,126 @@ class CarrierTest extends \PHPUnit_Framework_TestCase
5052
protected function setUp()
5153
{
5254
$this->scope = $this->getMockBuilder(
53-
'\Magento\Framework\App\Config\ScopeConfigInterface'
55+
\Magento\Framework\App\Config\ScopeConfigInterface::class
5456
)->disableOriginalConstructor()->getMock();
5557

56-
$this->scope->expects(
57-
$this->any()
58-
)->method(
59-
'getValue'
60-
)->will(
61-
$this->returnCallback([$this, 'scopeConfiggetValue'])
62-
);
63-
58+
$this->scope->expects($this->any())->method('getValue')->willReturnCallback([$this, 'scopeConfiggetValue']);
6459
$country = $this->getMock(
65-
'Magento\Directory\Model\Country',
60+
\Magento\Directory\Model\Country::class,
6661
['load', 'getData', '__wakeup'],
6762
[],
6863
'',
6964
false
7065
);
7166
$country->expects($this->any())->method('load')->will($this->returnSelf());
72-
$countryFactory = $this->getMock('Magento\Directory\Model\CountryFactory', ['create'], [], '', false);
67+
$countryFactory = $this->getMock(\Magento\Directory\Model\CountryFactory::class, ['create'], [], '', false);
7368
$countryFactory->expects($this->any())->method('create')->will($this->returnValue($country));
7469

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

88-
$store = $this->getMock('Magento\Store\Model\Store', ['getBaseCurrencyCode', '__wakeup'], [], '', false);
89-
$storeManager = $this->getMockForAbstractClass('Magento\Store\Model\StoreManagerInterface');
79+
$store = $this->getMock(\Magento\Store\Model\Store::class, ['getBaseCurrencyCode', '__wakeup'], [], '', false);
80+
$storeManager = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class);
9081
$storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
91-
$priceCurrency = $this->getMockBuilder('Magento\Framework\Pricing\PriceCurrencyInterface')->getMock();
82+
$priceCurrency = $this->getMockBuilder(\Magento\Framework\Pricing\PriceCurrencyInterface::class)->getMock();
9283

9384
$rateMethod = $this->getMock(
94-
'Magento\Quote\Model\Quote\Address\RateResult\Method',
85+
\Magento\Quote\Model\Quote\Address\RateResult\Method::class,
9586
null,
9687
['priceCurrency' => $priceCurrency]
9788
);
9889
$rateMethodFactory = $this->getMock(
99-
'Magento\Quote\Model\Quote\Address\RateResult\MethodFactory',
90+
\Magento\Quote\Model\Quote\Address\RateResult\MethodFactory::class,
10091
['create'],
10192
[],
10293
'',
10394
false
10495
);
10596
$rateMethodFactory->expects($this->any())->method('create')->will($this->returnValue($rateMethod));
10697
$this->_model = $this->getMock(
107-
'Magento\Fedex\Model\Carrier',
98+
\Magento\Fedex\Model\Carrier::class,
10899
['_getCachedQuotes', '_debug'],
109100
[
110101
'scopeConfig' => $this->scope,
111102
'rateErrorFactory' => $this->errorFactory,
112-
'logger' => $this->getMock('Psr\Log\LoggerInterface'),
103+
'logger' => $this->getMock(\Psr\Log\LoggerInterface::class),
113104
'xmlSecurity' => new Security(),
114-
'xmlElFactory' => $this->getMock('Magento\Shipping\Model\Simplexml\ElementFactory', [], [], '', false),
105+
'xmlElFactory' => $this->getMock(
106+
\Magento\Shipping\Model\Simplexml\ElementFactory::class,
107+
[],
108+
[],
109+
'',
110+
false
111+
),
115112
'rateFactory' => $rateFactory,
116113
'rateMethodFactory' => $rateMethodFactory,
117-
'trackFactory' => $this->getMock('Magento\Shipping\Model\Tracking\ResultFactory', [], [], '', false),
114+
'trackFactory' => $this->getMock(
115+
\Magento\Shipping\Model\Tracking\ResultFactory::class,
116+
[],
117+
[],
118+
'',
119+
false
120+
),
118121
'trackErrorFactory' =>
119-
$this->getMock('Magento\Shipping\Model\Tracking\Result\ErrorFactory', [], [], '', false),
122+
$this->getMock(\Magento\Shipping\Model\Tracking\Result\ErrorFactory::class, [], [], '', false),
120123
'trackStatusFactory' =>
121-
$this->getMock('Magento\Shipping\Model\Tracking\Result\StatusFactory', [], [], '', false),
122-
'regionFactory' => $this->getMock('Magento\Directory\Model\RegionFactory', [], [], '', false),
124+
$this->getMock(\Magento\Shipping\Model\Tracking\Result\StatusFactory::class, [], [], '', false),
125+
'regionFactory' => $this->getMock(\Magento\Directory\Model\RegionFactory::class, [], [], '', false),
123126
'countryFactory' => $countryFactory,
124-
'currencyFactory' => $this->getMock('Magento\Directory\Model\CurrencyFactory', [], [], '', false),
125-
'directoryData' => $this->getMock('Magento\Directory\Helper\Data', [], [], '', false),
126-
'stockRegistry' => $this->getMock('Magento\CatalogInventory\Model\StockRegistry', [], [], '', false),
127+
'currencyFactory' => $this->getMock(\Magento\Directory\Model\CurrencyFactory::class, [], [], '', false),
128+
'directoryData' => $this->getMock(\Magento\Directory\Helper\Data::class, [], [], '', false),
129+
'stockRegistry' => $this->getMock(
130+
\Magento\CatalogInventory\Model\StockRegistry::class,
131+
[],
132+
[],
133+
'',
134+
false
135+
),
127136
'storeManager' => $storeManager,
128-
'configReader' => $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false),
137+
'configReader' => $this->getMock(\Magento\Framework\Module\Dir\Reader::class, [], [], '', false),
129138
'productCollectionFactory' =>
130-
$this->getMock('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory', [], [], '', false),
139+
$this->getMock(
140+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class,
141+
[],
142+
[],
143+
'',
144+
false
145+
),
131146
'data' => []
132147
]
133148
);
134149
}
135150

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

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
@@ -16,6 +16,9 @@ define(
1616
},
1717
'country_id': {
1818
'required': true
19+
},
20+
'city': {
21+
'required': true
1922
}
2023
};
2124
}

0 commit comments

Comments
 (0)