0

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 ?

1
  • Any thoughts on this ?
    – devhs
    Commented Apr 5, 2021 at 10:18

2 Answers 2

0

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.