magento2: Method Magento\Payment\Gateway\Data\Quote\QuoteAdapter::getGrandTotalAmount() always returns null
Preconditions (*)
- Magento 2.4.3
Steps to reproduce (*)
Expected result (*)
- The grand total amount of the quote gets returned.
Actual result (*)
- null is always returned.
Cause of the bug
The method always returns null as seen here: QuoteAdapter::getGrandTotalAmount()
/**
* Returns order grand total amount
*
* @return null
*/
public function getGrandTotalAmount()
{
return null;
}
The solution
Change the function as follows:
/**
* Returns order grand total amount
*
* @return float
*/
public function getGrandTotalAmount()
{
return $this->quote->getBaseGrandTotal();
}
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:
<?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.
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 16 (5 by maintainers)
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 interfaceOrderAdapterInterface
which is implemented byQuoteAdapter
class, there is a function getGrandTotalAmount() which has the return type float and is inaccurate in that respect also. So confirming this issue.Thanks