Skip to content

Commit 812687d

Browse files
authored
fix(core-flows): translate line items when creating an order with a locale (#15804)
createOrderWorkflow now translates line items before building the order payload, matching the behavior of cart, add-to-cart, and add-items workflows. Previously, line items supplied during order or draft-order creation retained default-language titles even when a locale was set. The translation step is feature-flagged and no-ops when no locale is provided, preserving existing behavior for stores without translations.
1 parent 6d16222 commit 812687d

3 files changed

Lines changed: 60 additions & 6 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@medusajs/core-flows": patch
3+
---
4+
5+
fix(core-flows): translate line items when creating an order with items and a locale
6+
7+
`createOrderWorkflow` did not run `getTranslatedLineItemsStep`, so line items provided at order/draft-order creation kept their default-language titles even when a `locale` was set — while items added later (via `addOrderLineItemsWorkflow`) were translated. Line items are now translated on creation too, matching the add-items, cart, and add-to-cart paths.

integration-tests/http/__tests__/draft-order/admin/draft-order-translation.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,44 @@ medusaIntegrationTestRunner({
262262
await dbUtils.snapshot()
263263
})
264264

265+
describe("POST /admin/draft-orders (create draft order with items)", () => {
266+
it("should translate items when creating a draft order with items and locale", async () => {
267+
const created = (
268+
await api.post(
269+
"/admin/draft-orders",
270+
{
271+
email: "test@test.com",
272+
region_id: region.id,
273+
sales_channel_id: salesChannel.id,
274+
locale: "fr-FR",
275+
items: [{ variant_id: product.variants[0].id, quantity: 1 }],
276+
shipping_address: {
277+
address_1: "123 Main St",
278+
city: "Anytown",
279+
country_code: "us",
280+
province: "ca",
281+
postal_code: "12345",
282+
first_name: "John",
283+
},
284+
},
285+
adminHeaders
286+
)
287+
).data.draft_order
288+
289+
const draftOrder = (
290+
await api.get(`/admin/draft-orders/${created.id}`, adminHeaders)
291+
).data.draft_order
292+
293+
expect(draftOrder.items[0]).toEqual(
294+
expect.objectContaining({
295+
product_title: "T-Shirt Medusa",
296+
product_description: "Un t-shirt en coton confortable",
297+
variant_title: "Petit",
298+
})
299+
)
300+
})
301+
})
302+
265303
describe("POST /admin/draft-orders/:id/edit/items (add items to draft order)", () => {
266304
it("should translate items when adding to draft order with locale", async () => {
267305
const draftOrder = (

packages/core/core-flows/src/order/workflows/create-order.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import { pricingContextResult } from "../../cart/utils/schemas"
2727
import { confirmVariantInventoryWorkflow } from "../../cart/workflows/confirm-variant-inventory"
2828
import { getVariantsAndItemsWithPrices } from "../../cart/workflows/get-variants-and-items-with-prices"
29-
import { useQueryGraphStep } from "../../common"
29+
import { getTranslatedLineItemsStep, useQueryGraphStep } from "../../common"
3030
import { refreshDraftOrderAdjustmentsWorkflow } from "../../draft-order/workflows/refresh-draft-order-adjustments"
3131
import { createOrdersStep } from "../steps"
3232
import { productVariantsFields } from "../utils/fields"
@@ -390,13 +390,22 @@ export const createOrderWorkflow = createWorkflow(
390390

391391
validateLineItemPricesStep({ items: lineItems })
392392

393-
const orderToCreate = transform({ lineItems, orderInput }, (data) => {
394-
return {
395-
...data.orderInput,
396-
items: data.lineItems,
397-
}
393+
const translatedLineItems = getTranslatedLineItemsStep({
394+
items: lineItems,
395+
variants,
396+
locale: input.locale,
398397
})
399398

399+
const orderToCreate = transform(
400+
{ translatedLineItems, orderInput },
401+
(data) => {
402+
return {
403+
...data.orderInput,
404+
items: data.translatedLineItems,
405+
}
406+
}
407+
)
408+
400409
const orders = createOrdersStep([orderToCreate])
401410
const order = transform({ orders }, (data) => data.orders?.[0])
402411

0 commit comments

Comments
 (0)