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
- Create a store in DE with "Prices are entered with taxes included" enabled and a DE tax registration.
- Create an EU VAT tax type and uncheck "Display taxes of this type inclusive in product prices".
- 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).
- 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 onStoreTaxInterface, and use it inTaxOrderProcessor. - 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
- #2874167: Handle the prices-include-tax and Intra-Community-Supply scenario: found while writing tests for the Intra-Community Supply fix
- #2982355: Incorrect percentage discounts when prices are entered with tax, but displayed without (or vice-versa): also deals with prices entered with tax but displayed without, but is about discounts
- #2934538: Tax amount removed twice for tax-exempt customer when price include tax: same configuration, opposite symptom (tax removed twice), fixed in 2018
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
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
Comment #2
anybodyPushed 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.LocalTaxTypeBase::apply()removed the store tax for exempt customers regardless of the display setting. The filter was added when the logic moved intoTaxOrderProcessor.TaxOrderProcessoronly 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_taxkernel tests pass locally. API note:getDefaultTaxType()now also returns display-exclusive tax types. Within commerce, onlyTaxOrderProcessoruses 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.
Comment #4
anybodyComment #5
anybodyComment #6
anybodyNot 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!
Comment #7
anybodyTest-only fails as expected.