Problem/Motivation

If a store has "Prices are entered with taxes included" enabled, but the tax type is configured to display prices without tax (display_inclusive = FALSE), tax-exempt customers are overcharged. The tax included in the price is never removed.

TaxOrderProcessor::process() is supposed to reduce the unit price when no tax applies ("Don't overcharge a tax-exempt customer if the price is tax-inclusive"). To find the tax to remove, it calls StoreTax::getDefaultRates(). However, StoreTax::getTaxTypes() drops every tax type that is not display-inclusive:

if (!($tax_type_plugin instanceof LocalTaxTypeInterface) || !$tax_type_plugin->isDisplayInclusive()) {
  unset($this->taxTypes[$tax_type_id]);
}

So getDefaultRates() returns no rates and the price stays unchanged.

Example: a German store, prices entered including tax, the EU VAT tax type set to display tax excluded, and a product priced at 11.90 €:

  • Customer in Serbia (export): pays 11.90 € net instead of 10.00 €.
  • EU B2B customer with a valid VAT number (Intra-Community Supply, see #2874167): pays 11.90 € net instead of 10.00 €.

With display_inclusive = TRUE, both cases are correctly reduced to 10.00 €.

Steps to reproduce

  1. Create a store in DE with "Prices are entered with taxes included" enabled and a DE tax registration.
  2. Create an EU VAT tax type and uncheck "Display taxes of this type inclusive in product prices".
  3. Add a product priced at 11.90 € to the cart and check out with a billing address in RS (or in FR with a valid VAT number).
  4. The unit price stays at 11.90 € and no tax is applied.

Proposed resolution

The display-inclusive filter makes sense for showing prices (e.g. product price display), but not for working out the tax that is contained in an entered price. That tax depends on prices_include_tax, not on how the tax is displayed. Options:

  • Add a way to get the store's default rates regardless of display_inclusive, e.g. a parameter or a separate method on StoreTaxInterface, and use it in TaxOrderProcessor.
  • Or handle the reduction in LocalTaxTypeBase::apply(), which already converts between entered and displayed prices.

Add kernel tests for an export and an Intra-Community Supply with display_inclusive = FALSE.

Remaining tasks

  • Agree on the approach
  • MR + tests

Related

AI disclaimer: This issue was prepared with the help of an AI assistant (Claude Code). I reproduced the behaviour with a local kernel test on Commerce 3.3.14.

Issue fork commerce-3640293

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

anybody created an issue. See original summary.

anybody’s picture

Status: Active » Needs review

Pushed a fix with tests to the issue fork.

  • StoreTax::getTaxTypes() no longer skips tax types that are not display-inclusive. The display setting controls how prices are shown, not which tax is included in entered prices.
  • This is a regression from #2981432 (2018). Before that refactor, LocalTaxTypeBase::apply() removed the store tax for exempt customers regardless of the display setting. The filter was added when the logic moved into TaxOrderProcessor.
  • Tax can't be removed twice: TaxOrderProcessor only reduces the price when no tax adjustment was applied. For taxable customers, LocalTaxTypeBase::apply() keeps doing the entered-to-displayed conversion as before.

Tests:

  • OrderIntegrationTest::testTaxExemptPricesDisplayExclusive(): export customer, 12.00 becomes 10.00. Fails without the fix (12.00).
  • OrderIntegrationTest::testTaxablePricesDisplayExclusive(): taxable customer, unit price 10.00 + 2.00 tax shown separately, total 12.00 (no double removal).
  • StoreTaxTest::testDefaultTaxType(): now expects display-exclusive tax types to be returned.

All commerce_tax kernel tests pass locally. API note: getDefaultTaxType() now also returns display-exclusive tax types. Within commerce, only TaxOrderProcessor uses it. If maintainers prefer to keep the old behaviour of the public method, an alternative is a separate method or a parameter for the processor.

The Intra-Community Supply variant of this bug also needs #2874167.

AI disclaimer: This fix and the tests were prepared with the help of an AI assistant (Claude Code). I verified the results by running the tests locally.

anybody’s picture

anybody’s picture

Not even a super complicated fix, if it works as expected.

Also please take a look at the both related issues, I think we should solve them in combination.

Thanks!

anybody’s picture

Test-only fails as expected.