feat(): Add more translatable core entity (#14311)
* feat(): Add product type and collection translation support * Create sharp-poets-give.md * feat(): Add product type and collection translation support * feat(): Add product type and collection translation support * options * options * shipping options/type * return reason * fix * leave out shipping and return reason * leave out shipping and return reason * leave out shipping and return reason
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
"@medusajs/translation": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(): Add product type and collection translation support
|
||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
import { refetchCollection } from "../helpers"
|
import { refetchCollection } from "../helpers"
|
||||||
|
import { applyTranslations } from "@medusajs/framework/utils"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<HttpTypes.SelectParams>,
|
req: AuthenticatedMedusaRequest<HttpTypes.SelectParams>,
|
||||||
@@ -15,5 +16,11 @@ export const GET = async (
|
|||||||
req.queryConfig.fields
|
req.queryConfig.fields
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await applyTranslations({
|
||||||
|
localeCode: req.locale,
|
||||||
|
objects: [collection],
|
||||||
|
container: req.scope,
|
||||||
|
})
|
||||||
|
|
||||||
res.status(200).json({ collection })
|
res.status(200).json({ collection })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
applyTranslations,
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
@@ -26,6 +27,12 @@ export const GET = async (
|
|||||||
|
|
||||||
const { rows: collections, metadata } = await remoteQuery(query)
|
const { rows: collections, metadata } = await remoteQuery(query)
|
||||||
|
|
||||||
|
await applyTranslations({
|
||||||
|
localeCode: req.locale,
|
||||||
|
objects: collections,
|
||||||
|
container: req.scope,
|
||||||
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
collections,
|
collections,
|
||||||
count: metadata.count,
|
count: metadata.count,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { StoreProductCategoryResponse } from "@medusajs/framework/types"
|
import { StoreProductCategoryResponse } from "@medusajs/framework/types"
|
||||||
import { MedusaError } from "@medusajs/framework/utils"
|
import { applyTranslations, MedusaError } from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -24,5 +24,12 @@ export const GET = async (
|
|||||||
`Product category with id: ${req.params.id} was not found`
|
`Product category with id: ${req.params.id} was not found`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await applyTranslations({
|
||||||
|
localeCode: req.locale,
|
||||||
|
objects: [category],
|
||||||
|
container: req.scope,
|
||||||
|
})
|
||||||
|
|
||||||
res.json({ product_category: category })
|
res.json({ product_category: category })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import {
|
|
||||||
StoreProductCategoryListParams,
|
|
||||||
StoreProductCategoryListResponse,
|
|
||||||
} from "@medusajs/framework/types"
|
|
||||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
|
import {
|
||||||
|
StoreProductCategoryListParams,
|
||||||
|
StoreProductCategoryListResponse,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
|
import {
|
||||||
|
applyTranslations,
|
||||||
|
ContainerRegistrationKeys,
|
||||||
|
} from "@medusajs/framework/utils"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: AuthenticatedMedusaRequest<StoreProductCategoryListParams>,
|
req: AuthenticatedMedusaRequest<StoreProductCategoryListParams>,
|
||||||
@@ -21,6 +24,12 @@ export const GET = async (
|
|||||||
pagination: req.queryConfig.pagination,
|
pagination: req.queryConfig.pagination,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await applyTranslations({
|
||||||
|
localeCode: req.locale,
|
||||||
|
objects: product_categories,
|
||||||
|
container: req.scope,
|
||||||
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
product_categories,
|
product_categories,
|
||||||
count: metadata!.count,
|
count: metadata!.count,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { StoreProductTagResponse } from "@medusajs/framework/types"
|
import { StoreProductTagResponse } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
|
applyTranslations,
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
@@ -30,5 +31,14 @@ export const GET = async (
|
|||||||
`Product tag with id: ${req.params.id} was not found`
|
`Product tag with id: ${req.params.id} was not found`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
res.json({ product_tag: data[0] })
|
|
||||||
|
const productTag = data[0]
|
||||||
|
|
||||||
|
await applyTranslations({
|
||||||
|
localeCode: req.locale,
|
||||||
|
objects: [productTag],
|
||||||
|
container: req.scope,
|
||||||
|
})
|
||||||
|
|
||||||
|
res.json({ product_tag: productTag })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import { HttpTypes } from "@medusajs/framework/types"
|
import { HttpTypes } from "@medusajs/framework/types"
|
||||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
import {
|
||||||
|
applyTranslations,
|
||||||
|
ContainerRegistrationKeys,
|
||||||
|
} from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -18,6 +21,12 @@ export const GET = async (
|
|||||||
fields: req.queryConfig.fields,
|
fields: req.queryConfig.fields,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await applyTranslations({
|
||||||
|
localeCode: req.locale,
|
||||||
|
objects: product_tags,
|
||||||
|
container: req.scope,
|
||||||
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
product_tags,
|
product_tags,
|
||||||
count: metadata?.count ?? 0,
|
count: metadata?.count ?? 0,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { StoreProductTypeResponse } from "@medusajs/framework/types"
|
import { StoreProductTypeResponse } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
|
applyTranslations,
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
@@ -30,5 +31,14 @@ export const GET = async (
|
|||||||
`Product type with id: ${req.params.id} was not found`
|
`Product type with id: ${req.params.id} was not found`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
res.json({ product_type: data[0] })
|
|
||||||
|
const productType = data[0]
|
||||||
|
|
||||||
|
await applyTranslations({
|
||||||
|
localeCode: req.locale,
|
||||||
|
objects: [productType],
|
||||||
|
container: req.scope,
|
||||||
|
})
|
||||||
|
|
||||||
|
res.json({ product_type: productType })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import { HttpTypes } from "@medusajs/framework/types"
|
import { HttpTypes } from "@medusajs/framework/types"
|
||||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
import {
|
||||||
|
applyTranslations,
|
||||||
|
ContainerRegistrationKeys,
|
||||||
|
} from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
AuthenticatedMedusaRequest,
|
AuthenticatedMedusaRequest,
|
||||||
MedusaResponse,
|
MedusaResponse,
|
||||||
@@ -18,6 +21,12 @@ export const GET = async (
|
|||||||
fields: req.queryConfig.fields,
|
fields: req.queryConfig.fields,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await applyTranslations({
|
||||||
|
localeCode: req.locale,
|
||||||
|
objects: product_types,
|
||||||
|
container: req.scope,
|
||||||
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
product_types,
|
product_types,
|
||||||
count: metadata?.count ?? 0,
|
count: metadata?.count ?? 0,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
import { HttpTypes, QueryContextType } from "@medusajs/framework/types"
|
import { HttpTypes, QueryContextType } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
|
applyTranslations,
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
QueryContext,
|
QueryContext,
|
||||||
@@ -60,6 +61,12 @@ export const GET = async (
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await applyTranslations({
|
||||||
|
localeCode: req.locale,
|
||||||
|
objects: [variant],
|
||||||
|
container: req.scope,
|
||||||
|
})
|
||||||
|
|
||||||
if (withInventoryQuantity) {
|
if (withInventoryQuantity) {
|
||||||
await wrapVariantsWithInventoryQuantityForSalesChannel(req, [variant])
|
await wrapVariantsWithInventoryQuantityForSalesChannel(req, [variant])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
} from "@medusajs/framework/http"
|
} from "@medusajs/framework/http"
|
||||||
import { HttpTypes, QueryContextType } from "@medusajs/framework/types"
|
import { HttpTypes, QueryContextType } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
|
applyTranslations,
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
QueryContext,
|
QueryContext,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
@@ -54,6 +55,12 @@ export const GET = async (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await applyTranslations({
|
||||||
|
localeCode: req.locale,
|
||||||
|
objects: variants,
|
||||||
|
container: req.scope,
|
||||||
|
})
|
||||||
|
|
||||||
if (withInventoryQuantity) {
|
if (withInventoryQuantity) {
|
||||||
await wrapVariantsWithInventoryQuantityForSalesChannel(req, variants)
|
await wrapVariantsWithInventoryQuantityForSalesChannel(req, variants)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||||
|
import { HttpTypes } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
||||||
import { StoreReturnReasonParamsType } from "../validators"
|
import { StoreReturnReasonParamsType } from "../validators"
|
||||||
import { HttpTypes } from "@medusajs/framework/types"
|
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: MedusaRequest<StoreReturnReasonParamsType>,
|
req: MedusaRequest<StoreReturnReasonParamsType>,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||||
|
import { HttpTypes } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
||||||
import { HttpTypes } from "@medusajs/framework/types"
|
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
req: MedusaRequest<HttpTypes.FindParams>,
|
req: MedusaRequest<HttpTypes.FindParams>,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { HttpTypes } from "@medusajs/framework/types"
|
|
||||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
||||||
import { calculateShippingOptionsPricesWorkflow } from "@medusajs/core-flows"
|
import { calculateShippingOptionsPricesWorkflow } from "@medusajs/core-flows"
|
||||||
|
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||||
|
import { HttpTypes } from "@medusajs/framework/types"
|
||||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ export const GET = async (
|
|||||||
|
|
||||||
const workflow = listShippingOptionsForCartWorkflow(req.scope)
|
const workflow = listShippingOptionsForCartWorkflow(req.scope)
|
||||||
const { result: shipping_options } = await workflow.run({
|
const { result: shipping_options } = await workflow.run({
|
||||||
input: {
|
input: {
|
||||||
cart_id,
|
cart_id,
|
||||||
is_return: !!is_return,
|
is_return: !!is_return,
|
||||||
fields: req.queryConfig.fields
|
fields: req.queryConfig.fields,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import { ModuleJoinerConfig } from "@medusajs/framework/types"
|
import { ModuleJoinerConfig } from "@medusajs/framework/types"
|
||||||
import {
|
import { MEDUSA_SKIP_FILE, Modules } from "@medusajs/framework/utils"
|
||||||
FeatureFlag,
|
|
||||||
MEDUSA_SKIP_FILE,
|
|
||||||
Modules,
|
|
||||||
} from "@medusajs/framework/utils"
|
|
||||||
|
|
||||||
export const ProductTranslation: ModuleJoinerConfig = {
|
export const ProductTranslation: ModuleJoinerConfig = {
|
||||||
[MEDUSA_SKIP_FILE]: !FeatureFlag.isFeatureEnabled("translation"),
|
[MEDUSA_SKIP_FILE]: process.env.MEDUSA_FF_TRANSLATION !== "true",
|
||||||
isLink: true,
|
isLink: true,
|
||||||
isReadOnlyLink: true,
|
isReadOnlyLink: true,
|
||||||
extends: [
|
extends: [
|
||||||
|
|||||||
@@ -1,50 +1,9 @@
|
|||||||
import { LoaderOptions } from "@medusajs/framework/types"
|
import { LoaderOptions } from "@medusajs/framework/types"
|
||||||
import {
|
|
||||||
PRODUCT_TRANSLATABLE_FIELDS,
|
|
||||||
PRODUCT_VARIANT_TRANSLATABLE_FIELDS,
|
|
||||||
} from "../utils/translatable-fields"
|
|
||||||
import { asValue } from "awilix"
|
|
||||||
import { TRANSLATABLE_FIELDS_CONFIG_KEY } from "@utils/constants"
|
import { TRANSLATABLE_FIELDS_CONFIG_KEY } from "@utils/constants"
|
||||||
|
import { asValue } from "awilix"
|
||||||
|
import { translatableFieldsConfig } from "../utils/translatable-fields"
|
||||||
|
|
||||||
export default async ({
|
export default async ({ container }: LoaderOptions): Promise<void> => {
|
||||||
container,
|
|
||||||
options,
|
|
||||||
}: LoaderOptions<{
|
|
||||||
expandedTranslatableFields: { [key: string]: string[] }
|
|
||||||
}>): Promise<void> => {
|
|
||||||
const { expandedTranslatableFields } = options ?? {}
|
|
||||||
|
|
||||||
const { product, productVariant, ...others } =
|
|
||||||
expandedTranslatableFields ?? {}
|
|
||||||
|
|
||||||
const translatableFieldsConfig: Record<string, string[]> = {
|
|
||||||
product: PRODUCT_TRANSLATABLE_FIELDS,
|
|
||||||
product_variant: PRODUCT_VARIANT_TRANSLATABLE_FIELDS,
|
|
||||||
}
|
|
||||||
|
|
||||||
if (product) {
|
|
||||||
const translatableFields = new Set([
|
|
||||||
...PRODUCT_TRANSLATABLE_FIELDS,
|
|
||||||
...product,
|
|
||||||
])
|
|
||||||
translatableFieldsConfig.product = Array.from(translatableFields)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (productVariant) {
|
|
||||||
const translatableFields = new Set([
|
|
||||||
...PRODUCT_VARIANT_TRANSLATABLE_FIELDS,
|
|
||||||
...productVariant,
|
|
||||||
])
|
|
||||||
translatableFieldsConfig.product_variant = Array.from(translatableFields)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (others) {
|
|
||||||
Object.entries(others).forEach(([key, value]) => {
|
|
||||||
const translatableFields = new Set([...value])
|
|
||||||
translatableFieldsConfig[key] = Array.from(translatableFields)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
container.register(
|
container.register(
|
||||||
TRANSLATABLE_FIELDS_CONFIG_KEY,
|
TRANSLATABLE_FIELDS_CONFIG_KEY,
|
||||||
asValue(translatableFieldsConfig)
|
asValue(translatableFieldsConfig)
|
||||||
|
|||||||
@@ -5,5 +5,35 @@ export const PRODUCT_TRANSLATABLE_FIELDS = [
|
|||||||
"subtitle",
|
"subtitle",
|
||||||
"status",
|
"status",
|
||||||
]
|
]
|
||||||
|
|
||||||
export const PRODUCT_VARIANT_TRANSLATABLE_FIELDS = ["title", "material"]
|
export const PRODUCT_VARIANT_TRANSLATABLE_FIELDS = ["title", "material"]
|
||||||
|
export const PRODUCT_TYPE_TRANSLATABLE_FIELDS = ["value"]
|
||||||
|
export const PRODUCT_COLLECTION_TRANSLATABLE_FIELDS = ["title"]
|
||||||
|
export const PRODUCT_CATEGORY_TRANSLATABLE_FIELDS = ["name", "description"]
|
||||||
|
export const PRODUCT_TAG_TRANSLATABLE_FIELDS = ["value"]
|
||||||
|
export const PRODUCT_OPTION_TRANSLATABLE_FIELDS = ["title"]
|
||||||
|
export const PRODUCT_OPTION_VALUE_TRANSLATABLE_FIELDS = ["value"]
|
||||||
|
|
||||||
|
// export const SHIPPING_OPTION_TRANSLATABLE_FIELDS = ["name"]
|
||||||
|
// export const SHIPPING_OPTION_TYPE_TRANSLATABLE_FIELDS = ["label", "description"]
|
||||||
|
|
||||||
|
// export const RETURN_REASON_TRANSLATABLE_FIELDS = [
|
||||||
|
// "value",
|
||||||
|
// "label",
|
||||||
|
// "description",
|
||||||
|
// ]
|
||||||
|
|
||||||
|
export const translatableFieldsConfig = {
|
||||||
|
product: PRODUCT_TRANSLATABLE_FIELDS,
|
||||||
|
product_variant: PRODUCT_VARIANT_TRANSLATABLE_FIELDS,
|
||||||
|
product_type: PRODUCT_TYPE_TRANSLATABLE_FIELDS,
|
||||||
|
product_collection: PRODUCT_COLLECTION_TRANSLATABLE_FIELDS,
|
||||||
|
product_category: PRODUCT_CATEGORY_TRANSLATABLE_FIELDS,
|
||||||
|
product_tag: PRODUCT_TAG_TRANSLATABLE_FIELDS,
|
||||||
|
product_option: PRODUCT_OPTION_TRANSLATABLE_FIELDS,
|
||||||
|
product_option_value: PRODUCT_OPTION_VALUE_TRANSLATABLE_FIELDS,
|
||||||
|
|
||||||
|
// shipping_option: SHIPPING_OPTION_TRANSLATABLE_FIELDS,
|
||||||
|
// shipping_option_type: SHIPPING_OPTION_TYPE_TRANSLATABLE_FIELDS,
|
||||||
|
|
||||||
|
// return_reason: RETURN_REASON_TRANSLATABLE_FIELDS,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user