In product details page, The currency symbol shows at starting of the product price (₹125.00).
I need to show the currency symbol at end of the product price(125.00 ₹) in product details page.
i.e ., Change ₹125.00 to 125.00 ₹.
In product details page, The currency symbol shows at starting of the product price (₹125.00).
I need to show the currency symbol at end of the product price(125.00 ₹) in product details page.
i.e ., Change ₹125.00 to 125.00 ₹.
You can easily do this by just writing single event, First write events.xml
file in app>code>YOUR_VENDOR_ NAME>YOUR_MODULE_NAME>etc
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="currency_display_options_forming">
<observer name="change_currency_position" instance="YOUR_VENDOR\YOUR_MDOULENAME\Observer\CurrencyPositionChange" />
</event>
</config>
Write a observer
file in app>code>YOUR_VENDOR_ NAME>YOUR_MODULE_NAME>Observer
with the file name CurrencyPositionChange.php
<?php
namespace YOUR_VENDOR\YOUR_MDOULENAME\Observer;
use Magento\Framework\Event\ObserverInterface;
class CurrencyPositionChange implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$currencyOptions = $observer->getEvent()->getCurrencyOptions();
$currencyOptions->setData('position', \Magento\Framework\Currency::RIGHT);
return $this;
}
}
that's it and don't forgot to clear cache by
php bin/magento c:f
Magento\Framework\DataObject Object ( [_data:protected] => Array ( [position] => 16 [symbol] => ) )
but it not reflecting in the dispay result.
Try This
app/code/VendoreName/ModuleName/etc/frontend
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Directory\Model\Currency" type="VendoreName\ModuleName\Model\Currency" />
</config>
app/code/VendoreName/ModuleName/Model
Currency.php
<?php
namespace VendoreName\ModuleName\Model;
class Currency extends \Magento\Directory\Model\Currency
{
public function formatTxt($price, $options = [])
{
if (!is_numeric($price)) {
$price = $this->_localeFormat->getNumber($price);
}
$price = sprintf("%F", $price);
return $this->_localeCurrency->getCurrency($this->getCode())->toCurrency($price, $options);
}
}
app/code/VendoreName/ModuleName/etc
events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="currency_display_options_forming">
<observer name="change_currency_position" instance="VendoreName\ModuleName\Observer\ChangeCurrencyPosition" />
</event>
</config>
app/code/VendoreName/ModuleName/Observer
ChangeCurrencyPosition.php
<?php
namespace VendoreName\ModuleName\Observer;
use Magento\Framework\Event\ObserverInterface;
class ChangeCurrencyPosition implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$currencyOptions = $observer->getEvent()->getCurrencyOptions();
$currencyOptions->setData('position', \Magento\Framework\Currency::LEFT);
//$currencyOptions->setData('position', \Magento\Framework\Currency::RIGHT);
return $this;
}
}