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.55k stars 9.32k forks source link

Cart Price Rules not applying on shipping VAT when rule applied on whole cart #32468

Open Romz opened 3 years ago

Romz commented 3 years ago

Preconditions (*)

Magento 2.4.2 2.4-develop having EE and B2B Modules

Steps to reproduce (*)

Using Fresh magento installation with samples datas.

  1. Create a tax rate (20%) applied on both products and shipping.
  2. In Sales > Tax configuration Panel:
    1. Tax Class for Shipping : Taxable Goods
    2. Catalog Prices: Including Tax
    3. Shipping Prices: Including Tax
    4. Apply Discount On Prices: Including Tax
    5. Enable Cross BorderTrade : Yes
  3. Create a new cart rule
    1. Coupon: Specific Coupon
    2. Apply: Fixed amount discount for whole cart
    3. Discount Amount: 56
  4. Add a product in shopping cart (51$)
  5. Go to checkout and use a shipping methods: Flat Rate 5$
  6. Apply the cart rule using the coupon code

Expected result (*)

  1. -56$ dicount applied
  2. 0$ on Order total

Actual result (*)

  1. -55.17$ discount applied
  2. 0.83$ on order total

The discount seems to be only applied on Shipping amount excluding tax. In that case 4.17$. That's explain the -55.17$ discount amount on shopping cart (51 + 4.17)

For more details about the issue and configuration, please check this link


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 3 years ago

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


: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

m2-assistant[bot] commented 3 years ago

Hi @engcom-Oscar. 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-Oscar commented 3 years ago

Hi @Romz ! Thank you for your report.

Unfortunately, we are not able to reproduce the issue on a fresh 2.4-develop by following steps from this ticket.

Steps to reproduce (*)

  1. Create a tax rate (20%) applied on both products and shipping.
  2. In Sales > Tax configuration Panel:
    1. Tax Class for Shipping : Taxable Goods
    2. Catalog Prices: Including Tax
    3. Shipping Prices: Including Tax
    4. Apply Discount On Prices: Including Tax
    5. Enable Cross BorderTrade : Yes
  3. Create a new cart rule
    1. Coupon: Specific Coupon
    2. Apply: Fixed amount discount for whole cart
    3. Discount Amount: 56
  4. Add a product in shopping cart (51$)
  5. Go to checkout and use a shipping methods: Flat Rate 5$
  6. Apply the cart rule using the coupon code

Actual Result: :heavy_check_mark: Order summary before applying coupon: Screenshot from 2021-03-16 10-37-53 Order summary with discount after applying coupon: Screenshot from 2021-03-16 10-25-42

Please recheck - may be you missed some details in issue description.

Romz commented 3 years ago

I found out that the issue is before the checkout step.

Here the steps to reproduce.

Result:

Subtotal: $22 Dicount: $30.33 Shipping (Flat Rate - Fixed): $10 Tax: $0.28

Order Total: 1.67

The when I do the checkout process and set my address, the problem gone.

Romz commented 3 years ago

Hi @engcom-Oscar engcom-Oscar

I tried to use my $100 coupon on $102 subtotal + $15 shipping and I have an odd result. Discount applied: $101.58 which is more than the amount on my coupon rule.

m2-assistant[bot] commented 3 years ago

Hi @engcom-Echo. 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-Echo commented 3 years ago

Hi Romz ,

The issue is not getting re-produced as per the steps provided . Requested you to kindly test the issue on latest version i.e. 2.4-develop, or provide further clarification to help us reproduce the issue.

Thanks

4ctobias commented 3 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 3 years ago

Hi @4ctobias. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 3 years ago

Hi @4ctobias, here is your Magento Instance: https://d0f456901f993a68b3e51efd011f9f03-2-4-develop.instances.magento-community.engineering Admin access: https://d0f456901f993a68b3e51efd011f9f03-2-4-develop.instances.magento-community.engineering/admin_f20c Login: b68fb7d6 Password: f7a07f47c010

4ctobias commented 3 years ago

@magento give me 2.4.2-p1 instance

magento-deployment-service[bot] commented 3 years ago

Hi @4ctobias. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 3 years ago

Hi @4ctobias, here is your Magento Instance: https://d0f456901f993a68b3e51efd011f9f03-2-4-2-p1.instances.magento-community.engineering Admin access: https://d0f456901f993a68b3e51efd011f9f03-2-4-2-p1.instances.magento-community.engineering/admin_5d6b Login: ef714261 Password: c3ffe9397d48

4ctobias commented 3 years ago

Hi,

I am fully able to reproduce this with the upcoming 2.4-develop as well. It depends on the following settings (its a typical European set up - as we have to provide gross prices for products, services and shipping for customers B2C):

Now I added a product for 28$ and go to the cart page ("Edit and review cart")

I expect a order total value of 0.00 $.

As I have a Tax rate of 19 % the 0.80 order total is exactly the tax of the shipping rate (5 $ gross, 4.20 net).

If I apply this 50 $ coupon to a cart with a value more than 50 $ all works fine and is correct - so it seems that the tax of the shipping is not used correctly when using a fixed coupon if the cart value is less than this maximum discount value.

Best,

Tobias

4ctobias commented 3 years ago

For a quick/hot fix I have overriden the Magento\SalesRule\Model\Validator (with a preference-for in a di.xml). Within the processShippingAmount() I changed the processing within the \Magento\SalesRule\Model\Rule::CART_FIXED_ACTION-handling in the switch. I changed from

if ($cartRules[$rule->getId()] > 0) {
    $shippingAmount = $address->getShippingAmount() - $address->getShippingDiscountAmount();
...

to

if ($cartRules[$rule->getId()] > 0) {
    // Fix: Manual fix to respect shipping VAT if the possible fixed coupon value is > subtotal + shipping
    if ($rule->getDiscountAmount() + $shippingAmount-$address->getShippingAmount() < $address->getSubtotalInclTax() + $shippingAmount) {
        $shippingAmount = $address->getShippingAmount() - $address->getShippingDiscountAmount();
    }
...

Its not a clean solution:

But as a short and quick solution (until the issue is solved by itself) this will work.

m2-assistant[bot] commented 3 years ago

Hi @engcom-November. 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-November commented 3 years ago

Verified the issue on Magento 2.4-develop branch and the issue is reproducible on 2.4-develop branch having EE and B2B modules installed. Steps performed:

  1. Admin -> Setup EU(Germany) Store: Ref link
  2. Admin -> Stores -> Configuration -> Sales -> Tax -> Tax Class for Shipping set to "Taxable Goods" Set "Catalog Prices","Shipping Prices", "Apply Discount on Prices" to "Including Tax" Set "Apply Customer Tax" to "Before Discount".
    Note: Issue reproduced if "Apply Customer Tax" is set to After Discount as well Set Enable Cross Border Trade to "Yes"
  3. Stores -> Taxes -> Tax Zones and Rates Add new Tax Rate for Germany with 19 % (all ZIP Codes)
  4. Stores -> Taxes -> Tax Rules -> Add this Tax Zone to the current Tax rule
  5. Stores -> Configuration -> Sales -> Shipping Methods -> Change the Flat rate shipping rate from "Per Item" to "Per Order"
  6. Marketing -> Cart Price Rules -> Add New Rule -> Add a Cart Price Rule with no conditions, with a specific coupon code and apply "Fixed amount for the whole cart" for the value of say Ex: $50, and apply this coupon to Shipping Amount - Yes
  7. Front end -> Add a product worth 28$ to cart and go to the cart page ("Edit and review cart")
  8. Apply the discount and verify Issue: Cart Page - Discount of $32.20 is applied. There is no issue in Checkout page - Discount of $33 is applied. Order Total is displayed as 0 is both Cart page and Checkout page. No issue image

Checkout page: No issue image

Note: This issue is observed even for configuration: Stores -> Configuration -> Sales -> Tax -> "Apply Customer Tax" to "After Discount" as well.

magento-engcom-team commented 3 years ago

:white_check_mark: Confirmed by @engcom-November Thank you for verifying the issue. Based on the provided information internal tickets MC-42852 were created

Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

Thundar commented 3 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 3 years ago

Hi @Thundar. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 3 years ago

Hi @Thundar, here is your Magento Instance: https://d0f456901f993a68b3e51efd011f9f03-2-4-develop.instances.magento-community.engineering Admin access: https://d0f456901f993a68b3e51efd011f9f03-2-4-develop.instances.magento-community.engineering/admin_532b Login: cc06d6a0 Password: 18d8b5349234

ABC-Chefkoch commented 1 year ago

Hello,

facing same problem on 2.4.4 on catalog inc taxes (same configuration as start topic) Discount code configuration (50€ fixed values for whole cart with "Apply to Shipping Amount")

Warenkorb

please provide fix or any hints for fixing

timbaltissen commented 1 year ago

Exact same issue in 2.4.3-p2, please provide the fix. Thanks a lot.

anvanza commented 1 year ago

@timbaltissen @4ctobias ,

Have you found a solution for 2.4.5?