Skip to content
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

Closed
wants to merge 4 commits into from
Closed

This will shorten the list of allowed currencies #19946

wants to merge 4 commits into from

Conversation

melaxon
Copy link
Member

@melaxon melaxon commented Dec 22, 2018

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)

  1. magento/magento2#<issue_number>: Issue title
  2. ...

Manual testing scenarios (*)

  1. Currently if you select any currency in the list in Store->Configuration->General->Currency setup and this currency is not yet selected in Installed currency list (Configuration->Advanced->System) you will receive error message.
  2. After the modification is applied there will be only those currencies in the list (Store->Configuration->General->Currency setup) that can be selected without any error message

Contribution checklist (*)

  • [ x] Pull request has a meaningful description of its purpose
  • [ x] All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

in Store->Configuration->General->Currency setup will be shown only those currencies selected in 
Installed currencies list (Configuration->Advanced->System)
@magento-engcom-team
Copy link
Contributor

Hi @melaxon. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

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',

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

Copy link
Contributor

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

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)) {

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(

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?

Copy link
Member Author

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?

@sivaschenko
Copy link
Member

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.

@melaxon
Copy link
Member Author

melaxon commented Jan 11, 2019

@magento-engcom-team give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @melaxon. Thank you for your request. I'm working on Magento instance for you

@magento-engcom-team
Copy link
Contributor

Hi @melaxon, here is your new Magento instance.
Admin access: https://pr-19946.instances.magento-community.engineering/admin
Login: admin Password: 123123q

@melaxon
Copy link
Member Author

melaxon commented Jan 11, 2019

It works in test instance.
I allowed UDS and EUR in Configuration->Advanced->System
Then I see only allowed currencies in General->Currency Setup:
https://gyazo.com/c6a970fd6d34d1459ee7e9ed47828822

@melaxon
Copy link
Member Author

melaxon commented Jan 11, 2019

New commit will try 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

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
@melaxon
Copy link
Member Author

melaxon commented Jan 13, 2019

done

Copy link
Member

@sivaschenko sivaschenko left a 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;
Copy link
Member

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;
Copy link
Member

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.

Copy link
Member Author

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'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$selectedCurrencies = ['USD', 'EUR'];
$selectedCurrencies = ['USD', 'EUR'];

@melaxon melaxon closed this Jan 18, 2019
@melaxon melaxon deleted the patch-2 branch January 18, 2019 11:08
@ghost
Copy link

ghost commented Jan 18, 2019

Hi @melaxon, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@melaxon
Copy link
Member Author

melaxon commented Jan 18, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants