Order summary are showing zero subtotal on both cart page and checkout page. I have checked error log but i can't fin anything related to my issue. you can also view what i meant here https://vimeo.com/773253273 Note: i have disabled all third party extensions, i am currently using Rokantheme complex multipurpose theme
1 Answer
You need to create a patch for it. And it's a local issue.
- Install package for managing patches in composer:
composer require cweagans/composer-patches --ignore-platform-reqs
- Create a new patch file using the below command. copy this file (file A) and also copy your vendor/magento/module-directory/Model/Currency.php file (file B). Temporarily create a new folder and move both file A and file B. open the terminal that file location and run the below command.
diff -u Currency.php CurrencyUpdate.php > fix_price_zero.patch
- Now Copy that fix_price_zero.patch file and create a new folder in root Magento name: patches, paste your fix_price_zero.patch file here.
- Add the below content into the composer.json file
"extra": {
"magento-force": "override",
"patches-file": "composer-patches.json",
"composer-exit-on-patch-failure": true
}
- Create a new composer-patches.json file at Magento root and add the below content.
{
"patches": {
"magento/module-directory": {
"Price hotfix": "patches/fix_price_zero.patch"
}
}
}
- Then run below command and patch is applied.
composer install --ignore-platform-reqs
Reference Links
https://github.com/magento/magento2/issues/33798
https://github.com/magento/magento2/issues/34139
https://github.com/magento/magento2/pull/33966/commits/82c1a4d1137f747b9551e7d4d87106bf2c726b9e
https://github.com/magento/magento2/issues/34799
https://github.com/magento/magento2/issues/33856
https://github.com/magento/magento2/issues/34229
https://pandagroup.co/blog/composer-patches-in-magento-2/
Update
MY PATACH FILE fix_price_zero.patch
--- a/vendor/magento/module-directory/Model/Currency.php 2022-07-21 08:45:08.000000000 +0530
+++ b/vendor/magento/module-directory/Model/Currency.php 2022-11-21 15:27:16.005540428 +0530
@@ -11,9 +11,9 @@
use Magento\Directory\Model\Currency\Filter;
use Magento\Framework\Locale\Currency as LocaleCurrency;
use Magento\Framework\Locale\ResolverInterface as LocalResolverInterface;
+use Magento\Framework\NumberFormatter;
use Magento\Framework\NumberFormatterFactory;
use Magento\Framework\Serialize\Serializer\Json;
-use Magento\Framework\Exception\LocalizedException;
/**
* Currency model
@@ -28,11 +28,11 @@
/**
* CONFIG path constants
*/
- public const XML_PATH_CURRENCY_ALLOW = 'currency/options/allow';
+ const XML_PATH_CURRENCY_ALLOW = 'currency/options/allow';
- public const XML_PATH_CURRENCY_DEFAULT = 'currency/options/default';
+ const XML_PATH_CURRENCY_DEFAULT = 'currency/options/default';
- public const XML_PATH_CURRENCY_BASE = 'currency/options/base';
+ const XML_PATH_CURRENCY_BASE = 'currency/options/base';
/**
* @var Filter
@@ -40,6 +40,8 @@
protected $_filter;
/**
+ * Currency Rates
+ *
* @var array
*/
protected $_rates;
@@ -85,7 +87,7 @@
private $numberFormatterFactory;
/**
- * @var \Magento\Framework\NumberFormatter
+ * @var NumberFormatter
*/
private $numberFormatter;
@@ -146,14 +148,11 @@
$this->_localeCurrency = $localeCurrency;
$this->currencyConfig = $currencyConfig ?: ObjectManager::getInstance()->get(CurrencyConfig::class);
$this->localeResolver = $localeResolver ?: ObjectManager::getInstance()->get(LocalResolverInterface::class);
- $this->numberFormatterFactory = $numberFormatterFactory ?:
- ObjectManager::getInstance()->get(NumberFormatterFactory::class);
+ $this->numberFormatterFactory = $numberFormatterFactory ?: ObjectManager::getInstance()->get(NumberFormatterFactory::class);
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
}
/**
- * Initializing Currency Resource model
- *
* @return void
*/
protected function _construct()
@@ -255,10 +254,10 @@
/**
* Convert price to currency format
*
- * @param float $price
- * @param mixed $toCurrency
- * @return float
- * @throws LocalizedException
+ * @param float $price
+ * @param mixed $toCurrency
+ * @return float
+ * @throws \Exception
*/
public function convert($price, $toCurrency = null)
{
@@ -268,7 +267,7 @@
return (float)$price * (float)$rate;
}
- throw new LocalizedException(__(
+ throw new \Exception(__(
'Undefined rate from "%1-%2".',
$this->getCode(),
$this->getCurrencyCodeFromToCurrency($toCurrency)
@@ -276,10 +275,7 @@
}
/**
- * Return the currency code
- *
* @param mixed $toCurrency
- *
* @return string
* @throws \Magento\Framework\Exception\InputException
*/
@@ -353,11 +349,8 @@
}
/**
- * Return formatted currency
- *
* @param float $price
* @param array $options
- *
* @return string
*/
public function formatTxt($price, $options = [])
@@ -428,18 +421,17 @@
$this->numberFormatter = $this->getNumberFormatter($options);
$formattedCurrency = $this->numberFormatter->formatCurrency(
- $price,
- $this->getCode() ?? $this->numberFormatter->getTextAttribute(\NumberFormatter::CURRENCY_CODE)
+ $price, $this->getCode() ?? $this->numberFormatter->getTextAttribute(\NumberFormatter::CURRENCY_CODE)
);
if (array_key_exists(LocaleCurrency::CURRENCY_OPTION_SYMBOL, $options)) {
// remove only one non-breaking space from custom currency symbol to allow custom NBSP in currency symbol
- $formattedCurrency = preg_replace('/ /u', '', $formattedCurrency, 1);
+ $formattedCurrency = preg_replace('/ /u', '', $formattedCurrency, 1);
}
if ((array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options)
- && $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL)) {
- $formattedCurrency = str_replace(' ', '', $formattedCurrency);
+ && $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL)) {
+ $formattedCurrency = str_replace(' ', '', $formattedCurrency);
}
return preg_replace('/^\s+|\s+$/u', '', $formattedCurrency);
@@ -449,15 +441,14 @@
* 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));
+ $key = 'currency_' . md5($this->localeResolver->getLocale() . $this->serializer->serialize($options));
if (!isset($this->numberFormatterCache[$key])) {
$this->numberFormatter = $this->numberFormatterFactory->create(
- ['locale' => $locale, 'style' => \NumberFormatter::CURRENCY]
+ ['locale' => $this->localeResolver->getLocale(), 'style' => \NumberFormatter::CURRENCY]
);
$this->setOptions($options);
@@ -477,13 +468,13 @@
{
if (array_key_exists(LocaleCurrency::CURRENCY_OPTION_SYMBOL, $options)) {
$this->numberFormatter->setSymbol(
- \NumberFormatter::CURRENCY_SYMBOL,
- $options[LocaleCurrency::CURRENCY_OPTION_SYMBOL]
+ \NumberFormatter::CURRENCY_SYMBOL, $options[LocaleCurrency::CURRENCY_OPTION_SYMBOL]
);
}
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']);
@@ -501,15 +492,13 @@
}
/**
- * Return the price format to be displayed to user
- *
* @return string
*/
public function getOutputFormat()
{
$formatted = $this->formatTxt(0);
- $number = $this->formatTxt(0, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
- return $formatted !== null ? str_replace($this->trimUnicodeDirectionMark($number), '%s', $formatted) : '';
+ $number = str_replace($this->getCurrencySymbol(), '', $formatted);
+ return str_replace($this->trimUnicodeDirectionMark($number), '%s', $formatted);
}
/**
@@ -545,8 +534,6 @@
}
/**
- * Retrieve base config currency data by config path.
- *
* @return array
*/
public function getConfigBaseCurrencies()
@@ -586,13 +573,13 @@
* 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);
+ $string = preg_replace('/^' . $match[1] . '/u', '', $string);
}
return $string;
}
-}
+}
\ No newline at end of file
-
thanks for your response @Msquare, but i am getting a strange error after i did everything and i ran this command composer install --ignore-platform-reqs Error: Could not apply patch! Skipping. The error was: Cannot apply patch patches/fix_price_zero.patch [Exception] Cannot apply patch Price hotfix (patches/fix_price_zero.patch)!– AdexNov 24, 2022 at 10:54
-
I added my patch file there please check it, May be you miss file path , Please add file path like above.– MsquareNov 24, 2022 at 12:21
-
where do i add this file you sent because i have creted two files fileA and fileB and run this command diff -u fileB fileA > fix_price_zero.patch.– AdexNov 24, 2022 at 12:42
-
-