Open MercatoDocsSearch docsAPI reference

User guide

Taxes Overview

Define the tax rates used by Sales, then assign the appropriate rate to a product or variant. Inspect the stored tax details when reviewing how a recorded price was calculated.

Why taxes live in the Sales module

The Sales module owns tax definitions so every downstream surface (catalog, orders, quotes, invoices) reuses a single source of truth. Tax rates are tenant + organization scoped and stored as sales_tax_rates, which are administered from Sales → Configuration → Tax classes in the backend UI. Each tax class captures:

Assigning taxes to products and variants

  1. Open Catalog → Products → Create (or edit any existing product).
  2. Pick the product-level tax class. This value is automatically inherited by all variants that do not override their own class.
  3. Inside the variants builder, each SKU row exposes a “Tax class” column. Use it when specific option combinations (e.g., kids’ clothing) need a different rate than the base product.
  4. When entering prices, choose whether the price kind is including tax or excluding tax. The UI only asks for a single number – the system derives the complementary value (net vs. gross) by invoking the shared tax calculator described below.

The REST API mirrors this behaviour:

How prices store tax data

Every price row persists:

The admin UI and product APIs expose all four components so storefronts can choose the appropriate value to display or to pass into downstream ERP systems.

Shared tax calculation service

All price commands, importers, and backend forms call the DI token taxCalculationService. The default implementation (in packages/core/src/modules/sales/services/taxCalculationService.ts) runs this flow:

  1. Resolve the tax class from taxRateId, ensuring it belongs to the same org/tenant as the price row.
  2. If taxRateId is omitted, fall back to the explicit taxRate or default to zero.
  3. Normalize the entered amount (non-negative, finite).
  4. Derive the missing side of the price (net → gross or vice versa) and compute taxAmount.
  5. Emit before and after events so custom modules can intervene (see next section).

Hooking custom logic

The Event Bus publishes:

Example module hook:

import { createRequestContainer } from '@/lib/di/container'

const container = await createRequestContainer()
const eventBus = container.resolve('eventBus')

eventBus?.on('sales.tax.calculate.before', ({ input, setInput }) => {
  if (!input.taxRateId && input.organizationId === 'org-brazil') {
    setInput({ taxRateId: 'default-brazil' })
  }
})

eventBus?.on('sales.tax.calculate.after', ({ result, setResult }) => {
  if (result) {
    const rounded = Math.ceil(result.taxAmount * 100) / 100
    setResult({ ...result, taxAmount: rounded })
  }
})

Because this is a DI service, you can also replace it entirely by registering your own implementation in a module di.ts (e.g., plug in a headless tax SaaS) as long as you keep the same TaxCalculationService interface.

Price display modes

Price kinds determine whether backend inputs and frontend displays treat values as tax-inclusive (including-tax) or tax-exclusive (excluding-tax). Best practices:

Testing and migrations

Troubleshooting

Previous: System status · Next: Teams and team members