magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

[2.4.5-p3] [GraphQL] Applied discounts not returned for virtual carts #37769

Open DuckThom opened 1 year ago

DuckThom commented 1 year ago

Preconditions and environment

Steps to reproduce

  1. Create an empty cart
  2. Add virtual product to the cart
  3. Apply coupon code to cart
  4. Retrieve the cart with the applied discounts
query cart($cartId: String!) {
    cart(cart_id: $cartId) {
        is_virtual
        prices {
            discounts {
                amount {
                    value
                    currency
                }
                label
            }
        }
        applied_coupons {
            code
        }
    }
}

Expected result

Coupon is applied to the cart and the applied discount is visible in the cart.prices.discounts array.

{
  is_virtual: true,
  prices: {
    discounts: [
      { amount: { value: 159.8, currency: 'EUR' }, label: '20% Discount' }
    ]
  },
  applied_coupons: [ { code: 'TEST-123' } ]
}

Actual result

Coupon code is applied and the discount is subtracted from the order total, however, the cart.prices.discounts field is null

{
  is_virtual: true,
  prices: {
    discounts: null
  },
  applied_coupons: [ { code: 'TEST-123' } ]
}

Additional information

https://github.com/magento/magento2/blob/ca30c47787db932b9431e42226bb918e95c932d9/app/code/Magento/QuoteGraphQl/Model/Resolver/Discounts.php#L45

The Discounts resolver attempts to read the discounts from the cart shipping address. Since it's a virtual cart, there is no shipping address and therefor no discounts will be returned.

Potential fix Changing the line to $address = $quote->getBillingAddress(); will return the discounts as expected. But I am not sure if this will be 100% reliable.

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @DuckThom. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

m2-assistant[bot] commented 1 year ago

Hi @engcom-Bravo. 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:

engcom-Bravo commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo, here is your Magento Instance: https://7108b5f85a79b56ea3e7305a62bfbf5f.instances-prod.magento-community.engineering Admin access: https://7108b5f85a79b56ea3e7305a62bfbf5f.instances-prod.magento-community.engineering/admin_2634 Login: 7e2978d8 Password: 17963ab68801

engcom-Bravo commented 1 year ago

Hi @DuckThom,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is not reproducible.Kindly refer the screenshots.

Steps to reproduce

query cart($cartId: String!) {
    cart(cart_id: $cartId) {
        is_virtual
        prices {
            discounts {
                amount {
                    value
                    currency
                }
                label
            }
        }
        applied_coupons {
            code
        }
    }
}
Screenshot 2023-07-19 at 12 28 17 PM Screenshot 2023-07-19 at 12 26 52 PM

As per this document https://developer.adobe.com/commerce/webapi/graphql/schema/cart/queries/cart/#cartprices-object we will get the discounts under discounts object.Please refer the document and let us know if you are still facing any issue.

Thanks.

DuckThom commented 1 year ago

Hello @engcom-Bravo

I am able to reproduce this on the 2.4-develop branch.

I've created a clean Magento 2 installation, with 1 virtual product and 1 cart price rule (20% discount) with a coupon code "TEST-123"

image

image

After which I've executed the following GraphQL mutations:

  1. Create an empty cart:

image

  1. Added the product to the cart

image

  1. Applied the coupon code

image

As you can see in the final screenshot, the coupon code is applied, but the cart.prices.discounts field is empty

DuckThom commented 1 year ago

Additionally, here is a screenshot of the cart query of the current situation:

image

As you can see, the 20% discount itself is applied (grand total is 10 EUR lower than the subtotal). But there is no active discount listed in the response.

Here is a screenshot of the response (query is the same as above) where I applied the potential fix I mentioned in my original comment:

image

Here, the applied discount amount of 20% / 10 EUR is correctly visible in the response.

engcom-Bravo commented 1 year ago

Hi @DuckThom,

Thanks for your quick response.

Verified the issue on Magento 2.4-develop instance and the issue is reproducible. Kindly refer the screenshots.

Steps to reproduce

query cart($cartId: String!) {
    cart(cart_id: $cartId) {
        is_virtual
        prices {
            discounts {
                amount {
                    value
                    currency
                }
                label
            }
        }
        applied_coupons {
            code
        }
    }
}
Screenshot 2023-07-19 at 12 15 07 PM

Coupon is getting applied but in the discounts field we are getting as NULL.

Hence Confirming this issue.

Thanks.

github-jira-sync-bot commented 1 year ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-9169 is successfully created for this GitHub issue.

m2-assistant[bot] commented 1 year ago

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

duncan16101994 commented 6 months ago

any update?