This commit is contained in:
Your Name committed 2026-06-25 19:57:14 -04:00
1 parent 46d504e483
commit 4950661abf
15 files changed
+151 -123

No files matched your search

+47 -11
View File
@@ -302,7 +302,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
},
variants: {
type: "array",
description: "List of variants. 'option1' maps to options[0].values, 'option2' to options[1].values, etc.",
description: "List of variants mapping to the options. IMPORTANT: option1, option2, option3 MUST perfectly match the primary 'th' value provided in options.values.",
items: {
type: "object",
properties: {
@@ -310,9 +310,9 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
barcode: { type: "string" },
price: { type: "number" },
stock: { type: "number", default: 0 },
option1: { type: "string" },
option2: { type: "string" },
option3: { type: "string" }
option1: { type: "string", description: "MUST exactly match the 'th' string from options[0].values. Do NOT use translated strings." },
option2: { type: "string", description: "MUST exactly match the 'th' string from options[1].values. Do NOT use translated strings." },
option3: { type: "string", description: "MUST exactly match the 'th' string from options[2].values. Do NOT use translated strings." }
},
required: ["option1"]
}
@@ -372,6 +372,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
},
variants: {
type: "array",
description: "List of variants mapping to the options. IMPORTANT: option1, option2, option3 MUST perfectly match the primary 'th' value provided in options.values.",
items: {
type: "object",
properties: {
@@ -379,9 +380,9 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
barcode: { type: "string" },
price: { type: "number" },
stock: { type: "number", default: 0 },
option1: { type: "string" },
option2: { type: "string" },
option3: { type: "string" }
option1: { type: "string", description: "MUST exactly match the 'th' string from options[0].values. Do NOT use translated strings." },
option2: { type: "string", description: "MUST exactly match the 'th' string from options[1].values. Do NOT use translated strings." },
option3: { type: "string", description: "MUST exactly match the 'th' string from options[2].values. Do NOT use translated strings." }
},
required: ["option1"]
}
@@ -408,10 +409,12 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
properties: {
name: {
type: "object",
description: "Object with language codes as keys (e.g. {'th': 'ขนาด', 'en': 'Size'})",
additionalProperties: { type: "string" }
},
values: {
type: "array",
description: "Array of language map objects (e.g. [{'th': 'เล็ก', 'en': 'Small'}, {'th': 'ใหญ่', 'en': 'Large'}])",
items: {
type: "object",
additionalProperties: { type: "string" }
@@ -423,6 +426,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
},
variants: {
type: "array",
description: "List of variants mapping to the options. IMPORTANT: option1, option2, option3 MUST perfectly match the primary 'th' value provided in options.values.",
items: {
type: "object",
properties: {
@@ -430,9 +434,9 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
sku: { type: "string" },
price: { type: "number" },
stock: { type: "number" },
option1: { type: "string" },
option2: { type: "string" },
option3: { type: "string" }
option1: { type: "string", description: "MUST exactly match the 'th' string from options[0].values (e.g. 'เล็ก'). Do NOT use translated strings." },
option2: { type: "string", description: "MUST exactly match the 'th' string from options[1].values. Do NOT use translated strings." },
option3: { type: "string", description: "MUST exactly match the 'th' string from options[2].values. Do NOT use translated strings." }
},
required: ["option1"]
}
@@ -465,7 +469,19 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
lang: { type: "string", description: "Language code (e.g., en, ja, zh, vi, ko)" },
name: { type: "string", description: "Translated product name" },
description: { type: "string", description: "Translated description" },
details: { type: "string", description: "Translated details (HTML or Markdown allowed)" }
details: { type: "string", description: "Translated details (HTML or Markdown allowed)" },
options: {
type: "array",
description: "Translated options mapped by index. Provide array of { name: 'Translated Option', values: ['Trans Val 1', 'Trans Val 2'] }. Do not use for 'th', use sync_product_variants to edit base Thai options.",
items: {
type: "object",
properties: {
name: { type: "string" },
values: { type: "array", items: { type: "string" } }
},
required: ["name", "values"]
}
}
},
required: ["id", "lang"]
}
@@ -842,6 +858,26 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (params.description) payload.description = { [params.lang]: params.description };
if (params.details) payload.details = { [params.lang]: params.details };
if (params.options && params.lang !== "th") {
const productRes = await api.get(`/products/${params.id}`);
const product = productRes.data;
if (product && Array.isArray(product.options)) {
const mergedOptions = product.options.map((opt: any, i: number) => {
const newOpt = params.options[i];
if (!newOpt) return opt;
const mergedName = { ...opt.name, [params.lang]: newOpt.name };
const mergedValues = Array.isArray(opt.values) ? opt.values.map((val: any, j: number) => {
const newVal = newOpt.values?.[j];
return newVal ? { ...val, [params.lang]: newVal } : val;
}) : opt.values;
return { ...opt, name: mergedName, values: mergedValues };
});
payload.options = mergedOptions;
}
}
await api.patch(`/products/${params.id}`, payload);
return {
content: [{ type: "text", text: JSON.stringify({ success: true, message: `Translation for language '${params.lang}' updated successfully on product ${params.id}.` }, null, 2) }]