Skip to content

Commit 779ddf2

Browse files
author
Dmytro Yushkin
committed
MAGETWO-56447: UPS not providing shipping rates for Puerto Rico
2 parents e0575d6 + 697c5ac commit 779ddf2

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,13 @@ public function setRequest(RateRequest $request)
325325
$destCountry = self::GUAM_COUNTRY_ID;
326326
}
327327

328-
$rowRequest->setDestCountry($this->_countryFactory->create()->load($destCountry)->getData('iso2_code'));
328+
$country = $this->_countryFactory->create()->load($destCountry);
329+
$rowRequest->setDestCountry($country->getData('iso2_code') ?: $destCountry);
329330

330331
$rowRequest->setDestRegionCode($request->getDestRegionCode());
331332

332333
if ($request->getDestPostcode()) {
333334
$rowRequest->setDestPostal($request->getDestPostcode());
334-
} else {
335335
}
336336

337337
$weight = $this->getTotalNumOfBoxes($request->getPackageWeight());

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Quote\Model\Quote\Address\RateRequest;
99
use Magento\Ups\Model\Carrier;
10+
use Magento\Directory\Model\Country;
11+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1012

1113
/**
1214
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -57,7 +59,7 @@ class CarrierTest extends \PHPUnit_Framework_TestCase
5759
protected $countryFactory;
5860

5961
/**
60-
* @var \Magento\Directory\Model\Country
62+
* @var Country|MockObject
6163
*/
6264
protected $country;
6365

@@ -309,4 +311,47 @@ public function logDataProvider()
309311
]
310312
];
311313
}
314+
315+
/**
316+
* @covers \Magento\Ups\Model\Carrier::setRequest
317+
* @param string $countryCode
318+
* @param string $foundCountryCode
319+
* @dataProvider countryDataProvider
320+
*/
321+
public function testSetRequest($countryCode, $foundCountryCode)
322+
{
323+
/** @var RateRequest $request */
324+
$request = $this->helper->getObject(RateRequest::class);
325+
$request->setData([
326+
'orig_country' => 'USA',
327+
'orig_region_code' => 'CA',
328+
'orig_post_code' => 90230,
329+
'orig_city' => 'Culver City',
330+
'dest_country_id' => $countryCode,
331+
]);
332+
333+
$this->country->expects(static::at(1))
334+
->method('load')
335+
->with($countryCode)
336+
->willReturnSelf();
337+
338+
$this->country->expects(static::any())
339+
->method('getData')
340+
->with('iso2_code')
341+
->willReturn($foundCountryCode);
342+
343+
$this->model->setRequest($request);
344+
}
345+
346+
/**
347+
* Get list of country variations
348+
* @return array
349+
*/
350+
public function countryDataProvider()
351+
{
352+
return [
353+
['countryCode' => 'PR', 'foundCountryCode' => null],
354+
['countryCode' => 'US', 'foundCountryCode' => 'US'],
355+
];
356+
}
312357
}

0 commit comments

Comments
 (0)