Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
137eb53
Merge pull request #1 from lillik/1.0.0
lillik Feb 14, 2017
ffc75ea
Merge pull request #2 from lillik/1.0.0
lillik Feb 15, 2017
611cfb7
Merge pull request #4 from lillik/1.0.0
lillik Feb 20, 2017
ebf92c6
Merge pull request #5 from lillik/1.0.0
lillik Feb 20, 2017
38f90ea
Merge pull request #6 from lillik/1.0.0
lillik Feb 20, 2017
5a195cd
Merge pull request #7 from lillik/1.0.0
lillik Feb 20, 2017
16bcd9d
Merge pull request #8 from lillik/1.0.0
lillik Mar 27, 2017
1ab5515
fix bug when call format() with only mandatory argument (amount)
Jun 27, 2017
0afc129
Merge pull request #11 from polisys/fix-format-default-args
lillik Jun 27, 2017
3a410a8
Back-end price decimal
lillik Sep 24, 2017
a34c7c0
Merge pull request #13 from lillik/1.0.1
lillik Sep 24, 2017
28b2841
Update README.md
lillik Sep 26, 2017
eec5a1f
Update composer.json
lillik Sep 28, 2017
6fd07d1
Merge pull request #16 from lillik/1.0.1
lillik Sep 28, 2017
1e0c8e1
Fix issue #17
lillik Sep 28, 2017
8b42535
Update README.md
lillik Oct 6, 2017
def5621
add support php 7.1
novakivskiy Feb 18, 2018
8243545
Merge pull request #26 from novakivskiy/patch-1
lillik Feb 18, 2018
fb72881
#24 fix the price display the selected digits on product page
Mar 22, 2018
75b6575
show correct number of precision for order data
Mar 22, 2018
a632c63
force the price to not use 2 digitgs round
Mar 22, 2018
273c64c
update to support phpunit 6
Mar 22, 2018
b6fc6fd
Merge pull request #29 from cdiacon/calin/price-fixes
lillik Mar 22, 2018
37f101b
Update composer.json
lillik Mar 22, 2018
2eda0a2
Update module.xml
lillik Mar 22, 2018
4b285f0
Allow different settings per store view
Archipel Mar 29, 2018
f248835
Fix CS Issue
lillik May 27, 2018
60d9089
Add Precision option
lillik Jun 8, 2018
2afb335
Update composer.json
lillik Jun 19, 2018
122a455
Update module.xml
lillik Jun 19, 2018
7f092d0
Update README.md
lillik Jun 20, 2018
da36bab
Update README.md
lillik Jun 20, 2018
54cbe57
Merge tag '1.0.4'
Archipel Jul 20, 2018
e823191
Merge remote-tracking branch 'official/master'
Archipel Jul 20, 2018
e0d1197
Fixed bug due to wrong argument modification for ConvertAndFormat
Archipel Jul 20, 2018
3dc8028
Merge pull request #38 from Archipel/master
lillik Jul 27, 2018
9d0a343
Increase version
lillik Oct 23, 2018
bf30546
Update composer.json
lillik Oct 23, 2018
dd302c5
Fix Issue: Price change in admin when save product
lillik Oct 23, 2018
963eaab
Merge branch 'master' of github.com:lillik/magento2-price-decimal
lillik Oct 23, 2018
17adc5b
Fix Issue #46 (Magento 2.3 adminhtml inputs showing rounded value)
lillik Mar 20, 2020
e0a097b
Different decimal lenght for cart and checkout -- first version
Patriboom Mar 4, 2021
5384732
Includes Roy Nilsson (Aug 2021) and Patriboom modifications (mar 2021)
Patriboom Mar 5, 2021
1a40c47
Duplicates deleted
Patriboom Mar 9, 2021
a222321
More details about how to install PriceDecimal manually
Patriboom Mar 9, 2021
f0719f1
According to standard
Patriboom Mar 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.~
error_log
.gitignore
.htaccess~
30 changes: 30 additions & 0 deletions Block/System/Config/Form/Field/Precision.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* @category Evozon
* @package Magento_Evozon
* @copyright Copyright (c) 2018 Evozon (http://www.evozon.com)
* @author Lilian Codreanu <[email protected]>
*/

namespace Lillik\PriceDecimal\Block\System\Config\Form\Field;


class Precision implements \Magento\Framework\Option\ArrayInterface
{

/**
* Return array of options as value-label pairs
*
* @return array Format: array(array('value' => '<value>', 'label' => '<label>'), ...)
*/
public function toOptionArray()
{
return [
['value' => 0, 'label' => __('0')],
['value' => 1, 'label' => __('1')],
['value' => 2, 'label' => __('2')],
['value' => 3, 'label' => __('3')],
['value' => 4, 'label' => __('4')],
];
}
}
Empty file modified LICENSE.txt
100644 → 100755
Empty file.
61 changes: 44 additions & 17 deletions Model/Config.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,46 @@
/**
*
* @package Lillik\PriceDecimal\Model
*
* @author Lilian Codreanu <[email protected]>
* includes Roy Nilsson's modifications ( Aug 2020 )
* includes Patriboom's modifications ( Mar 2021 )
*/

namespace Lillik\PriceDecimal\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\RequestInterface;

class Config implements ConfigInterface
{

const XML_PATH_PRICE_PRECISION
= 'catalog_price_decimal/general/price_precision';
const XML_PATH_GENERAL_ENABLE = 'catalog_price_decimal/general/enable';
const XML_PATH_CAN_SHOW_PRICE_DECIMAL = 'catalog_price_decimal/general/can_show_decimal';
const XML_PATH_DISABLE_FOR_ACTIONS = 'catalog_price_decimal/general/disable_for_actions';

const XML_PATH_CAN_SHOW_PRICE_DECIMAL
= 'catalog_price_decimal/general/can_show_decimal';
const XML_PATH_PRICE_PRECISION = 'catalog_price_decimal/general/price_precision';
const XML_PATH_PRICE_PRECISIONCART = 'catalog_price_decimal/general/price_precision';
const XML_PATH_PRICE_PRECISIONCHECKOUT = 'catalog_price_decimal/general/price_precision';

const XML_PATH_GENERAL_ENABLE
= 'catalog_price_decimal/general/enable';

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $scopeConfig;

/**
* @var \Magento\Framework\App\RequestInterface
*/
private $request;

/**
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
ScopeConfigInterface $scopeConfig
) {

public function __construct( ScopeConfigInterface $scopeConfig, RequestInterface $request )
{
$this->scopeConfig = $scopeConfig;
}
$this->request = $request;
}

/**
* @return \Magento\Framework\App\Config\ScopeConfigInterface
Expand All @@ -48,28 +54,30 @@ public function getScopeConfig()
/**
* Return Config Value by XML Config Path
* @param $path
* @param $scopeType
*
* @return mixed
*/
public function getValueByPath($path)
public function getValueByPath($path, $scopeType = 'website')
{
return $this->getScopeConfig()->getValue($path);
return $this->getScopeConfig()->getValue($path, $scopeType);
}

/**
* @return mixed
*/
public function isEnable()
{
return $this->getValueByPath(self::XML_PATH_GENERAL_ENABLE);
//return $this->getValueByPath(self::XML_PATH_GENERAL_ENABLE, 'website');
return $this->getValueByPath(self::XML_PATH_GENERAL_ENABLE, 'website') && !$this->isDisabledForAction();
}

/**
* @return mixed
*/
public function canShowPriceDecimal()
{
return $this->getValueByPath(self::XML_PATH_CAN_SHOW_PRICE_DECIMAL);
return $this->getValueByPath(self::XML_PATH_CAN_SHOW_PRICE_DECIMAL, 'website');
}

/**
Expand All @@ -79,6 +87,25 @@ public function canShowPriceDecimal()
*/
public function getPricePrecision()
{
return $this->getValueByPath(self::XML_PATH_PRICE_PRECISION);
return $this->getValueByPath(self::XML_PATH_PRICE_PRECISION, 'website');
}
public function getPricePrecisionCart()
{
return $this->getValueByPath(self::XML_PATH_PRICE_PRECISIONCART, 'website');
}
public function getPricePrecisionCheckout()
{
return $this->getValueByPath(self::XML_PATH_PRICE_PRECISIONCHECKOUT, 'website');
}

private function isDisabledForAction()
{
$currentAction = $this->request->getModuleName() . '_' . $this->request->getControllerName() . '_' . $this->request->getActionName();
foreach (explode(',', $this->getValueByPath(self::XML_PATH_DISABLE_FOR_ACTIONS, 'website')) as $action) {
if (trim($action) == $currentAction) {
return true;
}
}
return false;
}
}
Empty file modified Model/ConfigInterface.php
100644 → 100755
Empty file.
43 changes: 43 additions & 0 deletions Model/Currency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
*
* @package package Lillik\PriceDecimal
*
* @author Lilian Codreanu <[email protected]>
*/

namespace Lillik\PriceDecimal\Model;

use Magento\Framework\CurrencyInterface;
use Magento\Framework\Currency as MagentoCurrency;
use Lillik\PriceDecimal\Model\ConfigInterface;

/** @method getPricePrecision */
class Currency extends MagentoCurrency implements CurrencyInterface
{

use PricePrecisionConfigTrait;

/**
* @var \Lillik\PriceDecimal\Model\ConfigInterface
*/
public $moduleConfig;

/**
* Currency constructor.
*
* @param \Magento\Framework\App\CacheInterface $appCache
* @param \Lillik\PriceDecimal\Model\ConfigInterface $moduleConfig
* @param null $options
* @param null $locale
*/
public function __construct(
\Magento\Framework\App\CacheInterface $appCache,
ConfigInterface $moduleConfig,
$options = null,
$locale = null
) {
$this->moduleConfig = $moduleConfig;
parent::__construct($appCache, $options, $locale);
}
}
31 changes: 31 additions & 0 deletions Model/Plugin/Currency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
*
* @package package Lillik\PriceDecimal\Model\Plugin\Local
*
* @author Lilian Codreanu <[email protected]>
*/

namespace Lillik\PriceDecimal\Model\Plugin;

class Currency extends PriceFormatPluginAbstract
{

/**
* {@inheritdoc}
*
* @param \Magento\Framework\CurrencyInterface $subject
* @param array ...$args
*
* @return array
*/
public function beforeToCurrency(
\Lillik\PriceDecimal\Model\Currency $subject,
...$arguments
) {
if ($this->getConfig()->isEnable()) {
$arguments[1]['precision'] = $subject->getPricePrecision();
}
return $arguments;
}
}
6 changes: 4 additions & 2 deletions Model/Plugin/Local/Format.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public function afterGetPriceFormat($subject, $result)
$precision = $this->getPricePrecision();

if ($this->getConfig()->isEnable()) {
$result['precision'] = $precision;
$result['requiredPrecision'] = $precision;
$result['precision'] = $precision;
$result['precisionCart'] = $this->getConfig()->getPricePrecisionCart();
$result['precisionCheckout'] = $this->getConfig()->getPricePrecisionCheckout();
$result['requiredPrecision'] = $precision;
}

return $result;
Expand Down
30 changes: 30 additions & 0 deletions Model/Plugin/OrderPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
*
* @package Lillik\PriceDecimal\Model\Plugin
*
* @author Lilian Codreanu <[email protected]>
*/

namespace Lillik\PriceDecimal\Model\Plugin;

class OrderPlugin extends PriceFormatPluginAbstract
{
/**
* @param \Magento\Sales\Model\Order $subject
* @param array ...$args
* @return array
*/
public function beforeFormatPricePrecision(
\Magento\Sales\Model\Order $subject,
...$args
) {
//is enabled
if ($this->getConfig()->isEnable()) {
//change the precision
$args[1] = $this->getPricePrecision();
}

return $args;
}
}
67 changes: 64 additions & 3 deletions Model/Plugin/PriceCurrency.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,77 @@ class PriceCurrency extends PriceFormatPluginAbstract
/**
* {@inheritdoc}
*/
public function aroundFormat(
public function beforeFormat(
\Magento\Directory\Model\PriceCurrency $subject,
...$args
) {
if ($this->getConfig()->isEnable()) {
// add the optional arg
if (!isset($args[1])) {
$args[1] = true;
}
// Precision argument
$args[2] = $this->getPricePrecision();
}

return $args;
}

/**
* @param \Magento\Directory\Model\PriceCurrency $subject
* @param callable $proceed
* @param $price
* @param array ...$args
* @return float
*/
public function aroundRound(
\Magento\Directory\Model\PriceCurrency $subject,
callable $proceed,
$price,
...$args
) {
if ($this->getConfig()->isEnable()) {
return round($price, $this->getPricePrecision());

} else {
return $proceed($price);
}
}

/**
* @param \Magento\Directory\Model\PriceCurrency $subject
* @param array ...$args
* @return array
*/
public function beforeConvertAndFormat(
\Magento\Directory\Model\PriceCurrency $subject,
...$args
) {
if ($this->getConfig()->isEnable()) {
// add the optional args
$args[1] = isset($args[1])? $args[1] : null;
$args[2] = intval($this->getPricePrecision());
}

return $args;
}

/**
* @param \Magento\Directory\Model\PriceCurrency $subject
* @param array ...$args
* @return array
*/
public function beforeConvertAndRound(
\Magento\Directory\Model\PriceCurrency $subject,
...$args
) {
if ($this->getConfig()->isEnable()) {
$args[2] = $this->getPricePrecision(); // Precision argument
//add optional args
$args[1] = isset($args[1])? $args[1] : null;
$args[2] = isset($args[2])? $args[2] : null;
$args[3] = $this->getPricePrecision();
}

return $proceed(...$args);
return $args;
}
}
Loading