-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
This will shorten the list of allowed currencies #19946
Conversation
in Store->Configuration->General->Currency setup will be shown only those currencies selected in Installed currencies list (Configuration->Advanced->System)
Hi @melaxon. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
@@ -150,10 +157,20 @@ public function getOptionCurrencies() | |||
$currencies = (new CurrencyBundle())->get($this->localeResolver->getLocale())['Currencies'] ?: []; | |||
$options = []; | |||
$allowed = $this->_config->getAllowedCurrencies(); | |||
$selectedCurrencies = explode( | |||
',', $this->scopeConfig->getValue( | |||
'system/currency/installed', |
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.
I would put inside private const inside class
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.
Not needed until it is used only once.
$selectedCurrencies = explode( | ||
',', $this->scopeConfig->getValue( | ||
'system/currency/installed', | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE |
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.
Maybe it could be move to imports and here left in short version
foreach ($currencies as $code => $data) { | ||
if (!in_array($code, $allowed)) { | ||
continue; | ||
} | ||
if (!in_array($code, $selectedCurrencies)) { |
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.
I think condition could be moved to separate protected function, in order to encapsulate it
@@ -150,10 +157,20 @@ public function getOptionCurrencies() | |||
$currencies = (new CurrencyBundle())->get($this->localeResolver->getLocale())['Currencies'] ?: []; | |||
$options = []; | |||
$allowed = $this->_config->getAllowedCurrencies(); | |||
$selectedCurrencies = explode( |
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.
Maybe getting selecting countries could be done in separate protected method?
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.
This function will be called only once. Does it deserve it?
Hi @melaxon Thanks for the contribution! Please see the code review notes and consider covering the introduced improvement with a test. Also failed unit tests need to be fixed. |
@magento-engcom-team give me test instance |
Hi @melaxon. Thank you for your request. I'm working on Magento instance for you |
Hi @melaxon, here is your new Magento instance. |
It works in test instance. |
New commit will try to solve this: |
Trying to solve this: TypeError: Argument 1 passed to Magento\Framework\Locale\TranslatedLists::__construct() must implement interface Magento\Framework\App\Config\ScopeConfigInterface, instance of Mock_ConfigInterface_33ac175b given, called in /home/travis/build/magento/magento2/lib/internal/Magento/Framework/Locale/Test/Unit/TranslatedListsTest.php on line 40
fix test unit
done |
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.
Hi @melaxon please see the code review notes
/** | ||
* @var TranslatedLists | ||
*/ | ||
public $selectedCurrencies; |
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 change the access level of new properties to private
$this->mockConfig->expects($this->once()) | ||
->method('getAllowedCurrencies') | ||
->will($this->returnValue($allowedCurrencies)); | ||
|
||
$expectedResults = ['USD', 'EUR', 'GBP', 'UAH']; | ||
$this->listsModel->selectedCurrencies = $selectedCurrencies; |
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 mock the return of selected currencies from the scopeConfig
.
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.
ok. Along with the above comment
@@ -64,12 +73,15 @@ public function testGetOptionAllCurrencies() | |||
public function testGetOptionCurrencies() | |||
{ | |||
$allowedCurrencies = ['USD', 'EUR', 'GBP', 'UAH']; | |||
|
|||
$selectedCurrencies = ['USD', 'EUR']; |
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.
$selectedCurrencies = ['USD', 'EUR']; | |
$selectedCurrencies = ['USD', 'EUR']; |
Hi @melaxon, thank you for your contribution! |
I understood that the Framework is not the place where such modification can be applied because it is based on user input. New PR will be opened now |
This will shorten the list of allowed currencies showing only installed currencies
Description (*)
in Store->Configuration->General->Currency setup will be shown only those currencies selected in
Installed currencies list (Configuration->Advanced->System)
Fixed Issues (if relevant)
Manual testing scenarios (*)
Contribution checklist (*)