File tree Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -410,6 +410,22 @@ public function saveRates($rates)
410
410
return $ this ;
411
411
}
412
412
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
+
413
429
/**
414
430
* This method removes LRM and RLM marks from string
415
431
*
Original file line number Diff line number Diff line change @@ -53,6 +53,32 @@ public function testGetCurrencySymbol()
53
53
$ this ->assertEquals ($ currencySymbol , $ this ->currency ->getCurrencySymbol ());
54
54
}
55
55
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
+ }
56
82
/**
57
83
* @dataProvider getOutputFormatDataProvider
58
84
* @param $withCurrency
Original file line number Diff line number Diff line change @@ -799,7 +799,9 @@ protected function _parseXmlResponse($xmlResponse)
799
799
'shipper_number '
800
800
) && !empty ($ negotiatedArr );
801
801
802
- $ allowedCurrencies = $ this ->_currencyFactory ->create ()->getConfigAllowCurrencies ();
802
+ /** @var \Magento\Directory\Model\Currency $currency */
803
+ $ currency = $ this ->_currencyFactory ->create ();
804
+ $ allowedCurrencies = $ currency ->getConfigAllowCurrencies ();
803
805
804
806
foreach ($ arr as $ shipElement ) {
805
807
$ code = (string )$ shipElement ->Service ->Code ;
@@ -812,7 +814,9 @@ protected function _parseXmlResponse($xmlResponse)
812
814
813
815
//convert price with Origin country currency code to base currency code
814
816
$ successConversion = true ;
815
- $ responseCurrencyCode = (string )$ shipElement ->TotalCharges ->CurrencyCode ;
817
+ $ responseCurrencyCode = $ currency ->mapCurrencyCode (
818
+ (string )$ shipElement ->TotalCharges ->CurrencyCode
819
+ );
816
820
if ($ responseCurrencyCode ) {
817
821
if (in_array ($ responseCurrencyCode , $ allowedCurrencies )) {
818
822
$ cost = (double )$ cost * $ this ->_getBaseCurrencyRate ($ responseCurrencyCode );
You can’t perform that action at this time.
0 commit comments