Skip to content

Vat calculated incorrectly on product when added to cart (using a vat number) #23116

@Unlimitedbul

Description

@Unlimitedbul

Preconditions (*)

  1. Magento CE 2.3.1 without sample data is installed.

Steps to reproduce (*)

  1. Configure tax zones and rates as follows:
    Screenshot 2019-06-03 at 17 21 36
  2. Configure tax rules as follows:
    Screenshot 2019-06-03 at 17 23 13
  3. Configure customer groups as follows:
    Screenshot 2019-06-03 at 17 23 55
  4. Add a test product:
    Screenshot 2019-06-03 at 17 24 54
  5. Set the default country (stores>configuration>general>general) to the Netherlands (other european countries should have the same problem)
  6. Configure store information as follows (Make sure you use a valid european Vat number and country combination. The vat number should not contain the country prefix):
    Screenshot 2019-06-03 at 17 10 10
  7. Configure customer configuration (stores>configuration>customers>customer configuration) as follows:
    Screenshot 2019-06-03 at 17 17 29
    Screenshot 2019-06-03 at 17 17 53
  8. Configure Tax (stores>configuration>sales>tax) as follows:
    Screenshot 2019-06-03 at 17 18 52
    Screenshot 2019-06-03 at 17 19 06
  9. Create an account in the frontend with (make sure you use a valid vat number country combination according to the tax rule setup earlier (BE vat number). The vat number should not contain the country prefix):
    Screenshot 2019-06-04 at 09 31 03
  10. Enter a default billing address (make sure the vat number is the same one used in the previous step and the country should be the same as the origin of the vat number (BE in this case)):
    Screenshot 2019-06-04 at 09 37 49
  11. Go to the product page of the product you added.
  12. The price it shows should not contain any tax for Belgium vat validated customers (this still works as long as you have never added a product to your cart before).
    Screenshot 2019-06-04 at 09 47 01
  13. Add the product to your cart.
  14. Open the shopping cart

Expected result (*)

  1. The shopping cart shows the same price as the catalog (no tax added to the product)

Actual result (*)

  1. The shopping cart shows the price with the default BE tax (10%) added.
    Screenshot 2019-06-04 at 09 48 31
  2. From this point on the catalog also shows the wrong price.
    Screenshot 2019-06-04 at 09 47 14

Workaround

Adding the following 2 lines to:
vendor/magento/module-quote/Observer/Frontend/Quote/Address/CollectTotalsObserver.php

Starting from line 105:

/** try to get data from customer if quote address needed data is empty */
if (empty($customerCountryCode) && empty($customerVatNumber) && $customer->getDefaultShipping()) {
    $customerAddress = $this->addressRepository->getById($customer->getDefaultShipping());

    $address->setCountryId($customerAddress->getCountryId());  // ADD THIS LINE
    $address->setVatId($customerAddress->getVatId());           // ADD THIS LINE
    $customerCountryCode = $customerAddress->getCountryId();
    $customerVatNumber = $customerAddress->getVatId();
}

Seems to have fixed the issue

Metadata

Metadata

Assignees

Labels

Component: QuoteComponent: TaxIssue: Cannot ReproduceCannot reproduce the issue on the latest `2.4-develop` branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentgood first issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions