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

8003: Using System Value for Base Currency Results in Config Error. #11809

Merged
merged 3 commits into from
Nov 21, 2017
Merged

8003: Using System Value for Base Currency Results in Config Error. #11809

merged 3 commits into from
Nov 21, 2017

Conversation

nmalevanec
Copy link
Contributor

Description

Fix for "Using System Value for Base Currency Results in Config Error".

Fixed Issues (if relevant)

  1. Using System Value for Base Currency Results in Config Error #8003: Using System Value for Base Currency Results in Config Error

Manual testing scenarios

  1. Log into Admin.
  2. Navigate to Stores > Settings > Configuration > General > Currency Setup.
  3. Select Use system value for Base Currency.
  4. Click Save Config if necessary and flush the cache.
  5. Navigate to Stores > Currency > Currency Rates.
  6. Try Importing Currency Rates via any of the three services.
  7. Check currency rates are successfully imported for Allowed Currencies.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • 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)

@nmalevanec nmalevanec changed the title Github-8003: Using System Value for Base Currency Results in Config Error. 8003: Using System Value for Base Currency Results in Config Error. Oct 27, 2017
@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Oct 30, 2017

CLA assistant check
All committers have signed the CLA.

@dmanners dmanners self-assigned this Nov 6, 2017
@dmanners dmanners added this to the November 2017 milestone Nov 6, 2017
@dmanners dmanners added Release Line: 2.2 2.2.x bug report Component: Config Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 6, 2017
Copy link
Contributor

@dmanners dmanners left a comment

Choose a reason for hiding this comment

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

I think that this plugin is not needed. From what I can see the methods getConfigDefaultCurrencies and getConfigBaseCurrencies should behave like getConfigAllowCurrencies. This method reads the data from the database but then also checks for the value set in the config. In this case it means that you will get all currencies set in the DB but also the default. Does that make sense?

@nmalevanec
Copy link
Contributor Author

nmalevanec commented Nov 6, 2017

@dmanners correct me, if I'm wrong, but in https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Directory/Model/Currency.php#L348 I see that allowed currencies reads only from DB, and later adds base currency(which indeed reads from db and system config) to allowed currencies array. So, if in admin I'll check 'Use system value' for Allowed Currencies, I'll get only base currency code.
I've created plugin, because both Model/Currency and ResourceModel/Currency marked with @api. And as far as I know, removing or marking as deprecated methods from such classes should be avoided(I mean ResourceModel/Currency::getConfigCurrencies()). And add system config, which reads config files, as dependency to ResourceModel, which interacts with DB looks like not the best idea for me.

@dmanners
Copy link
Contributor

dmanners commented Nov 9, 2017

@nmalevanec with regards to getConfigAllowCurrencies yes that does seem odd that it will add the base currency to the allowed currencies but I think that is another issue.

My concern with using the plugin is that this is a bug with the code code but fixing it with a plugin is not that obvious to all developers. If someone is interested in finding out how this code works it seems to be hidden.

I would actually love to see the following either been added to app/code/Magento/Directory/Model/Currency.php::getConfigDefaultCurrencies and app/code/Magento/Directory/Model/Currency.php::getConfigBaseCurrencies

  1. Call resource model that checks database values,
  2. Call new class that checks the config values,
  3. Combine the results of both for the system,

In this way we would cover the database and config values and since both getConfigDefaultCurrencies and getConfigBaseCurrencies are due to return an array it should work with 1 or more currencies.

How does that sound?

@nmalevanec
Copy link
Contributor Author

@dmanners Well, it's pretty doable. The only thing I'm concerning about(And this is actually one of the initial reasons to move logic into plugin) is Model/Currency already has coupling between objects more than allowed and suppressed warning about this. So adding to it another dependency like Magento\Config\App\Config\Type\System... Well, I'm not sure it's valid scenario. At least previously it wasn't.

@dmanners
Copy link
Contributor

dmanners commented Nov 9, 2017

@nmalevanec a very valid point.

We could always consider changing the app/code/Magento/Directory/Model/Currency/Import/AbstractImport.php::_getDefaultCurrencyCodes to use a new class that is specific for our purpose. Then we could deprecate the other methods and use the @see notation to highlight the new class and methods.

@nmalevanec
Copy link
Contributor Author

@dmanners Done.

public function __construct(
System $systemConfig,
StoreManagerInterface $storeManager,
ResourceConnection $resources
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we do not need this if it is never assigned to anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@@ -88,6 +95,7 @@ public function __construct(
\Magento\Framework\Locale\CurrencyInterface $localeCurrency,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
CurrencySystemConfig $currencyConfig = null,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this not be after the $data otherwise it will break backwards compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -378,7 +390,8 @@ public function getConfigDefaultCurrencies()
*/
public function getConfigBaseCurrencies()
{
$defaultCurrencies = $this->_getResource()->getConfigCurrencies($this, self::XML_PATH_CURRENCY_BASE);
$defaultCurrencies = $this->_getResource()->getConfigCurrencies($this, self::XML_PATH_CURRENCY_BASE) ?:
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens in the case that you have multiple stores, 1 with a database value and one without. In this case I guess we need to merge the values here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@okorshenko okorshenko merged commit 3e0c785 into magento:2.2-develop Nov 21, 2017
okorshenko pushed a commit that referenced this pull request Nov 21, 2017
@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Nov 21, 2017
@nmalevanec nmalevanec deleted the Github-8003 branch August 21, 2018 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report bugfix Component: Config Fixed in 2.2.x The issue has been fixed in 2.2 release line Progress: accept Release Line: 2.2 Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants