From 706f530315f8bf4cf5b68c25ffde8ae4a6df767a Mon Sep 17 00:00:00 2001 From: M_Kececi Date: Fri, 13 Mar 2026 14:34:46 +0300 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- svc/routes/product_images.go | 49 +++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/svc/routes/product_images.go b/svc/routes/product_images.go index 07c7d06..a45b8dd 100644 --- a/svc/routes/product_images.go +++ b/svc/routes/product_images.go @@ -38,6 +38,32 @@ func tokenizeImageFileName(fileName string) []string { }) } +func isAllDigits(s string) bool { + if s == "" { + return false + } + for _, r := range s { + if r < '0' || r > '9' { + return false + } + } + return true +} + +func imageFileHasDim3Pattern(fileName string) bool { + tokens := tokenizeImageFileName(fileName) + for _, t := range tokens { + parts := strings.SplitN(t, "_", 2) + if len(parts) != 2 { + continue + } + if len(parts[0]) == 3 && isAllDigits(parts[0]) && isAllDigits(parts[1]) { + return true + } + } + return false +} + func imageFileMatches(fileName, dim1, dim3 string) bool { dim1 = strings.ToUpper(strings.TrimSpace(dim1)) dim3 = strings.ToUpper(strings.TrimSpace(dim3)) @@ -122,9 +148,11 @@ JOIN mmitem i WHERE b.typ = 'img' AND b.src_table = 'mmitem' AND ( - UPPER(i.code) = UPPER($1) - OR UPPER(i.code) = UPPER('S001-' || $1) - OR UPPER(i.code) LIKE '%-' || UPPER($1) + -- exact code match (spaces ignored) + UPPER(REPLACE(COALESCE(i.code,''), ' ', '')) = UPPER(REPLACE(COALESCE($1,''), ' ', '')) + -- or exact core-code match after last '-' (e.g. S901-DMY18252 -> DMY18252) + OR UPPER(REPLACE(REGEXP_REPLACE(COALESCE(i.code,''), '^.*-', ''), ' ', '')) = + UPPER(REPLACE(REGEXP_REPLACE(COALESCE($1,''), '^.*-', ''), ' ', '')) ) ORDER BY COALESCE(b.sort_order,999999), @@ -204,6 +232,21 @@ ORDER BY } else if dim3 == "" && len(matchedByNameDim1Only) > 0 { // Sadece 1. renk filtreleniyorsa dim1-only fallback kabul. items = matchedByNameDim1Only + } else if dim3 != "" && len(matchedByNameDim1Only) > 0 { + // dim3 verilmis ama kayitlar eski tek-renk adlandirma kullaniyor olabilir. + // Eger dosya adlarinda "001_1" gibi ikinci renk pattern'i yoksa dim1-only fallback kabul. + hasDim3Pattern := false + for _, it := range matchedByNameDim1Only { + if imageFileHasDim3Pattern(it.FileName) { + hasDim3Pattern = true + break + } + } + if !hasDim3Pattern { + items = matchedByNameDim1Only + } else { + items = []ProductImageItem{} + } } else { // dim3 (2. renk) verildiyse yanlis varyanta dusmemek icin bos don. items = []ProductImageItem{}