0

I installed a fresh version of magento2 with the simple data, test the payment in USD using the cash on delivery, and the payment was fine.

I added more currencies KWD, EGP, and EUR. Then configure the rates. After that, I tested the payment with EUR and it was fine. I tested the payment with EGP/KWD but the price is 0 only on the checkout page. I got that the attached image

The change of the currency works fine for all pages including orders in the admin pages. shipping page payment page Admin Currency Rates Admin Configuration

2 Answers2

0

I know is late but for feature search.

Same issue here. In my case was from Currency Symbols (vendor/magento/module-directory/Model/Currency.php) method (getOutputFormat) when has to give format for price-utils.js

In case of EURO or USD the $formatted is something like this: $0.00 or €0.00 in case you have EGP the $formatted is EGP 0.00

$formatted = $this->formatTxt(0); 
RESULT: $0.00, €0.00, EGP 0.00

$number = $this->formatTxt(0, ['display' => \Magento\Framework\Currency::NO_SYMBOL]); RESULT: 0.00, €0.00, EGP0.00 return str_replace($this->trimUnicodeDirectionMark($number), '%s', $formatted); RESULT: $%s, %s, EGP 0.00

Issue in trimUnicodeDirectionMark on

preg_match('/^(\x{200E}|\x{200F})/u', $string, $match)
0

Yes, Many times this issue is a big problem. I found below file is responsible for this issue.

vendor/magento/module-directory/Model/Currency.php

Solution: https://github.com/magento/magento2/pull/33966/commits/82c1a4d1137f747b9551e7d4d87106bf2c726b9e

You need to update your core Currency.php file. You can not overwrite this core file in your custom module. I tried but it's not working. So I created a custom patch for it.

created custom patch click here: https://magento.stackexchange.com/a/368552/82670

Latest Magento version [2.4.6.p2] Custom Patch for fix this issue

--- a/vendor/magento/module-directory/Model/Currency.php    2023-09-20 10:44:14.635173580 +0200
+++ b/vendor/magento/module-directory/Model/Currency.php    2023-09-20 10:41:29.819340923 +0200
@@ -14,6 +14,7 @@
 use Magento\Framework\Locale\ResolverInterface as LocalResolverInterface;
 use Magento\Framework\NumberFormatterFactory;
 use Magento\Framework\Serialize\Serializer\Json;
+use Magento\Framework\NumberFormatter;

/**

  • Currency model

@@ -85,7 +86,7 @@ private $numberFormatterFactory;

 /**
  • * @var \Magento\Framework\NumberFormatter
    
  • * @var NumberFormatter
    */
    
    private $numberFormatter;

@@ -444,9 +445,9 @@ * Get NumberFormatter object from cache. * * @param array $options

  • * @return \Magento\Framework\NumberFormatter
    
  • * @return NumberFormatter
    */
    
  • private function getNumberFormatter(array $options): \Magento\Framework\NumberFormatter
  • private function getNumberFormatter(array $options): NumberFormatter { $locale = $this->localeResolver->getLocale() . ($this->getCode() ? '@currency=' . $this->getCode() : ''); $key = 'currency_' . hash('sha256', $locale . $this->serializer->serialize($options));

@@ -479,6 +480,7 @@ if (array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options) && $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL) { $this->numberFormatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, '');

  •        $this->numberFormatter->setPattern(str_replace('¤', '', $this->numberFormatter->getPattern()));
       }
       if (array_key_exists('precision', $options)) {
           $this->numberFormatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $options['precision']);
    

@@ -503,7 +505,7 @@ public function getOutputFormat() { $formatted = $this->formatTxt(0);

  •    $number = $this->formatTxt(0, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
    
  •    $number = str_replace($this->getCurrencySymbol(), '', $formatted);
       return $formatted !== null ? str_replace($this->trimUnicodeDirectionMark($number), '%s', $formatted) : '';
    
    }

@@ -581,9 +583,9 @@ * This method removes LRM and RLM marks from string * * @param string $string

  • * @return $this
    
  • * @return string
    */
    
  • private function trimUnicodeDirectionMark($string)
  • private function trimUnicodeDirectionMark(string $string): string { if (preg_match('/^(\x{200E}|\x{200F})/u', $string, $match)) { $string = preg_replace('/^' . $match[1] . '/u', '', $string);

Msquare
  • 9,063
  • 7
  • 25
  • 63