Question

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 ?

Was it helpful?

Solution

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'));

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top