浏览文章

文章信息

Magento2 货币价格转化 13809

/**
* 货币价格转化
*
* @param $amountValue
* @param null $current_currency_code
* @param null $base_currency
* @return float
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function convertPrice($amountValue, $current_currency_code = null, $base_currency = null)
{
   $current_currency_code = $current_currency_code ?? $currentCurrency = $this->storeManager->getStore()->getCurrentCurrency()->getCode();
   $base_currency = $base_currency ?? $baseCurrency = $this->storeManager->getStore()->getBaseCurrency()->getCode();
   if ($current_currency_code != $base_currency) {
       $rate = $this->currencyFactory->create()->load($current_currency_code)->getAnyRate($base_currency);
       $amountValue = $amountValue * $rate;
   }

   return $amountValue;
}


原创