Skip to content

Commit

Permalink
Merge pull request #6019 from magento-mpi/MC-36547
Browse files Browse the repository at this point in the history
[mpi] MC-36547: Unexpected behavior of "FedEx" shipping method in the case of multiple currencies
  • Loading branch information
dhorytskyi authored Aug 13, 2020
2 parents 334ce01 + f1d4254 commit 632267c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
43 changes: 25 additions & 18 deletions app/code/Magento/Fedex/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,29 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
*/
private $_rawTrackingRequest;

/**
* ISO 4217 to Fedex currency codes matching
*
* @var string[]
*/
private $codes = [
'DOP' => 'RDD',
'XCD' => 'ECD',
'ARS' => 'ARN',
'SGD' => 'SID',
'KRW' => 'WON',
'JMD' => 'JAD',
'CHF' => 'SFR',
'JPY' => 'JYE',
'KWD' => 'KUD',
'GBP' => 'UKL',
'AED' => 'DHS',
'MXN' => 'NMP',
'UYU' => 'UYP',
'CLP' => 'CHP',
'TWD' => 'NTD',
];

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
Expand Down Expand Up @@ -678,6 +701,7 @@ protected function _getRateAmountOriginBased($rate)
*/
private function getBaseCurrencyRate(string $currencyCode): float
{
$currencyCode = array_search($currencyCode, $this->codes) ?: $currencyCode;
if (!isset($this->baseCurrencyRate[$currencyCode])) {
$baseCurrencyCode = $this->_request->getBaseCurrency()->getCode();
$rate = $this->_currencyFactory->create()
Expand Down Expand Up @@ -1033,26 +1057,9 @@ public function getCode($type, $code = '')
*/
public function getCurrencyCode()
{
$codes = [
'DOP' => 'RDD',
'XCD' => 'ECD',
'ARS' => 'ARN',
'SGD' => 'SID',
'KRW' => 'WON',
'JMD' => 'JAD',
'CHF' => 'SFR',
'JPY' => 'JYE',
'KWD' => 'KUD',
'GBP' => 'UKL',
'AED' => 'DHS',
'MXN' => 'NMP',
'UYU' => 'UYP',
'CLP' => 'CHP',
'TWD' => 'NTD',
];
$currencyCode = $this->_storeManager->getStore()->getBaseCurrencyCode();

return $codes[$currencyCode] ?? $currencyCode;
return $this->codes[$currencyCode] ?? $currencyCode;
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Fedex/Test/Unit/Model/CarrierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ public function collectRatesDataProvider()
[12.12, 'USD', 'USD', 'RATED_LIST_SHIPMENT', 12.12, 0],
[38.9, 'USD', 'USD', 'PAYOR_LIST_SHIPMENT', 38.9],
[38.9, 'USD', 'USD', 'PAYOR_LIST_SHIPMENT', 38.9, 0],
[10.0, 'SID', 'USD', 'PAYOR_LIST_SHIPMENT', 10.0, 0],
];
}

Expand Down

0 comments on commit 632267c

Please sign in to comment.