Magento 2 : How to change the currency symbol wise price in list.phtml page?
-
21-02-2021 - |
質問
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?
解決 2
<?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 ....
他のヒント
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);
所属していません magento.stackexchange