feat(core-flows,types,utils,medusa): Translate tax lines (#14359)

* Include locale field for traslations on tax line workflows

* Translate tax lines in getItemTaxLinesStep with new util

* Update tax calculation context, so that we pass locale to third party tax providers if they want to return translated tax rates

* Apply translations to tax lines on product and variant tax middlewares

* Cart management translations tests

* Update tax lines when order locale gets updated

* Add changeset

* Get tranlsated tax lines step

* Fix wording

* Mutate ref directly

* Update order tax lines translations upon order locale change

* Claims translations tests

* Update tax lines upon draft order locale update

* Exchange tests for tax lines translations

* Order edits test for tax line translation

* Add tests for shipping methods tax line translations on various order flows

* Returns shipping method translations tests

* Execute update in parallel

* Use TranslationFeatureFlag.key

* Fix feature flag import

* Add @medusajs/medusa dependency for feature flag usage

* Revert "Add @medusajs/medusa dependency for feature flag usage"

This reverts commit e8897aed0a88f83c1034ac73e817e4222250a2c9.

* Use feature flag string directly

* Fix test

* Parallelize tax line translations application
This commit is contained in:
Nicolas Gorga
2026-01-13 15:12:42 -03:00
committed by GitHub
parent 28fae96cee
commit cec8b8e428
23 changed files with 2032 additions and 164 deletions
@@ -3,8 +3,14 @@ import {
ItemTaxLineDTO,
TaxableItemDTO,
} from "@medusajs/framework/types"
import { calculateAmountsWithTax, Modules } from "@medusajs/framework/utils"
import {
calculateAmountsWithTax,
FeatureFlag,
Modules,
} from "@medusajs/framework/utils"
import { StoreRequestWithContext } from "../types"
import { applyTranslationsToTaxLines } from "@medusajs/framework/utils"
import TranslationFeatureFlag from "../../../feature-flags/translation"
export const wrapVariantsWithTaxPrices = async <T>(
req: StoreRequestWithContext<T>,
@@ -31,11 +37,22 @@ export const wrapVariantsWithTaxPrices = async <T>(
const taxService = req.scope.resolve(Modules.TAX)
const taxLines = (await taxService.getTaxLines(
let taxLines = (await taxService.getTaxLines(
items,
req.taxContext.taxLineContext
)) as unknown as ItemTaxLineDTO[]
const isTranslationEnabled = FeatureFlag.isFeatureEnabled(
TranslationFeatureFlag.key
)
if (isTranslationEnabled) {
taxLines = (await applyTranslationsToTaxLines(
taxLines,
req.locale,
req.scope
)) as ItemTaxLineDTO[]
}
const taxRatesMap = new Map<string, ItemTaxLineDTO[]>()
taxLines.forEach((taxLine) => {
@@ -5,8 +5,14 @@ import {
MedusaContainer,
TaxableItemDTO,
} from "@medusajs/framework/types"
import { calculateAmountsWithTax, Modules } from "@medusajs/framework/utils"
import {
applyTranslationsToTaxLines,
calculateAmountsWithTax,
FeatureFlag,
Modules,
} from "@medusajs/framework/utils"
import { StoreRequestWithContext } from "../types"
import TranslationFeatureFlag from "../../../feature-flags/translation"
export type RequestWithContext<
Body,
@@ -56,13 +62,24 @@ export const wrapProductsWithTaxPrices = async <T>(
const taxService = req.scope.resolve(Modules.TAX)
const taxRates = (await taxService.getTaxLines(
let taxLines = (await taxService.getTaxLines(
products.map(asTaxItem).flat(),
req.taxContext.taxLineContext
)) as unknown as ItemTaxLineDTO[]
const isTranslationEnabled = FeatureFlag.isFeatureEnabled(
TranslationFeatureFlag.key
)
if (isTranslationEnabled) {
taxLines = (await applyTranslationsToTaxLines(
taxLines,
req.locale,
req.scope
)) as ItemTaxLineDTO[]
}
const taxRatesMap = new Map<string, ItemTaxLineDTO[]>()
taxRates.forEach((taxRate) => {
taxLines.forEach((taxRate) => {
if (!taxRatesMap.has(taxRate.line_item_id)) {
taxRatesMap.set(taxRate.line_item_id, [])
}
@@ -76,6 +76,7 @@ const getTaxLinesContext = async (req: MedusaRequest) => {
country_code: req.filterableFields.country_code as string,
province_code: req.filterableFields.province as string,
},
locale: req.locale,
} as TaxCalculationContext
return taxContext