Show custom currency symbol in Magento2main.CRITICAL: Plugin class doesn't existSet custom price of product when adding to cart code not workingWhy Getting categories and names on product view page Magento 2 fails?Magento 2: Add a product to the cart programmaticallyMagento 2.3 email attachment not working while sending custom email

Handling Disruptive Student on the Autism Spectrum

Photoshop: How can I change the layer type?

Ghidra: Prepend memory segment in assembly listing view

What should come first—characters or plot?

Do Bayesian credible intervals treat the estimated parameter as a random variable?

Was the Boeing 2707 design flawed?

Why is the UK so keen to remove the "backstop" when their leadership seems to think that no border will be needed in Northern Ireland?

Command "root" and "subcommands"

Separating old 2 x 4 brick with wheel holder

Why isn't "I've" a proper response?

"Opusculum hoc, quamdiu vixero, doctioribus emendandum offero."?

Does maintaining a spell with a longer casting time count as casting a spell?

How to gently end involvement with an online community?

How do I make my image comply with the requirements of this photography competition?

Non-visual Computers - thoughts?

Why do banks “park” their money at the European Central Bank?

Foreign language movie, people enter a church but find they can't leave

Boot Windows from SAN

Another solution to create a set with two conditions

Filling a listlineplot with a texture

Limitations with dynamical systems vs. PDEs?

How do proponents of Sola Scriptura address the ministry of those Apostles who authored no parts of Scripture?

What does "rel" in `mathrel` and `stackrel` stands for?

Does ostensible/specious make sense in this sentence?



Show custom currency symbol in Magento2


main.CRITICAL: Plugin class doesn't existSet custom price of product when adding to cart code not workingWhy Getting categories and names on product view page Magento 2 fails?Magento 2: Add a product to the cart programmaticallyMagento 2.3 email attachment not working while sending custom email






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I used below event



<event name="currency_display_options_forming">
<observer name="vendor_extension_change_currency_position" instance="VendorModuleObserverChangeCurrencySymbol" />
</event>


then,



<?php 
namespace VendorModuleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkLocaleCurrency;
use MagentoDirectoryModelCurrencyFactory;
class ChangeCurrencySymbol implements ObserverInterface

private $logger;
protected $symbolFactory;
protected $_coreSession;
private $currencyCode;
public function __construct(
PsrLogLoggerInterface $logger,
MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory,
MagentoFrameworkSessionSessionManagerInterface $coreSession,
CurrencyFactory $currencyFactory
)
$this->logger = $logger;
$this->symbolFactory = $symbolFactory;
$this->_coreSession = $coreSession;
$this->currencyCode = $currencyFactory->create();


public function execute(MagentoFrameworkEventObserver $observer)


$baseCode = $observer->getEvent()->getBaseCode();
$currencyOptions = $observer->getEvent()->getCurrencyOptions();
$currencyOptions->addData($this->getCurrencyOptions($baseCode));
return $this;


protected function getCurrencyOptions($baseCode)

$currencyCode = $this->getActiveCurrencyCode();

$currencyOptions = [];
if ($baseCode)

//$customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);
$currency = $this->currencyCode->load($currencyCode);
$currencySymbol = $currency->getCurrencySymbol();
$this->logger->info('currencySymbolObs'.$currencySymbol);

$this->logger->info('customCurrencySymbol'.$customCurrencySymbol);
if ($customCurrencySymbol)
$currencyOptions[Currency::CURRENCY_OPTION_SYMBOL] = $customCurrencySymbol;
$currencyOptions[Currency::CURRENCY_OPTION_DISPLAY] = MagentoFrameworkCurrency::USE_SYMBOL;


return $currencyOptions;


public function getActiveCurrencyCode()
$this->_coreSession->start();
$sessionCurrency = $this->_coreSession->getActiveCurrency();
if(isset($sessionCurrency) && $sessionCurrency != '')
return $sessionCurrency;
else
$sessionCurrency = GBP;
return $sessionCurrency;






I have drop down in header with countries, Once any country is selected, I am setting value(Currency Code) in session by calling custom controller.



$currencyCode = $this->getRequest()->getPostValue('currency_code');
$this->_coreSession->setActiveCurrency($currencyCode);


I am looking for code how can we show custom currency symbol in all the pages.



I need to get the currency Symbol from currency code and show that symbol everywhere where prices are displayed. getActiveCurrencyCode() function returns the currency code.



Above code is not working as expected, This is hitting page continuously and site is getting hanged.



Can anyone help me to achieve this functionality.



Is this approach is good to achieve that functionality? Please look into it and share your thoughts with better approach. Thanks!!










share|improve this question
































    1















    I used below event



    <event name="currency_display_options_forming">
    <observer name="vendor_extension_change_currency_position" instance="VendorModuleObserverChangeCurrencySymbol" />
    </event>


    then,



    <?php 
    namespace VendorModuleObserver;
    use MagentoFrameworkEventObserverInterface;
    use MagentoFrameworkLocaleCurrency;
    use MagentoDirectoryModelCurrencyFactory;
    class ChangeCurrencySymbol implements ObserverInterface

    private $logger;
    protected $symbolFactory;
    protected $_coreSession;
    private $currencyCode;
    public function __construct(
    PsrLogLoggerInterface $logger,
    MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory,
    MagentoFrameworkSessionSessionManagerInterface $coreSession,
    CurrencyFactory $currencyFactory
    )
    $this->logger = $logger;
    $this->symbolFactory = $symbolFactory;
    $this->_coreSession = $coreSession;
    $this->currencyCode = $currencyFactory->create();


    public function execute(MagentoFrameworkEventObserver $observer)


    $baseCode = $observer->getEvent()->getBaseCode();
    $currencyOptions = $observer->getEvent()->getCurrencyOptions();
    $currencyOptions->addData($this->getCurrencyOptions($baseCode));
    return $this;


    protected function getCurrencyOptions($baseCode)

    $currencyCode = $this->getActiveCurrencyCode();

    $currencyOptions = [];
    if ($baseCode)

    //$customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);
    $currency = $this->currencyCode->load($currencyCode);
    $currencySymbol = $currency->getCurrencySymbol();
    $this->logger->info('currencySymbolObs'.$currencySymbol);

    $this->logger->info('customCurrencySymbol'.$customCurrencySymbol);
    if ($customCurrencySymbol)
    $currencyOptions[Currency::CURRENCY_OPTION_SYMBOL] = $customCurrencySymbol;
    $currencyOptions[Currency::CURRENCY_OPTION_DISPLAY] = MagentoFrameworkCurrency::USE_SYMBOL;


    return $currencyOptions;


    public function getActiveCurrencyCode()
    $this->_coreSession->start();
    $sessionCurrency = $this->_coreSession->getActiveCurrency();
    if(isset($sessionCurrency) && $sessionCurrency != '')
    return $sessionCurrency;
    else
    $sessionCurrency = GBP;
    return $sessionCurrency;






    I have drop down in header with countries, Once any country is selected, I am setting value(Currency Code) in session by calling custom controller.



    $currencyCode = $this->getRequest()->getPostValue('currency_code');
    $this->_coreSession->setActiveCurrency($currencyCode);


    I am looking for code how can we show custom currency symbol in all the pages.



    I need to get the currency Symbol from currency code and show that symbol everywhere where prices are displayed. getActiveCurrencyCode() function returns the currency code.



    Above code is not working as expected, This is hitting page continuously and site is getting hanged.



    Can anyone help me to achieve this functionality.



    Is this approach is good to achieve that functionality? Please look into it and share your thoughts with better approach. Thanks!!










    share|improve this question




























      1












      1








      1


      1






      I used below event



      <event name="currency_display_options_forming">
      <observer name="vendor_extension_change_currency_position" instance="VendorModuleObserverChangeCurrencySymbol" />
      </event>


      then,



      <?php 
      namespace VendorModuleObserver;
      use MagentoFrameworkEventObserverInterface;
      use MagentoFrameworkLocaleCurrency;
      use MagentoDirectoryModelCurrencyFactory;
      class ChangeCurrencySymbol implements ObserverInterface

      private $logger;
      protected $symbolFactory;
      protected $_coreSession;
      private $currencyCode;
      public function __construct(
      PsrLogLoggerInterface $logger,
      MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory,
      MagentoFrameworkSessionSessionManagerInterface $coreSession,
      CurrencyFactory $currencyFactory
      )
      $this->logger = $logger;
      $this->symbolFactory = $symbolFactory;
      $this->_coreSession = $coreSession;
      $this->currencyCode = $currencyFactory->create();


      public function execute(MagentoFrameworkEventObserver $observer)


      $baseCode = $observer->getEvent()->getBaseCode();
      $currencyOptions = $observer->getEvent()->getCurrencyOptions();
      $currencyOptions->addData($this->getCurrencyOptions($baseCode));
      return $this;


      protected function getCurrencyOptions($baseCode)

      $currencyCode = $this->getActiveCurrencyCode();

      $currencyOptions = [];
      if ($baseCode)

      //$customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);
      $currency = $this->currencyCode->load($currencyCode);
      $currencySymbol = $currency->getCurrencySymbol();
      $this->logger->info('currencySymbolObs'.$currencySymbol);

      $this->logger->info('customCurrencySymbol'.$customCurrencySymbol);
      if ($customCurrencySymbol)
      $currencyOptions[Currency::CURRENCY_OPTION_SYMBOL] = $customCurrencySymbol;
      $currencyOptions[Currency::CURRENCY_OPTION_DISPLAY] = MagentoFrameworkCurrency::USE_SYMBOL;


      return $currencyOptions;


      public function getActiveCurrencyCode()
      $this->_coreSession->start();
      $sessionCurrency = $this->_coreSession->getActiveCurrency();
      if(isset($sessionCurrency) && $sessionCurrency != '')
      return $sessionCurrency;
      else
      $sessionCurrency = GBP;
      return $sessionCurrency;






      I have drop down in header with countries, Once any country is selected, I am setting value(Currency Code) in session by calling custom controller.



      $currencyCode = $this->getRequest()->getPostValue('currency_code');
      $this->_coreSession->setActiveCurrency($currencyCode);


      I am looking for code how can we show custom currency symbol in all the pages.



      I need to get the currency Symbol from currency code and show that symbol everywhere where prices are displayed. getActiveCurrencyCode() function returns the currency code.



      Above code is not working as expected, This is hitting page continuously and site is getting hanged.



      Can anyone help me to achieve this functionality.



      Is this approach is good to achieve that functionality? Please look into it and share your thoughts with better approach. Thanks!!










      share|improve this question
















      I used below event



      <event name="currency_display_options_forming">
      <observer name="vendor_extension_change_currency_position" instance="VendorModuleObserverChangeCurrencySymbol" />
      </event>


      then,



      <?php 
      namespace VendorModuleObserver;
      use MagentoFrameworkEventObserverInterface;
      use MagentoFrameworkLocaleCurrency;
      use MagentoDirectoryModelCurrencyFactory;
      class ChangeCurrencySymbol implements ObserverInterface

      private $logger;
      protected $symbolFactory;
      protected $_coreSession;
      private $currencyCode;
      public function __construct(
      PsrLogLoggerInterface $logger,
      MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory,
      MagentoFrameworkSessionSessionManagerInterface $coreSession,
      CurrencyFactory $currencyFactory
      )
      $this->logger = $logger;
      $this->symbolFactory = $symbolFactory;
      $this->_coreSession = $coreSession;
      $this->currencyCode = $currencyFactory->create();


      public function execute(MagentoFrameworkEventObserver $observer)


      $baseCode = $observer->getEvent()->getBaseCode();
      $currencyOptions = $observer->getEvent()->getCurrencyOptions();
      $currencyOptions->addData($this->getCurrencyOptions($baseCode));
      return $this;


      protected function getCurrencyOptions($baseCode)

      $currencyCode = $this->getActiveCurrencyCode();

      $currencyOptions = [];
      if ($baseCode)

      //$customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);
      $currency = $this->currencyCode->load($currencyCode);
      $currencySymbol = $currency->getCurrencySymbol();
      $this->logger->info('currencySymbolObs'.$currencySymbol);

      $this->logger->info('customCurrencySymbol'.$customCurrencySymbol);
      if ($customCurrencySymbol)
      $currencyOptions[Currency::CURRENCY_OPTION_SYMBOL] = $customCurrencySymbol;
      $currencyOptions[Currency::CURRENCY_OPTION_DISPLAY] = MagentoFrameworkCurrency::USE_SYMBOL;


      return $currencyOptions;


      public function getActiveCurrencyCode()
      $this->_coreSession->start();
      $sessionCurrency = $this->_coreSession->getActiveCurrency();
      if(isset($sessionCurrency) && $sessionCurrency != '')
      return $sessionCurrency;
      else
      $sessionCurrency = GBP;
      return $sessionCurrency;






      I have drop down in header with countries, Once any country is selected, I am setting value(Currency Code) in session by calling custom controller.



      $currencyCode = $this->getRequest()->getPostValue('currency_code');
      $this->_coreSession->setActiveCurrency($currencyCode);


      I am looking for code how can we show custom currency symbol in all the pages.



      I need to get the currency Symbol from currency code and show that symbol everywhere where prices are displayed. getActiveCurrencyCode() function returns the currency code.



      Above code is not working as expected, This is hitting page continuously and site is getting hanged.



      Can anyone help me to achieve this functionality.



      Is this approach is good to achieve that functionality? Please look into it and share your thoughts with better approach. Thanks!!







      magento2 currency currency-symbol






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 16 at 9:55







      jafar pinjar

















      asked Aug 13 at 15:47









      jafar pinjarjafar pinjar

      1,0375 silver badges27 bronze badges




      1,0375 silver badges27 bronze badges























          1 Answer
          1






          active

          oldest

          votes


















          3







          +50








          You need add "symbol" in $currencyOptions array. Please add this below code in your observer file :



          <?php
          /**
          * Copyright © Magento, Inc. All rights reserved.
          * See COPYING.txt for license details.
          */
          namespace VendorModuleObserver;

          use MagentoFrameworkLocaleCurrency;
          use MagentoFrameworkEventObserverInterface;

          class CurrencyDisplayOptions implements ObserverInterface

          /**
          * @var MagentoCurrencySymbolModelSystemCurrencysymbolFactory
          */
          protected $symbolFactory;

          /**
          * @param MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory
          */
          public function __construct(MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory)

          $this->symbolFactory = $symbolFactory;


          /**
          * Generate options for currency displaying with custom currency symbol
          *
          * @param MagentoFrameworkEventObserver $observer
          * @return $this
          */
          public function execute(MagentoFrameworkEventObserver $observer)

          $baseCode = $observer->getEvent()->getBaseCode();
          $currencyOptions = $observer->getEvent()->getCurrencyOptions();
          $currencyOptions->addData($this->getCurrencyOptions($baseCode));

          return $this;


          /**
          * Get currency display options
          *
          * @param string $baseCode
          * @return array
          */
          protected function getCurrencyOptions($baseCode)

          $currencyOptions = [];
          if ($baseCode)
          $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);
          if ($customCurrencySymbol)
          $currencyOptions[Currency::CURRENCY_OPTION_SYMBOL] = $customCurrencySymbol;
          $currencyOptions[Currency::CURRENCY_OPTION_DISPLAY] = MagentoFrameworkCurrency::USE_SYMBOL;



          return $currencyOptions;





          UPDATED :



          You loaded every time currency object using this below line and create object in construct. You should remove this below lines :



          $this->currencyCode = $currencyFactory->create(); // Remove this class from construct
          $currency = $this->currencyCode->load($currencyCode);
          $currencySymbol = $currency->getCurrencySymbol();


          and use this below line for get currency symbol :



          $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);


          Remove generated folder and clean cache.



          Hope, It will helpful for you.






          share|improve this answer



























          • hi @Rohan, this code shows my custom symbol where symbol is showing currently?

            – jafar pinjar
            Aug 14 at 6:31







          • 1





            Hi @Rohan, Great!! its working

            – jafar pinjar
            Aug 14 at 7:14











          • This has some issue, in place of this line, $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode); I have written function to get symbol based on country code, that is not working

            – jafar pinjar
            Aug 14 at 12:35











          • Using country code it will not working. You should pass currency code in that.

            – Rohan Hapani
            Aug 15 at 8:53











          • Yes, sorry Iam passing currency code only

            – jafar pinjar
            Aug 15 at 12:53













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f285369%2fshow-custom-currency-symbol-in-magento2%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3







          +50








          You need add "symbol" in $currencyOptions array. Please add this below code in your observer file :



          <?php
          /**
          * Copyright © Magento, Inc. All rights reserved.
          * See COPYING.txt for license details.
          */
          namespace VendorModuleObserver;

          use MagentoFrameworkLocaleCurrency;
          use MagentoFrameworkEventObserverInterface;

          class CurrencyDisplayOptions implements ObserverInterface

          /**
          * @var MagentoCurrencySymbolModelSystemCurrencysymbolFactory
          */
          protected $symbolFactory;

          /**
          * @param MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory
          */
          public function __construct(MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory)

          $this->symbolFactory = $symbolFactory;


          /**
          * Generate options for currency displaying with custom currency symbol
          *
          * @param MagentoFrameworkEventObserver $observer
          * @return $this
          */
          public function execute(MagentoFrameworkEventObserver $observer)

          $baseCode = $observer->getEvent()->getBaseCode();
          $currencyOptions = $observer->getEvent()->getCurrencyOptions();
          $currencyOptions->addData($this->getCurrencyOptions($baseCode));

          return $this;


          /**
          * Get currency display options
          *
          * @param string $baseCode
          * @return array
          */
          protected function getCurrencyOptions($baseCode)

          $currencyOptions = [];
          if ($baseCode)
          $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);
          if ($customCurrencySymbol)
          $currencyOptions[Currency::CURRENCY_OPTION_SYMBOL] = $customCurrencySymbol;
          $currencyOptions[Currency::CURRENCY_OPTION_DISPLAY] = MagentoFrameworkCurrency::USE_SYMBOL;



          return $currencyOptions;





          UPDATED :



          You loaded every time currency object using this below line and create object in construct. You should remove this below lines :



          $this->currencyCode = $currencyFactory->create(); // Remove this class from construct
          $currency = $this->currencyCode->load($currencyCode);
          $currencySymbol = $currency->getCurrencySymbol();


          and use this below line for get currency symbol :



          $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);


          Remove generated folder and clean cache.



          Hope, It will helpful for you.






          share|improve this answer



























          • hi @Rohan, this code shows my custom symbol where symbol is showing currently?

            – jafar pinjar
            Aug 14 at 6:31







          • 1





            Hi @Rohan, Great!! its working

            – jafar pinjar
            Aug 14 at 7:14











          • This has some issue, in place of this line, $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode); I have written function to get symbol based on country code, that is not working

            – jafar pinjar
            Aug 14 at 12:35











          • Using country code it will not working. You should pass currency code in that.

            – Rohan Hapani
            Aug 15 at 8:53











          • Yes, sorry Iam passing currency code only

            – jafar pinjar
            Aug 15 at 12:53















          3







          +50








          You need add "symbol" in $currencyOptions array. Please add this below code in your observer file :



          <?php
          /**
          * Copyright © Magento, Inc. All rights reserved.
          * See COPYING.txt for license details.
          */
          namespace VendorModuleObserver;

          use MagentoFrameworkLocaleCurrency;
          use MagentoFrameworkEventObserverInterface;

          class CurrencyDisplayOptions implements ObserverInterface

          /**
          * @var MagentoCurrencySymbolModelSystemCurrencysymbolFactory
          */
          protected $symbolFactory;

          /**
          * @param MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory
          */
          public function __construct(MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory)

          $this->symbolFactory = $symbolFactory;


          /**
          * Generate options for currency displaying with custom currency symbol
          *
          * @param MagentoFrameworkEventObserver $observer
          * @return $this
          */
          public function execute(MagentoFrameworkEventObserver $observer)

          $baseCode = $observer->getEvent()->getBaseCode();
          $currencyOptions = $observer->getEvent()->getCurrencyOptions();
          $currencyOptions->addData($this->getCurrencyOptions($baseCode));

          return $this;


          /**
          * Get currency display options
          *
          * @param string $baseCode
          * @return array
          */
          protected function getCurrencyOptions($baseCode)

          $currencyOptions = [];
          if ($baseCode)
          $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);
          if ($customCurrencySymbol)
          $currencyOptions[Currency::CURRENCY_OPTION_SYMBOL] = $customCurrencySymbol;
          $currencyOptions[Currency::CURRENCY_OPTION_DISPLAY] = MagentoFrameworkCurrency::USE_SYMBOL;



          return $currencyOptions;





          UPDATED :



          You loaded every time currency object using this below line and create object in construct. You should remove this below lines :



          $this->currencyCode = $currencyFactory->create(); // Remove this class from construct
          $currency = $this->currencyCode->load($currencyCode);
          $currencySymbol = $currency->getCurrencySymbol();


          and use this below line for get currency symbol :



          $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);


          Remove generated folder and clean cache.



          Hope, It will helpful for you.






          share|improve this answer



























          • hi @Rohan, this code shows my custom symbol where symbol is showing currently?

            – jafar pinjar
            Aug 14 at 6:31







          • 1





            Hi @Rohan, Great!! its working

            – jafar pinjar
            Aug 14 at 7:14











          • This has some issue, in place of this line, $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode); I have written function to get symbol based on country code, that is not working

            – jafar pinjar
            Aug 14 at 12:35











          • Using country code it will not working. You should pass currency code in that.

            – Rohan Hapani
            Aug 15 at 8:53











          • Yes, sorry Iam passing currency code only

            – jafar pinjar
            Aug 15 at 12:53













          3







          +50







          3







          +50



          3






          +50





          You need add "symbol" in $currencyOptions array. Please add this below code in your observer file :



          <?php
          /**
          * Copyright © Magento, Inc. All rights reserved.
          * See COPYING.txt for license details.
          */
          namespace VendorModuleObserver;

          use MagentoFrameworkLocaleCurrency;
          use MagentoFrameworkEventObserverInterface;

          class CurrencyDisplayOptions implements ObserverInterface

          /**
          * @var MagentoCurrencySymbolModelSystemCurrencysymbolFactory
          */
          protected $symbolFactory;

          /**
          * @param MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory
          */
          public function __construct(MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory)

          $this->symbolFactory = $symbolFactory;


          /**
          * Generate options for currency displaying with custom currency symbol
          *
          * @param MagentoFrameworkEventObserver $observer
          * @return $this
          */
          public function execute(MagentoFrameworkEventObserver $observer)

          $baseCode = $observer->getEvent()->getBaseCode();
          $currencyOptions = $observer->getEvent()->getCurrencyOptions();
          $currencyOptions->addData($this->getCurrencyOptions($baseCode));

          return $this;


          /**
          * Get currency display options
          *
          * @param string $baseCode
          * @return array
          */
          protected function getCurrencyOptions($baseCode)

          $currencyOptions = [];
          if ($baseCode)
          $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);
          if ($customCurrencySymbol)
          $currencyOptions[Currency::CURRENCY_OPTION_SYMBOL] = $customCurrencySymbol;
          $currencyOptions[Currency::CURRENCY_OPTION_DISPLAY] = MagentoFrameworkCurrency::USE_SYMBOL;



          return $currencyOptions;





          UPDATED :



          You loaded every time currency object using this below line and create object in construct. You should remove this below lines :



          $this->currencyCode = $currencyFactory->create(); // Remove this class from construct
          $currency = $this->currencyCode->load($currencyCode);
          $currencySymbol = $currency->getCurrencySymbol();


          and use this below line for get currency symbol :



          $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);


          Remove generated folder and clean cache.



          Hope, It will helpful for you.






          share|improve this answer















          You need add "symbol" in $currencyOptions array. Please add this below code in your observer file :



          <?php
          /**
          * Copyright © Magento, Inc. All rights reserved.
          * See COPYING.txt for license details.
          */
          namespace VendorModuleObserver;

          use MagentoFrameworkLocaleCurrency;
          use MagentoFrameworkEventObserverInterface;

          class CurrencyDisplayOptions implements ObserverInterface

          /**
          * @var MagentoCurrencySymbolModelSystemCurrencysymbolFactory
          */
          protected $symbolFactory;

          /**
          * @param MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory
          */
          public function __construct(MagentoCurrencySymbolModelSystemCurrencysymbolFactory $symbolFactory)

          $this->symbolFactory = $symbolFactory;


          /**
          * Generate options for currency displaying with custom currency symbol
          *
          * @param MagentoFrameworkEventObserver $observer
          * @return $this
          */
          public function execute(MagentoFrameworkEventObserver $observer)

          $baseCode = $observer->getEvent()->getBaseCode();
          $currencyOptions = $observer->getEvent()->getCurrencyOptions();
          $currencyOptions->addData($this->getCurrencyOptions($baseCode));

          return $this;


          /**
          * Get currency display options
          *
          * @param string $baseCode
          * @return array
          */
          protected function getCurrencyOptions($baseCode)

          $currencyOptions = [];
          if ($baseCode)
          $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);
          if ($customCurrencySymbol)
          $currencyOptions[Currency::CURRENCY_OPTION_SYMBOL] = $customCurrencySymbol;
          $currencyOptions[Currency::CURRENCY_OPTION_DISPLAY] = MagentoFrameworkCurrency::USE_SYMBOL;



          return $currencyOptions;





          UPDATED :



          You loaded every time currency object using this below line and create object in construct. You should remove this below lines :



          $this->currencyCode = $currencyFactory->create(); // Remove this class from construct
          $currency = $this->currencyCode->load($currencyCode);
          $currencySymbol = $currency->getCurrencySymbol();


          and use this below line for get currency symbol :



          $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode);


          Remove generated folder and clean cache.



          Hope, It will helpful for you.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 16 at 10:57

























          answered Aug 14 at 4:50









          Rohan HapaniRohan Hapani

          8,8984 gold badges21 silver badges66 bronze badges




          8,8984 gold badges21 silver badges66 bronze badges















          • hi @Rohan, this code shows my custom symbol where symbol is showing currently?

            – jafar pinjar
            Aug 14 at 6:31







          • 1





            Hi @Rohan, Great!! its working

            – jafar pinjar
            Aug 14 at 7:14











          • This has some issue, in place of this line, $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode); I have written function to get symbol based on country code, that is not working

            – jafar pinjar
            Aug 14 at 12:35











          • Using country code it will not working. You should pass currency code in that.

            – Rohan Hapani
            Aug 15 at 8:53











          • Yes, sorry Iam passing currency code only

            – jafar pinjar
            Aug 15 at 12:53

















          • hi @Rohan, this code shows my custom symbol where symbol is showing currently?

            – jafar pinjar
            Aug 14 at 6:31







          • 1





            Hi @Rohan, Great!! its working

            – jafar pinjar
            Aug 14 at 7:14











          • This has some issue, in place of this line, $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode); I have written function to get symbol based on country code, that is not working

            – jafar pinjar
            Aug 14 at 12:35











          • Using country code it will not working. You should pass currency code in that.

            – Rohan Hapani
            Aug 15 at 8:53











          • Yes, sorry Iam passing currency code only

            – jafar pinjar
            Aug 15 at 12:53
















          hi @Rohan, this code shows my custom symbol where symbol is showing currently?

          – jafar pinjar
          Aug 14 at 6:31






          hi @Rohan, this code shows my custom symbol where symbol is showing currently?

          – jafar pinjar
          Aug 14 at 6:31





          1




          1





          Hi @Rohan, Great!! its working

          – jafar pinjar
          Aug 14 at 7:14





          Hi @Rohan, Great!! its working

          – jafar pinjar
          Aug 14 at 7:14













          This has some issue, in place of this line, $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode); I have written function to get symbol based on country code, that is not working

          – jafar pinjar
          Aug 14 at 12:35





          This has some issue, in place of this line, $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode); I have written function to get symbol based on country code, that is not working

          – jafar pinjar
          Aug 14 at 12:35













          Using country code it will not working. You should pass currency code in that.

          – Rohan Hapani
          Aug 15 at 8:53





          Using country code it will not working. You should pass currency code in that.

          – Rohan Hapani
          Aug 15 at 8:53













          Yes, sorry Iam passing currency code only

          – jafar pinjar
          Aug 15 at 12:53





          Yes, sorry Iam passing currency code only

          – jafar pinjar
          Aug 15 at 12:53

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f285369%2fshow-custom-currency-symbol-in-magento2%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

          Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

          Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림