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

Method Magento\Payment\Gateway\Data\Quote\QuoteAdapter::getGrandTotalAmount() always returns null #33872

Open
1 of 5 tasks
t-heuser opened this issue Aug 20, 2021 · 16 comments
Open
1 of 5 tasks
Assignees
Labels
Area: Cart & Checkout Component: Quote Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: dev in progress Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@t-heuser
Copy link

t-heuser commented Aug 20, 2021

Preconditions (*)

  1. Magento 2.4.3

Steps to reproduce (*)

  1. Call Magento\Payment\Gateway\Data\Quote\QuoteAdapter::getGrandTotalAmount()

Expected result (*)

  1. The grand total amount of the quote gets returned.

Actual result (*)

  1. 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”.
@m2-assistant
Copy link

m2-assistant bot commented Aug 20, 2021

Hi @oneserv-heuser. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

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


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 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.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@t-heuser
Copy link
Author

I can confirm this issue exists on a vanilla magento instance.

@t-heuser
Copy link
Author

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

@engcom-Delta engcom-Delta self-assigned this Aug 23, 2021
@m2-assistant
Copy link

m2-assistant bot commented Aug 23, 2021

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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf 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 branch

    Details- 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.

@engcom-Delta engcom-Delta added Issue: needs update Additional information is require, waiting for response and removed Issue: ready for confirmation labels Aug 25, 2021
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board Aug 25, 2021
@engcom-Delta
Copy link
Contributor

engcom-Delta commented Aug 25, 2021

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

@t-heuser
Copy link
Author

t-heuser commented Aug 25, 2021

@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.

@t-heuser
Copy link
Author

@engcom-Delta I've provided the requested information, can you please change the labels/ confirm that the issue exists?

@engcom-Delta engcom-Delta added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Sep 9, 2021
@m2-assistant
Copy link

m2-assistant bot commented Sep 9, 2021

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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf 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 branch

    Details- 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.

@engcom-Lima
Copy link
Contributor

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

@engcom-Lima engcom-Lima added Component: Quote Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Area: Cart & Checkout Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed and removed Issue: needs update Additional information is require, waiting for response labels Sep 17, 2021
@m2-community-project m2-community-project bot moved this from Needs Update to Confirmed in Issue Confirmation and Triage Board Sep 17, 2021
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.magento.com/browse/AC-1290 is successfully created for this GitHub issue.

@m2-assistant
Copy link

m2-assistant bot commented Sep 17, 2021

✅ 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.

@engcom-Lima
Copy link
Contributor

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 engcom-Lima added the Issue: needs update Additional information is require, waiting for response label Sep 28, 2021
@m2-community-project m2-community-project bot moved this from Confirmed to Needs Update in Issue Confirmation and Triage Board Sep 28, 2021
@m2-community-project m2-community-project bot removed the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Sep 28, 2021
@engcom-Lima engcom-Lima self-assigned this Sep 28, 2021
@t-heuser
Copy link
Author

@engcom-Lima
Lets dive deeper into the code:

The object passed to the validate function of a Payment Gateway Validator Instance is an array:

public function validate(array $validationSubject);

This array contains an an object of the type PaymentDataObjectInterface:

<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Payment\Gateway\Data;
use Magento\Payment\Model\InfoInterface;
/**
* Interface PaymentDataObjectInterface
* @package Magento\Payment\Gateway\Data
* @api
* @since 100.0.2
*/
interface PaymentDataObjectInterface
{
/**
* Returns order
*
* @return OrderAdapterInterface
*/
public function getOrder();
/**
* Returns payment
*
* @return InfoInterface
*/
public function getPayment();
}

My use case here is now to get the order total. The way I can achieve this is by calling the getOrder() functiom:

/**
* Returns order
*
* @return OrderAdapterInterface
*/
public function getOrder();

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:

/**
* Returns order grand total amount
*
* @return null
*/
public function getGrandTotalAmount()
{
return null;
}

I hope that this explanation now is enough for this obvious bug to be fixed.

@engcom-Lima
Copy link
Contributor

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.

@engcom-Lima engcom-Lima added the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Oct 6, 2021
@m2-community-project m2-community-project bot moved this from Needs Update to Confirmed in Issue Confirmation and Triage Board Oct 6, 2021
@github-jira-sync-bot
Copy link

❌ Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.magento.com/browse/AC-1290

@m2-community-project m2-community-project bot removed the Issue: needs update Additional information is require, waiting for response label Oct 6, 2021
@github-jira-sync-bot github-jira-sync-bot added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Oct 6, 2021
@m2-community-project m2-community-project bot added this to Dev In Progress in High Priority Backlog Oct 6, 2021
@m2-community-project m2-community-project bot moved this from Dev In Progress to Ready for Development in High Priority Backlog Oct 6, 2021
@KrasnoshchokBohdan
Copy link
Contributor

@magento I am working on this

@m2-community-project m2-community-project bot moved this from Ready for Development to Dev In Progress in High Priority Backlog Aug 25, 2022
@KrasnoshchokBohdan KrasnoshchokBohdan removed their assignment Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Cart & Checkout Component: Quote Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: dev in progress Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
High Priority Backlog
  
Dev In Progress
Development

No branches or pull requests

5 participants