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

Avoid exception when config.xml nodes exist for not-installed payment methods #27940

Conversation

fredden
Copy link
Member

@fredden fredden commented Apr 22, 2020

Description

When a payment configuration node exists in XML but there is no <model> defined, getList() will throw an UnexpectedValueException. One use case for creating such a set-up is a module that provides default configuration overrides for payment methods which are not installed on the current website. For example:

<config>
  <default>
    <payment>
      <checkmo>
        <active>0</active>
      </checkmo>
      <not_installed_here>
        <debug>0</debug>
        <environment>production</environment>
      </not_installed_here>
    </payment>
  </default>
</config>

In this case, the payment method not_installed_here does not have a <model> node defined, as the payment method module is not installed on the website.

Related Pull Requests

None known

Fixed Issues

None known

Manual testing scenarios (*)

  1. Add supplied XML or similar to a local module's config.xml
  2. Browse to checkout with an item in basket
  3. Observe (lack of) exception thrown during checkout page load

Questions or comments

I have not yet written/changed any unit/functional tests for this change. I suspect some existing tests may fail which I will review at a later date.

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 are green)

Resolved issues:

  1. resolves [Issue] Avoid exception when config.xml nodes exist for not-installed payment methods #29555: Avoid exception when config.xml nodes exist for not-installed payment methods

When a payment configuration node exists in XML but there is no <model>
defined, getList() will throw an UnexpectedValueException. One use case for
creating such a set-up is a module that provides default configuration
overrides for payment methods which are not installed on the current website.
For example:

<config>
  <default>
    <payment>
      <checkmo>
        <active>0</active>
      </checkmo>
      <not_installed_here>
        <debug>0</debug>
        <environment>production</environment>
      </not_installed_here>
    </payment>
  </default>
</config>

In this case, the payment method 'not_installed_here' does not have a <model>
node defined, as the payment method module is not installed on the website.
@m2-assistant
Copy link

m2-assistant bot commented Apr 22, 2020

Hi @fredden. 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 give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@ghost
Copy link

ghost commented Jul 14, 2020

With this code change applied, there are issues reloading checkout payments. An example from internal testing:

Expected Result:

  • Zero Subtotal Checkout is enabled
  • Apply reward points so that order grand total reaches 0
  • The free checkout method should be displayed on the frontend
  • The existing payment methods should be removed from the frontend

Actual Result:

  • Zero Subtotal Checkout is enabled
  • Apply reward points so that order grand total reaches 0
  • The free checkout method is not displayed at all
  • The existing payment methods remain
  • An error is displayed on the page stating the current payment method is no longer available

This is perhaps due to the second parameter of the getStoreMethods function being null instead of a Quote model, but cannot be sure.

@sidolov
Copy link
Contributor

sidolov commented Aug 14, 2020

@magento create issue

@sidolov sidolov added Priority: P3 May be fixed according to the position in the backlog. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Aug 14, 2020
Copy link
Contributor

@sidolov sidolov left a comment

Choose a reason for hiding this comment

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

@fredden please, take a look at comment, looks like provided implementation broke the functionality.

@ghost ghost moved this from Pending Review to Changes Requested in Pull Requests Dashboard Aug 27, 2020
@ghost ghost assigned sidolov Aug 27, 2020
@engcom-Charlie engcom-Charlie self-assigned this Aug 31, 2020
@engcom-Charlie
Copy link
Contributor

Hi @fredden, can you please look through at comment #27940 (comment) ?

@gabrieldagama
Copy link
Contributor

The risk was set tomedium due to: the suggested changes shouldn't affect other areas but it affects a critical part of e-commerce.

Now instead of using the helper, we are only catching the exception thrown. See
previous commit for full description.
@engcom-Charlie
Copy link
Contributor

@fredden can you please fix static tests and cover changes by autotest?
Thank you.

@engcom-Charlie
Copy link
Contributor

@fredden can you please cover changes by autotest? Otherwise, we can't proceed with your PR.
Thank you.

@fredden
Copy link
Member Author

fredden commented Sep 26, 2020

@engcom-Charlie, how would you suggest writing a test for this? I'm considering adding some XML nodes to app/code/Magento/Payment/etc/config.xml, but don't really want these to end up in a production release. Is there a way to inject/set configuration specifically for the test-suite?

@engcom-Charlie
Copy link
Contributor

@fredden, you can do this, for example like here dev/tests/integration/_files/Magento/TestModuleFakePaymentMethod/etc/config.xml.
Thank you.

@engcom-Charlie
Copy link
Contributor

@sidolov I checked test \Magento\Checkout\Model\ShippingInformationManagementTest::testQuoteApiWithOnlyVirtualProducts
without changes from this PR in Magento/Payment/Model/PaymentMethodList it falls with exception
UnexpectedValueException : Payment model name is not provided in config!

With changes from this PR test passed.
What do you think it will be enough for test coverage?

@sidolov
Copy link
Contributor

sidolov commented Sep 29, 2020

@engcom-Charlie sounds reasonable, I see additional config was added for the exceptional case, so, it's enough to proceed with PR. Thank you!

@ghost ghost moved this from Changes Requested to Ready for Testing in Pull Requests Dashboard Sep 29, 2020
@magento-engcom-team
Copy link
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-8283 has been created to process this Pull Request
✳️ @sidolov, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@engcom-Delta engcom-Delta self-assigned this Sep 30, 2020
@engcom-Delta engcom-Delta moved this from Ready for Testing to Testing in Progress in Pull Requests Dashboard Sep 30, 2020
@engcom-Delta
Copy link
Contributor

✔️ QA passed
Result according Manual testing scenarios:
❌ Before:
Exception error Payment model name is not provided in config! {"exception":"[object] (UnexpectedValueException(code: 0): Payment model name is not provided in config! in logs
image

✔️ After:
No exception errors
image

Result according comment with coupon code:
image

@engcom-Delta engcom-Delta added the QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope label Oct 1, 2020
@engcom-Delta
Copy link
Contributor

Note: Automation tests are passed

@engcom-Delta engcom-Delta moved this from Testing in Progress to Merge in Progress in Pull Requests Dashboard Oct 2, 2020
@sidolov sidolov added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Oct 2, 2020
magento-engcom-team pushed a commit that referenced this pull request Oct 6, 2020
@magento-engcom-team magento-engcom-team merged commit 2e0dde8 into magento:2.4-develop Oct 6, 2020
@m2-assistant
Copy link

m2-assistant bot commented Oct 6, 2020

Hi @fredden, 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.

@ghost ghost moved this from Merge in Progress to Recently Merged in Pull Requests Dashboard Oct 6, 2020
@fredden fredden deleted the payment-list/model-not-provided-in-config branch October 6, 2020 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: Payment Partner: Fisheye partners-contribution Pull Request is created by Magento Partner Priority: P3 May be fixed according to the position in the backlog. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Risk: medium Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
Pull Requests Dashboard
  
Recently Merged
Development

Successfully merging this pull request may close these issues.

[Issue] Avoid exception when config.xml nodes exist for not-installed payment methods
6 participants