Skip to content

Commit 046a7a8

Browse files
committed
MAGETWO-53795: [Github] Ups shipping method CNY vs RMB currencycode problem
- Add currency code mapping
1 parent 04795a6 commit 046a7a8

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

app/code/Magento/Directory/Model/Currency.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,22 @@ public function saveRates($rates)
410410
return $this;
411411
}
412412

413+
/**
414+
* Map currency alias to currency code
415+
*
416+
* @param string $code
417+
* @return string
418+
*/
419+
public function mapCurrencyCode($code)
420+
{
421+
$currencyMapping = [
422+
'RMB' => 'CNY',
423+
'CNH' => 'CNY'
424+
];
425+
426+
return isset($currencyMapping[$code]) ? $currencyMapping[$code] : $code;
427+
}
428+
413429
/**
414430
* This method removes LRM and RLM marks from string
415431
*

app/code/Magento/Directory/Test/Unit/Model/CurrencyTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,32 @@ public function testGetCurrencySymbol()
5353
$this->assertEquals($currencySymbol, $this->currency->getCurrencySymbol());
5454
}
5555

56+
/**
57+
* @dataProvider mapCurrencyCodeDataProvider
58+
* @param string $currencyCode
59+
* @param string $expected
60+
*/
61+
public function testMapCurrencyCode($currencyCode, $expected)
62+
{
63+
static::assertEquals(
64+
$expected,
65+
$this->currency->mapCurrencyCode($currencyCode)
66+
);
67+
}
68+
69+
/**
70+
* Return data sets for testMapCurrencyCode()
71+
*
72+
* @return array
73+
*/
74+
public function mapCurrencyCodeDataProvider()
75+
{
76+
return [
77+
['RMB', 'CNY'],
78+
['CNH', 'CNY'],
79+
['USD', 'USD']
80+
];
81+
}
5682
/**
5783
* @dataProvider getOutputFormatDataProvider
5884
* @param $withCurrency

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,9 @@ protected function _parseXmlResponse($xmlResponse)
799799
'shipper_number'
800800
) && !empty($negotiatedArr);
801801

802-
$allowedCurrencies = $this->_currencyFactory->create()->getConfigAllowCurrencies();
802+
/** @var \Magento\Directory\Model\Currency $currency */
803+
$currency = $this->_currencyFactory->create();
804+
$allowedCurrencies = $currency->getConfigAllowCurrencies();
803805

804806
foreach ($arr as $shipElement) {
805807
$code = (string)$shipElement->Service->Code;
@@ -812,7 +814,9 @@ protected function _parseXmlResponse($xmlResponse)
812814

813815
//convert price with Origin country currency code to base currency code
814816
$successConversion = true;
815-
$responseCurrencyCode = (string)$shipElement->TotalCharges->CurrencyCode;
817+
$responseCurrencyCode = $currency->mapCurrencyCode(
818+
(string)$shipElement->TotalCharges->CurrencyCode
819+
);
816820
if ($responseCurrencyCode) {
817821
if (in_array($responseCurrencyCode, $allowedCurrencies)) {
818822
$cost = (double)$cost * $this->_getBaseCurrencyRate($responseCurrencyCode);

0 commit comments

Comments
 (0)