Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Update Format.php
Browse files Browse the repository at this point in the history
  • Loading branch information
phamcuongmp authored Nov 22, 2021
1 parent 3fed279 commit 8d7a960
Showing 1 changed file with 57 additions and 4 deletions.
61 changes: 57 additions & 4 deletions Plugin/Locale/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@

namespace Mageplaza\CurrencyFormatter\Plugin\Locale;

use Magento\Checkout\Model\Session;
use Magento\Directory\Model\Currency\DefaultLocator;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Locale\CurrencyInterface;
use Magento\Framework\Locale\Format as LocaleFormat;
use Magento\Framework\Locale\FormatInterface;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Store\Model\StoreManagerInterface;
use Mageplaza\CurrencyFormatter\Helper\Data as HelperData;
use Mageplaza\CurrencyFormatter\Model\Locale\DefaultFormat;
use Mageplaza\CurrencyFormatter\Plugin\AbstractFormat;

/**
Expand All @@ -32,6 +41,48 @@
*/
class Format extends AbstractFormat
{
/**
* @var Session
*/
protected $_checkoutSession;

/**
* AbstractFormat constructor.
*
* @param StoreManagerInterface $storeManager
* @param HelperData $helperData
* @param ResolverInterface $localeResolver
* @param CurrencyInterface $localeCurrency
* @param FormatInterface $localeFormat
* @param DefaultFormat $defaultFormat
* @param DefaultLocator $currencyLocator
* @param RequestInterface $request
* @param Session $checkoutSession
*/
public function __construct(
StoreManagerInterface $storeManager,
HelperData $helperData,
ResolverInterface $localeResolver,
CurrencyInterface $localeCurrency,
FormatInterface $localeFormat,
DefaultFormat $defaultFormat,
DefaultLocator $currencyLocator,
RequestInterface $request,
Session $checkoutSession
) {
$this->_checkoutSession = $checkoutSession;
parent::__construct(
$storeManager,
$helperData,
$localeResolver,
$localeCurrency,
$localeFormat,
$defaultFormat,
$currencyLocator,
$request
);
}

/**
* @param LocaleFormat $subject
* @param callable $proceed
Expand Down Expand Up @@ -69,12 +120,14 @@ public function afterGetPriceFormat(LocaleFormat $subject, $result)
if (!$this->_helperData->isEnabled()) {
return $result;
}
$baseCurrencyCode = $this->_storeManager->getStore()->getBaseCurrency()->getCode();
$baseCurrencyCode = $this->_checkoutSession->getQuote()->getBaseCurrencyCode();

$code = $this->getCurrencyCode();
if ($baseCurrencyCode && isset($result['currencyCode']) && $result['currencyCode'] === $baseCurrencyCode) {
$code = $baseCurrencyCode;
if ($baseCurrencyCode) {
if (isset($result['currencyCode']) && $result['currencyCode'] === $baseCurrencyCode) {
$code = $baseCurrencyCode;
}
}

$config = $this->getFormatByCurrency($code);
$localeShowSymbol = $this->_helperData->getLocaleShowSymbol(
$code,
Expand Down

0 comments on commit 8d7a960

Please sign in to comment.