-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different decimal lenght for cart and checkout -- first version #57
Open
Patriboom
wants to merge
7
commits into
lillik:master
Choose a base branch
from
Patriboom:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e0a097b
Different decimal lenght for cart and checkout -- first version
Patriboom 5384732
Includes Roy Nilsson (Aug 2021) and Patriboom modifications (mar 2021)
Patriboom 1a40c47
Duplicates deleted
Patriboom a222321
More details about how to install PriceDecimal manually
Patriboom f0719f1
According to standard
Patriboom a6943b2
Inclusions Quitibuis
Patriboom 7a4a41c
Fixed bug about type of argument
Patriboom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.~ | ||
error_log | ||
.gitignore | ||
.htaccess~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,40 +2,50 @@ | |
/** | ||
* | ||
* @package Lillik\PriceDecimal\Model | ||
* | ||
* @author Lilian Codreanu <[email protected]> | ||
* includes Roy Nilsson's modifications ( Aug 2020 ) | ||
* Includes: differentCurrencies from quintenbuis (2021-03-14) | ||
* Includes: diffenteDecimales from Patriboom (2021-03-01) | ||
*/ | ||
|
||
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_DIFFERENT_CURRENCY = 'catalog_price_decimal/general/different'; | ||
const XML_PATH_PRICE_PRECISION_CURRENCY= 'catalog_price_decimal/general/price_precision_currency'; | ||
|
||
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 | ||
|
@@ -62,7 +72,8 @@ public function getValueByPath($path, $scopeType = 'website') | |
*/ | ||
public function isEnable() | ||
{ | ||
return $this->getValueByPath(self::XML_PATH_GENERAL_ENABLE, 'website'); | ||
//return $this->getValueByPath(self::XML_PATH_GENERAL_ENABLE, 'website'); | ||
return $this->getValueByPath(self::XML_PATH_GENERAL_ENABLE, 'website') && !$this->isDisabledForAction(); | ||
} | ||
|
||
/** | ||
|
@@ -76,10 +87,52 @@ public function canShowPriceDecimal() | |
/** | ||
* Return Price precision from store config | ||
* | ||
* @return mixed | ||
* @return int | ||
*/ | ||
public function getPricePrecision(): int | ||
{ | ||
return (int) $this->getValueByPath(self::XML_PATH_PRICE_PRECISION, 'website'); | ||
} | ||
|
||
/** | ||
* Returns if the currency decimal is different | ||
* | ||
* @return bool | ||
*/ | ||
public function getDifferentForCurrency(): bool | ||
{ | ||
return (bool) $this->getValueByPath(self::XML_PATH_DIFFERENT_CURRENCY, 'website'); | ||
} | ||
|
||
/** | ||
* Return Price precision for currency from store config | ||
* | ||
* @return int | ||
*/ | ||
public function getPricePrecision() | ||
public function getPricePrecisionCurrency(): int | ||
{ | ||
return $this->getValueByPath(self::XML_PATH_PRICE_PRECISION, 'website'); | ||
return (int) $this->getValueByPath(self::XML_PATH_PRICE_PRECISION_CURRENCY, '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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
* @package package Lillik\PriceDecimal | ||
* | ||
* @author Lilian Codreanu <[email protected]> | ||
* Includes: differentCurrencies from quintenbuis (2021-03-14) | ||
*/ | ||
|
||
namespace Lillik\PriceDecimal\Model; | ||
|
@@ -12,7 +13,10 @@ | |
use Magento\Framework\Currency as MagentoCurrency; | ||
use Lillik\PriceDecimal\Model\ConfigInterface; | ||
|
||
/** @method getPricePrecision */ | ||
/** | ||
* @method getPricePrecision | ||
* @method getPricePrecisionCurrency | ||
*/ | ||
class Currency extends MagentoCurrency implements CurrencyInterface | ||
{ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
* @package package Lillik\PriceDecimal\Model\Plugin\Local | ||
* | ||
* @author Lilian Codreanu <[email protected]> | ||
* Includes: differentCurrencies from quintenbuis (2021-03-14) | ||
*/ | ||
|
||
namespace Lillik\PriceDecimal\Model\Plugin; | ||
|
@@ -24,7 +25,7 @@ public function beforeToCurrency( | |
...$arguments | ||
) { | ||
if ($this->getConfig()->isEnable()) { | ||
$arguments[1]['precision'] = $subject->getPricePrecision(); | ||
$arguments[1]['precision'] = $subject->getPricePrecisionCurrency(); | ||
} | ||
return $arguments; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
* @package package Lillik\PriceDecimal\Model\Plugin\Local | ||
* | ||
* @author Lilian Codreanu <[email protected]> | ||
*/ | ||
* Includes: differentCurrencies from quintenbuis (2021-03-14) | ||
*/ | ||
|
||
namespace Lillik\PriceDecimal\Model\Plugin\Local; | ||
|
||
|
@@ -13,23 +14,24 @@ | |
class Format extends PriceFormatPluginAbstract | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param $subject | ||
* @param $result | ||
* | ||
* @return mixed | ||
*/ | ||
public function afterGetPriceFormat($subject, $result) | ||
{ | ||
$precision = $this->getPricePrecision(); | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param $subject | ||
* @param $result | ||
* | ||
* @return mixed | ||
*/ | ||
public function afterGetPriceFormat($subject, $result) | ||
{ | ||
$precision = $this->getPricePrecisionCurrency(); | ||
if ($this->getConfig()->isEnable()) { | ||
$result['precision'] = $precision; | ||
$result['precisionCart'] = $this->getConfig()->getPricePrecisionCart(); | ||
$result['precisionCheckout'] = $this->getConfig()->getPricePrecisionCheckout(); | ||
$result['requiredPrecision'] = $precision; | ||
} | ||
|
||
if ($this->getConfig()->isEnable()) { | ||
$result['precision'] = $precision; | ||
$result['requiredPrecision'] = $precision; | ||
} | ||
|
||
return $result; | ||
} | ||
return $result; | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,31 +4,99 @@ | |
* @package Lillik\PriceDecimal | ||
* | ||
* @author Lilian Codreanu <[email protected]> | ||
* Includes: differentCurrencies from quintenbuis (2021-03-14) | ||
* Includes: diffenteDecimales from Patriboom (2021-03-01) | ||
*/ | ||
|
||
namespace Lillik\PriceDecimal\Model; | ||
|
||
trait PricePrecisionConfigTrait | ||
{ | ||
|
||
/** | ||
* @$Val used to keep track of the way to count decimals | ||
*/ | ||
public $Val; | ||
|
||
/** | ||
* @$requestUri used to know which page is calling function so, which value return to | ||
*/ | ||
public $requestUri; | ||
|
||
/** | ||
|
||
* @return \Lillik\PriceDecimal\Model\ConfigInterface | ||
*/ | ||
public function getConfig() | ||
{ | ||
return $this->moduleConfig; | ||
} | ||
|
||
/** | ||
* Set the PAGE INFO string | ||
* | ||
* @param string|null $pathInfo | ||
* @return $this | ||
*/ | ||
public function getPageInfo($pathInfo = null) | ||
{ | ||
if ($pathInfo === null) { | ||
$requestUri = $this->getRequestUri(); | ||
if ($requestUri == '/') { | ||
return $this; | ||
} | ||
|
||
// Remove the query string from REQUEST_URI | ||
$pos = strpos($requestUri, '?'); | ||
if ($pos) { | ||
$requestUri = substr($requestUri, 0, $pos); | ||
} | ||
|
||
$baseUrl = $this->getBaseUrl(); | ||
$pathInfo = substr($requestUri, strlen($baseUrl)); | ||
if (!empty($baseUrl) && '/' === $pathInfo) { | ||
$pathInfo = ''; | ||
} elseif ($baseUrl === null) { | ||
$pathInfo = $requestUri; | ||
} | ||
$pathInfo = ($pos !== false) ? substr($requestUri, $pos) : ''; | ||
$this->requestString = $pathInfo; | ||
} | ||
$this->pathInfo = ($pathInfo == '') ? array() : explode('/', $pathInfo); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return int|mixed | ||
*/ | ||
public function getPricePrecision() | ||
{ | ||
if ($this->getConfig()->canShowPriceDecimal()) { | ||
//return $context->getLayout(); | ||
$Val = $this->getConfig()->getPricePrecision(); | ||
$Val = (in_array('checkout', getPageInfo())) ? $this->getConfig()->getPricePrecisionCheckout() : $Val; | ||
$Val = (in_array('cart', getPageInfo())) ? $this->getConfig()->getPricePrecisionCart() : $Val; | ||
// $Val = (strstr($_SERVER['PHP_SELF'], 'checkout') > -1 ) ? $this->getConfig()->getPricePrecisionCheckout() : $Val; | ||
// $Val = (strstr($_SERVER['PHP_SELF'], 'cart') > -1 ) ? $this->getConfig()->getPricePrecisionCart() : $Val; | ||
return $Val; | ||
} | ||
return 0; | ||
} | ||
|
||
/** | ||
* @return int|mixed | ||
*/ | ||
public function getPricePrecisionCurrency() | ||
{ | ||
if (!$this->getConfig()->canShowPriceDecimal()) { | ||
return 0; | ||
} | ||
|
||
if (!$this->getConfig()->getDifferentForCurrency()) { | ||
return $this->getConfig()->getPricePrecision(); | ||
} | ||
|
||
return 0; | ||
return $this->getConfig()->getPricePrecisionCurrency(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, declare the local variables according to PSR.