From 8bf1843b9b1ada4d0f04f371d16eb23ed2d64d68 Mon Sep 17 00:00:00 2001 From: devops Date: Wed, 14 Oct 2026 15:48:29 +0000 Subject: [PATCH] fix(torob): deduplicate subtitle package size and add fresh expiry guarantee --- backend/src/products/torob.controller.ts | 30 +++++++++++++------ .../app/api/torob/products/route.ts | 24 ++++++++++++--- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/backend/src/products/torob.controller.ts b/backend/src/products/torob.controller.ts index d268ad10..33726b9f 100644 --- a/backend/src/products/torob.controller.ts +++ b/backend/src/products/torob.controller.ts @@ -102,7 +102,7 @@ function buildTorobProductSpec(product: { const spec: Record = { 'برند': 'کنینا (Canina Pharma Germany)', 'کشور سازنده': 'آلمان', - 'ضمانت': 'اصالت ۱۰۰٪ کالای آلمانی و سلامت فیزیکی', + 'ضمانت': 'اصالت ۱۰۰٪ کالای آلمانی، سلامت فیزیکی و تاریخ انقضای به‌روز', }; const pet = normalizeSuitableFor(product.suitableFor); @@ -183,16 +183,28 @@ export class TorobController { const rawEn = (product.nameEn || "").trim(); const numSize = Number(product.packageSize); const unit = (product.unit || "").trim(); - const sizeStr = - numSize && numSize > 0 - ? unit - ? `${numSize} ${unit}` - : `${numSize}` - : ""; let subtitle = rawEn.startsWith("Canina") ? rawEn : `Canina ${rawEn}`.trim(); - if (sizeStr && !subtitle.includes(sizeStr)) { + + // Check if size is already present in subtitle + let sizeAlreadyInSubtitle = false; + if (numSize && numSize > 0) { + const escapedUnit = unit.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + const regexList = [ + new RegExp(`\\b${numSize}\\s*${escapedUnit}\\b`, 'i'), + new RegExp(`\\b${numSize}${escapedUnit}\\b`, 'i'), + new RegExp(`\\b${numSize}\\s*g(r|ram)?\\b`, 'i'), + new RegExp(`\\b${numSize}g(r|ram)?\\b`, 'i'), + new RegExp(`\\b${numSize}\\s*m?l\\b`, 'i'), + new RegExp(`\\b${numSize}m?l\\b`, 'i'), + new RegExp(`\\b${numSize}\\s*Tab(let)?s?\\b`, 'i'), + ]; + sizeAlreadyInSubtitle = regexList.some((rgx) => rgx.test(subtitle)); + } + + if (!sizeAlreadyInSubtitle && numSize && numSize > 0) { + const sizeStr = unit ? `${numSize} ${unit}` : `${numSize}`; subtitle = `${subtitle} - ${sizeStr}`; } @@ -236,7 +248,7 @@ export class TorobController { old_price: oldPrice, availability: isInStock ? "instock" : "outofstock", image_link: imageLink, - guarantee: "ضمانت اصالت ۱۰۰٪ کمپانی Canina آلمان و اصالت کالا", + guarantee: "ضمانت اصالت ۱۰۰٪ کالای آلمانی، سلامت فیزیکی و تاریخ مصرف به‌روز", category_name: product.category?.name || product.categorySlug || diff --git a/frontend/application/app/api/torob/products/route.ts b/frontend/application/app/api/torob/products/route.ts index 5669bfb1..af89cb23 100644 --- a/frontend/application/app/api/torob/products/route.ts +++ b/frontend/application/app/api/torob/products/route.ts @@ -105,7 +105,7 @@ function buildTorobProductSpec(product: { const spec: Record = { 'برند': 'کنینا (Canina Pharma Germany)', 'کشور سازنده': 'آلمان', - 'ضمانت': 'اصالت ۱۰۰٪ کالای آلمانی و سلامت فیزیکی', + 'ضمانت': 'اصالت ۱۰۰٪ کالای آلمانی، سلامت فیزیکی و تاریخ انقضای به‌روز', }; const pet = normalizeSuitableFor(product.suitableFor); @@ -169,9 +169,25 @@ export async function GET(request: NextRequest) { const rawEn = (product.nameEn || '').trim(); const numSize = Number(product.packageSize); const unit = (product.unit || '').trim(); - const sizeStr = numSize && numSize > 0 ? (unit ? `${numSize} ${unit}` : `${numSize}`) : ''; let subtitle = rawEn.startsWith('Canina') ? rawEn : `Canina ${rawEn}`.trim(); - if (sizeStr && !subtitle.includes(sizeStr)) { + + let sizeAlreadyInSubtitle = false; + if (numSize && numSize > 0) { + const escapedUnit = unit.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + const regexList = [ + new RegExp(`\\b${numSize}\\s*${escapedUnit}\\b`, 'i'), + new RegExp(`\\b${numSize}${escapedUnit}\\b`, 'i'), + new RegExp(`\\b${numSize}\\s*g(r|ram)?\\b`, 'i'), + new RegExp(`\\b${numSize}g(r|ram)?\\b`, 'i'), + new RegExp(`\\b${numSize}\\s*m?l\\b`, 'i'), + new RegExp(`\\b${numSize}m?l\\b`, 'i'), + new RegExp(`\\b${numSize}\\s*Tab(let)?s?\\b`, 'i'), + ]; + sizeAlreadyInSubtitle = regexList.some((rgx) => rgx.test(subtitle)); + } + + if (!sizeAlreadyInSubtitle && numSize && numSize > 0) { + const sizeStr = unit ? `${numSize} ${unit}` : `${numSize}`; subtitle = `${subtitle} - ${sizeStr}`; } @@ -208,7 +224,7 @@ export async function GET(request: NextRequest) { old_price: oldPrice, availability: isInStock ? 'instock' : 'outofstock', image_link: imageLink, - guarantee: 'ضمانت اصالت ۱۰۰٪ کمپانی Canina آلمان و اصالت کالا', + guarantee: 'ضمانت اصالت ۱۰۰٪ کالای آلمانی، سلامت فیزیکی و تاریخ مصرف به‌روز', category_name: catName || 'مکمل حیوانات خانگی', spec, };