문제

I have placed order in euro

& tried to get product price in phtml file of an email template

using below code

/** @var $_item \Magento\Sales\Model\Order\Item */

$_item         = $block->getItem();
$_order        = $_item->getOrder();
$helper        = $this->helper('Vendor\Sales\Helper\Data');
$productObj    = $helper->getProductBySku($_item->getSku());

echo $_order->formatPrice($productObj->getPrice()); // This changes only currency symbol not price exg. ( product price in dollar $11 ) it converts into €11 not €8.

Any thoughts how it can be converted ?

도움이 되었습니까?

해결책

Create a method in helper

public function formatProductPrice($currencyCodeTo, $price)
            {
                $currency = $this->_storeManager->getStore()->getBaseCurrency();
                return $currency->convert($price, $currencyCodeTo);
            }

Call this method & pass required arguments

$originalPrice = $helper->formatProductPrice($_order->getOrderCurrencyCode(),$productObj->getPrice('regular_price'));

다른 팁

In magento 2, there are no 'core' module. You can get this by following way inside view file(.phtml)

$this->helper('Magento\Framework\Pricing\Helper\Data')->currency(number_format(50,2),true,false);

If the above does not work you can refer to the solutions here: How to convert number into currency format in magento2

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top