Open t-heuser opened 3 years ago
Hi @oneserv-heuser. Thank you for your report. To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, please, review the Magento Contributor Assistant documentation.
Please, add a comment to assign the issue: @magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.
:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
I can confirm this issue exists on a vanilla magento instance.
For everyone interested here is a patch to fix this issue temporary:
From bbfb31408bdb4a5551f54e72975233e392b94eaf Mon Sep 17 00:00:00 2001
From: Timon Heuser <heuser@bueromoebel-experte.de>
Date: Fri, 20 Aug 2021 14:13:53 +0200
Subject: [PATCH] fix
---
.../module-payment/Gateway/Data/Quote/QuoteAdapter.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/vendor/magento/module-payment/Gateway/Data/Quote/QuoteAdapter.php b/vendor/magento/module-payment/Gateway/Data/Quote/QuoteAdapter.php
index 645c347..f130572 100644
--- a/vendor/magento/module-payment/Gateway/Data/Quote/QuoteAdapter.php
+++ b/vendor/magento/module-payment/Gateway/Data/Quote/QuoteAdapter.php
@@ -122,11 +122,11 @@ class QuoteAdapter implements OrderAdapterInterface
/**
* Returns order grand total amount
*
- * @return null
+ * @return float
*/
public function getGrandTotalAmount()
{
- return null;
+ return $this->quote->getBaseGrandTotal();
}
/**
--
2.27.0
Just copy it to a .patch file and follow instructions here: https://github.com/cweagans/composer-patches
Hi @engcom-Delta. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hi @oneserv-heuser,
Thanks for logging an issue. Kindly see if you can provide list of functional scenarios. Hence, added the label 'Needs Update'
Thanks
@engcom-Delta Why should I provide functional scenarios? There is a obvious bug in the code base which also violates coding standards as in the interface OrderAdapterInterface (which the QuoteAdapter implements) the function getGrandTotalAmount() has the return type float. But in the QuoteAdapter it's implemented (hardcoded!) to return null which makes no sense at all as the required data can be obtained from the quote.
Anyway, my use case is to use the Gateway Implementation for Payment methods which magento provides and requires me to use. Specifically I need it for the availability Validator as configured as decribed here.
Here is a code example:
<?php
declare(strict_types=1);
namespace Oneserv\B2BInvoice\Gateway\Validator;
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
use Magento\Payment\Gateway\Validator\AbstractValidator;
/**
* Class AvailabilityValidator
*/
class AvailabilityValidator extends AbstractValidator
{
/**
* @param array{payment: PaymentDataObjectInterface} $validationSubject
* @return ResultInterface
*/
public function validate(array $validationSubject): ResultInterface
{
$order = $validationSubject['payment']->getOrder();
$grandTotal = (float)$order->getGrandTotalAmount();
if ($grandTotal === (float)0) {
return $this->createResult(false, [__('The order total amount must be greater than 0.')]);
}
return $this->createResult(true);
}
}
In my code example you can see the use case. If the function getGrandTotalAmount() always returns null (which it does, as it's hardcoded to do that) my payment method will never be available.
@engcom-Delta I've provided the requested information, can you please change the labels/ confirm that the issue exists?
Hi @engcom-Lima. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hi @oneserv-heuser,
I have gone through your comments and agrees that hardcoded null should not be there in getGrandTotalAmount() of class QuoteAdapter
. Also found that in the interface OrderAdapterInterface
which is implemented by QuoteAdapter
class, there is a function getGrandTotalAmount() which has the return type float and is inaccurate in that respect also. So confirming this issue.
Thanks
:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-1290 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Lima. Thank you for verifying the issue.
Issue Available: @engcom-Lima, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
Hi @oneserv-heuser,
Before we move ahead with this issue confirmation, there is 1 more thing which we need to clarify:
As per your use case, you are calling $order->getGrandTotalAmount()
but you are not calling getGrandTotalAmount
method from QuoteAdapter
class. We need to understand the impact of it that is why we need some more information. So please clarify how QuoteAdapter class is creating issue as per your use case ?
Thanks
@engcom-Lima Lets dive deeper into the code:
The object passed to the validate function of a Payment Gateway Validator Instance is an array: https://github.com/magento/magento2/blob/192b28038dac2e993c65b49fb8b5af10cb520945/app/code/Magento/Payment/Gateway/Validator/ValidatorInterface.php#L22
This array contains an an object of the type PaymentDataObjectInterface: https://github.com/magento/magento2/blob/192b28038dac2e993c65b49fb8b5af10cb520945/app/code/Magento/Payment/Gateway/Data/PaymentDataObjectInterface.php#L1-L31
My use case here is now to get the order total. The way I can achieve this is by calling the getOrder() functiom: https://github.com/magento/magento2/blob/192b28038dac2e993c65b49fb8b5af10cb520945/app/code/Magento/Payment/Gateway/Data/PaymentDataObjectInterface.php#L18-L23
This function now returns an object of the type OrderAdapterInterface. This interface is implemented by the classes OrderAdapter and QuoteAdapter. In my case I get an instance of the QuoteAdapter as I'm handling a Quote. And then I run into the problem that the function returns hardcoded null: https://github.com/magento/magento2/blob/192b28038dac2e993c65b49fb8b5af10cb520945/app/code/Magento/Payment/Gateway/Data/Quote/QuoteAdapter.php#L122-L130
I hope that this explanation now is enough for this obvious bug to be fixed.
Hi @oneserv-heuser,
Thank you for the detailed explanation. Based on it we can proceed with this issue accordingly and therefore confirming this issue again.
:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.magento.com/browse/AC-1290
@magento I am working on this
Preconditions (*)
Steps to reproduce (*)
Expected result (*)
Actual result (*)
Cause of the bug
The method always returns null as seen here: QuoteAdapter::getGrandTotalAmount()
The solution
Change the function as follows:
Example
My use case is to use the Gateway Implementation for Payment methods which magento provides and requires me to use. Specifically I need it for the availability Validator as configured as decribed here.
Here is a code example:
In my code example you can see the use case. If the function getGrandTotalAmount() always returns null (which it does, as it's hardcoded to do that) my payment method will never be available.
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.