Skip to content

Commit ab481b3

Browse files
committed
Merge branch 'MAGETWO-49093' into MAGETWO-48463
2 parents 71a6ab8 + e2281ed commit ab481b3

File tree

4 files changed

+144
-3
lines changed

4 files changed

+144
-3
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ protected function _parseXmlResponse($response)
550550
$serviceName = $this->_filterServiceName((string)$service->SvcDescription);
551551
$serviceCode = 'INT_' . (string)$service->attributes()->ID;
552552
$serviceCodeToActualNameMap[$serviceCode] = $serviceName;
553+
if (!$this->isServiceAvailable($service)) {
554+
continue;
555+
}
553556
if (in_array($serviceCode, $allowedMethods)) {
554557
$costArr[$serviceCode] = (string)$service->Postage;
555558
$priceArr[$serviceCode] = $this->getMethodPrice(
@@ -2021,4 +2024,20 @@ protected function _parseZip($zipString, $returnFull = false)
20212024

20222025
return [$zip5, $zip4];
20232026
}
2027+
2028+
/**
2029+
* Check availability of post service
2030+
*
2031+
* @param \SimpleXMLElement $service
2032+
* @return boolean
2033+
*/
2034+
private function isServiceAvailable(\SimpleXMLElement $service)
2035+
{
2036+
foreach ($service->ExtraServices->children() as $child) {
2037+
if (filter_var($child->Available, FILTER_VALIDATE_BOOLEAN)) {
2038+
return true;
2039+
}
2040+
}
2041+
return false;
2042+
}
20242043
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Usps\Test\Unit\Model;
77

88
use Magento\Quote\Model\Quote\Address\RateRequest;
9-
use Magento\Store\Model\StoreManager;
109

1110
class CarrierTest extends \PHPUnit_Framework_TestCase
1211
{
@@ -179,14 +178,33 @@ public function testCollectRates()
179178
$this->returnValue(file_get_contents(__DIR__ . '/_files/success_usps_response_rates.xml'))
180179
);
181180
// for setRequest
181+
$data = require __DIR__ . '/_files/rates_request_data.php';
182182
$request = $this->helper->getObject(
183183
'Magento\Quote\Model\Quote\Address\RateRequest',
184-
require __DIR__ . '/_files/rates_request_data.php'
184+
['data' => $data[0]]
185185
);
186186

187187
$this->assertNotEmpty($this->carrier->collectRates($request)->getAllRates());
188188
}
189189

190+
public function testCollectRatesWithUnavailableService()
191+
{
192+
$expectedCount = 5;
193+
194+
$this->scope->expects(static::once())
195+
->method('isSetFlag')
196+
->willReturn(true);
197+
198+
$this->httpResponse->expects(static::once())
199+
->method('getBody')
200+
->willReturn(file_get_contents(__DIR__ . '/_files/response_rates.xml'));
201+
202+
$data = require __DIR__ . '/_files/rates_request_data.php';
203+
$request = $this->helper->getObject(RateRequest::class, ['data' => $data[1]]);
204+
$rates = $this->carrier->collectRates($request)->getAllRates();
205+
static::assertEquals($expectedCount, count($rates));
206+
}
207+
190208
public function testReturnOfShipment()
191209
{
192210
$this->httpResponse->expects(

app/code/Magento/Usps/Test/Unit/Model/_files/rates_request_data.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
return [
7-
'data' => [
7+
[
88
'dest_country_id' => 'US',
99
'dest_region_id' => '12',
1010
'dest_region_code' => 'CA',
@@ -34,5 +34,32 @@
3434
'height' => null,
3535
'length' => null,
3636
'width' => null,
37+
], [
38+
'dest_country_id' => 'CA',
39+
'dest_postcode' => 'M5V 3G5',
40+
'dest_country_name' => 'Canada',
41+
'package_value' => '5',
42+
'package_value_with_discount' => '5',
43+
'package_weight' => '5',
44+
'package_qty' => '1',
45+
'package_physical_value' => '5',
46+
'free_method_weight' => '5',
47+
'store_id' => '1',
48+
'website_id' => '1',
49+
'free_shipping' => '0',
50+
'limit_carrier' => 'null',
51+
'base_subtotal_incl_tax' => '5',
52+
'orig_country_id' => 'US',
53+
'country_id' => 'US',
54+
'region_id' => '12',
55+
'city' => 'Culver City',
56+
'postcode' => '90034',
57+
'usps_userid' => '213MAGEN6752',
58+
'usps_container' => 'VARIABLE',
59+
'usps_size' => 'REGULAR',
60+
'girth' => null,
61+
'height' => null,
62+
'length' => null,
63+
'width' => null,
3764
]
3865
];
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<IntlRateV2Response>
3+
<Package>
4+
<Service ID="12">
5+
<Pounds>3</Pounds>
6+
<Ounces>0</Ounces>
7+
<Postage>80.45</Postage>
8+
<ExtraServices>
9+
<ExtraService>
10+
<Available>True</Available>
11+
</ExtraService>
12+
</ExtraServices>
13+
<SvcDescription>USPS GXG&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt; Envelopes</SvcDescription>
14+
</Service>
15+
<Service ID="1">
16+
<Pounds>3</Pounds>
17+
<Ounces>0</Ounces>
18+
<Postage>54.25</Postage>
19+
<ExtraServices>
20+
<ExtraService>
21+
<Available>True</Available>
22+
</ExtraService>
23+
</ExtraServices>
24+
<SvcDescription>Priority Mail Express International&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt;</SvcDescription>
25+
</Service>
26+
<Service ID="10">
27+
<Pounds>3</Pounds>
28+
<Ounces>0</Ounces>
29+
<Postage>41.50</Postage>
30+
<ExtraServices>
31+
<ExtraService>
32+
<ServiceID>1</ServiceID>
33+
<Available>True</Available>
34+
</ExtraService>
35+
</ExtraServices>
36+
<SvcDescription>Priority Mail Express International&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt; Flat Rate Envelope</SvcDescription>
37+
</Service>
38+
<Service ID="11">
39+
<Pounds>3</Pounds>
40+
<Ounces>0</Ounces>
41+
<Postage>59.95</Postage>
42+
<ExtraServices>
43+
<ExtraService>
44+
<Available>True</Available>
45+
</ExtraService>
46+
<ExtraService>
47+
<Available>True</Available>
48+
</ExtraService>
49+
</ExtraServices>
50+
<SvcDescription>Priority Mail International&amp;lt;sup&amp;gt;&amp;#174;&amp;lt;/sup&amp;gt; Large Flat Rate Box</SvcDescription>
51+
</Service>
52+
<Service ID="15">
53+
<Pounds>3</Pounds>
54+
<Ounces>0</Ounces>
55+
<Postage>24.50</Postage>
56+
<ExtraServices>
57+
<ExtraService>
58+
<Available>False</Available>
59+
</ExtraService>
60+
<ExtraService>
61+
<Available>True</Available>
62+
</ExtraService>
63+
</ExtraServices>
64+
<SvcDescription>First-Class Package International Service&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt;</SvcDescription>
65+
</Service>
66+
<Service ID="2">
67+
<Pounds>3</Pounds>
68+
<Ounces>0</Ounces>
69+
<Postage>0.00</Postage>
70+
<ExtraServices>
71+
<ExtraService>
72+
<Available>False</Available>
73+
</ExtraService>
74+
</ExtraServices>
75+
</Service>
76+
</Package>
77+
</IntlRateV2Response>

0 commit comments

Comments
 (0)