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

Commit

Permalink
Merge pull request #33 from mageplaza/2.3-develop
Browse files Browse the repository at this point in the history
merge branch 2.3 develop into 2.3
  • Loading branch information
namnh112 authored Feb 25, 2022
2 parents 1d6f221 + 7596e78 commit 9ec55e6
Show file tree
Hide file tree
Showing 5 changed files with 614 additions and 1 deletion.
92 changes: 92 additions & 0 deletions Plugin/Directory/PriceCurrency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_CurrencyFormatter
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\CurrencyFormatter\Plugin\Directory;

use Magento\Directory\Model\PriceCurrency as DirectoryPriceCurrency;
use Magento\Framework\Exception\NoSuchEntityException;
use Mageplaza\CurrencyFormatter\Plugin\AbstractFormat;
use Zend_Currency_Exception;

/**
* Class PriceCurrency
* @package Mageplaza\CurrencyFormatter\Plugin\Directory
*/
class PriceCurrency extends AbstractFormat
{
/**
* @return int
* @throws NoSuchEntityException
*/
public function getPrecision(): int
{
$baseCurrencyCode = $this->_storeManager->getStore()->getBaseCurrency()->getCode();
$code = $this->getCurrencyCode();
if ($baseCurrencyCode && isset($result['currencyCode']) && $result['currencyCode'] === $baseCurrencyCode) {
$code = $baseCurrencyCode;
}

$config = $this->getFormatByCurrency($code);

return (int) $config['decimal_number'];
}

/**
* @param DirectoryPriceCurrency $subject
* @param callable $proceed
* @param float $price
*
* @return float
* @throws NoSuchEntityException
* @throws Zend_Currency_Exception
*/
public function aroundRound(DirectoryPriceCurrency $subject, callable $proceed, float $price): float
{
if (!$this->_helperData->isEnabled()) {
return $proceed($price);
}

return round($price, $this->getPrecision());
}

/**
* @param DirectoryPriceCurrency $subject
* @param callable $proceed
* @param float $price
* @param int $precision
*
* @return float
* @throws NoSuchEntityException
* @throws Zend_Currency_Exception
*/
public function aroundRoundPrice(
DirectoryPriceCurrency $subject,
callable $proceed,
float $price,
int $precision
): float {
if (!$this->_helperData->isEnabled()) {
return $proceed($price, $precision);
}

return round($price, $this->getPrecision());
}
}
Loading

0 comments on commit 9ec55e6

Please sign in to comment.