1

I will trying but its not working ?

<?php
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of Object Manager
    $currencyModel = $objectManager->create('Magento\Directory\Model\Currency'); // Instance of Currency Model
    $price =$block->getProductPrice($_product);

    $currencyCode = 'SAR';
    $currencySymbol = $currencyModel->load($currencyCode)->getCurrencySymbol();
    $precision = 2;   
    echo $formattedPrice = $currencyModel->format($price, ['symbol' => $currencySymbol, 'precision'=> $precision], true, false);
    var_dump($formattedPrice);
?>

How to solve this problams?

  • more information. what is not working. what is the error? – Philipp Sander Mar 7 at 13:40
0

You should add the option 'display' => \Magento\Framework\Currency::USE_SYMBOL in order to get the symbol.

Change your format() call like this:

echo $formattedPrice = $currencyModel->format(
         $price, [
                   'symbol' => $currencySymbol, 
                   'precision'=> $precision, 
                   'display' => \Magento\Framework\Currency::USE_SYMBOL], 
         true, false);
0
     <?php   $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
         $currencysymbol = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
         echo "<br>";

         $currencysymbol = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
         $currency2 = $currencysymbol->getStore()->getCurrentCurrencyCode();

         if ($currency2=="AED") {

         $currency = $objectManager->create('Magento\Directory\Model\Currency')->load('AED'); 
         $currency2 = $currencysymbol->getStore()->getCurrentCurrencyCode();

        echo  "<h4 class=product-price>AED".number_format($currency->convert($product->getPrice(),'AED'), 2)."</h4>";
         }
         if ($currency2=="SAR") {

            $currency = $objectManager->create('Magento\Directory\Model\Currency')->load('AED'); 
            $currency2 = $currencysymbol->getStore()->getCurrentCurrencyCode();

         echo  "<h4 class=product-price>SAR".number_format($currency->convert($product->getPrice(),'SAR'), 2)."</h4>";
            } ?>

Its Working ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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