From e341489d6ea7465037541c17caf745497902e324 Mon Sep 17 00:00:00 2001 From: M_Kececi Date: Fri, 13 Mar 2026 14:40:48 +0300 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- svc/routes/product_images.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/svc/routes/product_images.go b/svc/routes/product_images.go index a45b8dd..1348ec0 100644 --- a/svc/routes/product_images.go +++ b/svc/routes/product_images.go @@ -150,9 +150,16 @@ WHERE b.typ = 'img' AND ( -- 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,''), '^.*-', ''), ' ', '')) + -- core-code fallback only when there is no exact item code for the input + OR ( + NOT EXISTS ( + SELECT 1 + FROM mmitem ix + WHERE UPPER(REPLACE(COALESCE(ix.code,''), ' ', '')) = UPPER(REPLACE(COALESCE($1,''), ' ', '')) + ) + AND UPPER(REPLACE(REGEXP_REPLACE(COALESCE(i.code,''), '^.*-', ''), ' ', '')) = + UPPER(REPLACE(REGEXP_REPLACE(COALESCE($1,''), '^.*-', ''), ' ', '')) + ) ) ORDER BY COALESCE(b.sort_order,999999),