Currency conversion from 3 character code (USD) to their symbol as output ($) in magento 2?
-
11-05-2021 - |
Pergunta
Does magento 2 is having something inbuilt function for currency symbol getting ?
What I want is - Input will be 3 characters currency code as USD, INR, JPY, EUR etc. corresponsing to that output should be $ , ₹ , ¥ etc...
All the solutions are appreciated even if its inbuilt in magento 2 or custom function or some API.
Edit - Code Added
At the position echo $ocd;
it gives me USD after that I need to print $, it may give Euro then I need to echo € and so on..
$detail_query_1="SELECT a.quote_id,a.entity_id,a.state,a.status,a.coupon_code,a.shipping_description,a.order_currency_code,a.discount_amount,a.customer_id,a.base_discount_amount,a.base_grand_total,a.base_shipping_amount,DATE_FORMAT(a.created_at,'%d-%m-%Y') AS order_date,a.total_item_count,b.increment_id FROM rpt_sales_order AS a JOIN rpt_sales_order_grid AS b ON a.entity_id=b.entity_id WHERE 1 AND b.increment_id='$ids'";
//echo $detail_query_1;//exit;
$sql_detail_1=mysqli_query($con,$detail_query_1) or die(mysqli_error($con));
if(@mysqli_num_rows($sql_detail_1))
{
$cnt1=@mysqli_num_rows($sql_detail_1);
while($rt_details_1=mysqli_fetch_array($sql_detail_1,MYSQLI_ASSOC))
{
#print_r($rt_details);exit;
$ordDt=$rt_details_1['order_date'];
$shpDesc=$rt_details_1['shipping_description'];
$ocd= $rt_details_1['order_currency_code'];
echo $ocd;
$discount_amount= $rt_details_1['discount_amount'];
}
echo '<h3 class="shipping-method">Shipping Method: '.$shpDesc.'</h3>';
}
Thanks
Vibhore
Solução
1. Set your symbol currency from admin settings
Store -> Currency -> Currency Symbols
As per you question try below code
$currency = $_objectManager->create('Magento\Directory\Model\CurrencyFactory')->create()->load($currencyCode);
$currencySymbol = $currency->getCurrencySymbol();
As per your requirement, Add this code in php file at Magento root folder and run through Magento URL. For example: You file name script.php and run magentostore.com/script.php
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$currencyCode = 'your_code';
$currency = $objectManager->create('Magento\Directory\Model\CurrencyFactory')->create()->load($currencyCode);
echo $currencySymbol = $currency->getCurrencySymbol();
?>