Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

t-heuser/magento2-33869

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

magento2-33869

This is an example for magento/magento2#33869.

Prerequisites to reproduce the bug

  1. At least Magento 2.4.0 installation
  2. A product with price > 0

Steps to reproduce the bug

  1. Install this module
    1. Execute composer config repositories.oneserv-magento2-33869 composer https://github.com/oneserv-heuser/magento2-33869
    2. Execute composer require oneserv/magento2-33869 @dev
  2. Execute bin/magento module:enable Oneserv_ExamplePaymentMethod
  3. Execute bin/magento setup:upgrade
  4. Create an empty cart via GraphQl
  5. Add your product to the cart
  6. Request all available payment methods

Expected result

The payment method oneserv_example_payment_method should not be available as the AvailabilityValidator always returns false.

The payment method was created exactly as stated in the docs for creating payment methods.

Actual result

The method is always available.

Cause of the problem

The cause of the problem is that Adapter::isAvailable() gets called from MethodList::getAvailableMethods(). The Adapter::isAvailable() method then tries to get the infoInstance as seen on line 290. If it's null it will not execute the availability validator from the validatorPool which would return false. The infoInstance is ALWAYS null in this case as the method instance gets freshly created from it's factory. The MethodList::getAvailableMethods() sets the infoInstance AFTER it calls the Adapter::isAvailable() method. So there is no way the validator gets called when using the new Payment Provider Gateway.

I guess this issue was never found as all of magentos payment methods are using the deprecated AbstractMethod class. I think this should be fixed asap as the method MethodList::getAvailableMethods() MUST work for all payment methods, especially if they're implemented the way they should be and not with deprecated classes.

Possible workarounds

I've implemented a workaround for this bug. It can be found in the Model of the payment method. There I overwrite the isAvailable() function. At the moment the fix is not executed. To see the fix in action just remove line 80 from the Model of the payment method and request all available payment methods from the cart again. The payment method oneserv_example_payment_method is not available anymore.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages