feat(): sync cart translation synced (#14226)
ref: https://github.com/medusajs/medusa/pull/14189 **Summary** This PR extends the translation module to support automatic translation syncing for cart line items based on the cart's locale. Key changes: - Added locale field to the Cart model to store the cart's locale preference - Created new workflow steps: - getTranslatedLineItemsStep - Translates line items when adding to cart or creating a cart - updateCartItemsTranslationsStep - Re-translates all cart items when the cart's locale changes - Integrated translation logic into cart workflows: - createCartWorkflow - Applies translations to initial line items - addToCartWorkflow - Applies translations when adding new items - updateCartWorkflow - Re-translates all items when locale_code is updated - refreshCartItemsWorkflow - Maintains translations during cart refresh - Added applyTranslationsToItems utility to map variant/product/type/collection translations to line item fields (title, subtitle, description, etc.)
This commit is contained in:
@@ -6,12 +6,12 @@ import {
|
||||
FeatureFlag,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { BatchMethodRequest, HttpTypes } from "@medusajs/types"
|
||||
import TranslationFeatureFlag from "../../../../feature-flags/translation"
|
||||
import { defaultAdminTranslationFields } from "../query-config"
|
||||
import {
|
||||
AdminCreateTranslationType,
|
||||
AdminUpdateTranslationType,
|
||||
} from "../validators"
|
||||
import TranslationFeatureFlag from "../../../../feature-flags/translation"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<
|
||||
|
||||
@@ -23,6 +23,7 @@ export const CreateCart = z
|
||||
sales_channel_id: z.string().nullish(),
|
||||
promo_codes: z.array(z.string()).optional(),
|
||||
metadata: z.record(z.unknown()).nullish(),
|
||||
locale: z.string().optional(),
|
||||
})
|
||||
.strict()
|
||||
export const StoreCreateCart = WithAdditionalData(CreateCart)
|
||||
@@ -57,6 +58,7 @@ export const UpdateCart = z
|
||||
sales_channel_id: z.string().nullish(),
|
||||
metadata: z.record(z.unknown()).nullish(),
|
||||
promo_codes: z.array(z.string()).optional(),
|
||||
locale: z.string().optional(),
|
||||
})
|
||||
.strict()
|
||||
export const StoreUpdateCart = WithAdditionalData(UpdateCart)
|
||||
|
||||
Reference in New Issue
Block a user