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

Commit

Permalink
clean code update i18n & update composer version
Browse files Browse the repository at this point in the history
  • Loading branch information
phamcuongmp committed Nov 22, 2021
1 parent 43af5ce commit ab2f233
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 53 deletions.
63 changes: 11 additions & 52 deletions Plugin/Locale/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,9 @@

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 @@ -41,40 +32,6 @@
*/
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 @@ -112,17 +69,19 @@ public function afterGetPriceFormat(LocaleFormat $subject, $result)
if (!$this->_helperData->isEnabled()) {
return $result;
}
$baseCurrencyCode = $this->_checkoutSession->getQuote()->getBaseCurrencyCode();

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

$config = $this->getFormatByCurrency($code);
$result['pattern'] = $this->_helperData->getLocaleShowSymbol($code, $config['show_symbol'],
$config['symbol']);
$localeShowSymbol = $this->_helperData->getLocaleShowSymbol(
$code,
$config['show_symbol'],
$config['symbol']
);
$result['pattern'] = $localeShowSymbol;
$result['precision'] = $config['decimal_number'];
$result['requiredPrecision'] = $config['decimal_number'];
$result['decimalSymbol'] = $config['decimal_separator'];
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mageplaza/module-core": "^1.4.4"
},
"type": "magento2-module",
"version": "1.0.2",
"version": "1.0.3",
"license": "proprietary",
"authors": [
{
Expand Down

0 comments on commit ab2f233

Please sign in to comment.