diff --git a/svc/queries/product_pricing_fx_publish.go b/svc/queries/product_pricing_fx_publish.go index 67be7f2..0217fa1 100644 --- a/svc/queries/product_pricing_fx_publish.go +++ b/svc/queries/product_pricing_fx_publish.go @@ -264,8 +264,8 @@ norm AS ( norm.product_code AS product_code, md.val1::bigint AS dim1, CASE - WHEN md.val2 IS NULL OR md.val2 = 0 THEN NULL - ELSE md.val2::bigint + WHEN md.val3 IS NULL OR md.val3 = 0 THEN NULL + ELSE md.val3::bigint END AS dim3 FROM norm JOIN mmitem mm diff --git a/svc/routes/product_pricing_save.go b/svc/routes/product_pricing_save.go index 496021a..5d09ed8 100644 --- a/svc/routes/product_pricing_save.go +++ b/svc/routes/product_pricing_save.go @@ -591,9 +591,10 @@ DO UPDATE SET dim_id = EXCLUDED.dim_id, updated_at = EXCLUDED.updated_at if err := rows.Scan(&colorCode, &dim1Code, &dim3Code); err != nil { return nil, err } - // Resolve to PG dim ids. For this installation we align with PG's authoritative mmitem_dim model: - // - dim1 corresponds to mmitem_dim.val1 (typically Color). - // - dim3 corresponds to mmitem_dim.val2 (typically Size). + // Resolve to PG dim ids. For this installation we align with mmitem_dim key: + // - dim1 = color + // - dim3 = itemdim3 (optional) + // Size (ItemDim1Code) is not part of the key here. d1 := int64(0) if id, ok := resolveDimvalFromToken(pgTx, "dimval1", colorCode); ok { d1 = id @@ -609,11 +610,8 @@ DO UPDATE SET dim_id = EXCLUDED.dim_id, updated_at = EXCLUDED.updated_at continue } var d3 sql.NullInt64 - // dim3 corresponds to mmitem_dim.val2 (usually ItemDim1Code). - if id, ok := resolveDimvalFromToken(pgTx, "dimval1", dim1Code); ok { - d3 = sql.NullInt64{Int64: id, Valid: true} - resolvedDim3++ - } else if id, ok := resolveDimvalFromToken(pgTx, "dimval1", dim3Code); ok { + // dim3 corresponds to mmitem_dim.val3 (ItemDim3Code). + if id, ok := resolveDimvalFromToken(pgTx, "dimval1", dim3Code); ok { d3 = sql.NullInt64{Int64: id, Valid: true} resolvedDim3++ } @@ -720,15 +718,14 @@ WHERE mmitem_id = $1 if !v1.Valid || v1.Int64 <= 0 { continue } + // Variant key in this installation: (val1=color, val3=itemdim3_if_any). Ignore val2 (size). d1 := v1.Int64 + _ = mmdimID + _ = v2 var d3 sql.NullInt64 - // In production data we've observed the variant key as (val1, val2). val3 may exist but is not - // used as the second axis for pricing/campaign matching in this app. - _ = mmdimID - _ = v3 - if v2.Valid && v2.Int64 > 0 { - d3 = sql.NullInt64{Int64: v2.Int64, Valid: true} + if v3.Valid && v3.Int64 > 0 { + d3 = sql.NullInt64{Int64: v3.Int64, Valid: true} } key := fmt.Sprintf("%d|%d", d1, func() int64 { diff --git a/svc/routes/wholesale_campaigns.go b/svc/routes/wholesale_campaigns.go index 19670a6..8e8dc0f 100644 --- a/svc/routes/wholesale_campaigns.go +++ b/svc/routes/wholesale_campaigns.go @@ -772,14 +772,13 @@ WHERE mmitem_id = ANY($1::bigint[]) if !v1.Valid || v1.Int64 <= 0 { continue } + // Variant key in this installation: (val1=color, val3=itemdim3_if_any). Ignore val2 (size). d1 := v1.Int64 - - d3k := int64(0) - // Variant key in this app is (val1, val2). val3 may exist but is not the second axis for matching. _ = mmdimID - _ = v3 - if v2.Valid && v2.Int64 > 0 { - d3k = v2.Int64 + _ = v2 + d3k := int64(0) + if v3.Valid && v3.Int64 > 0 { + d3k = v3.Int64 } code := strings.TrimSpace(itemToCode[itemID]) @@ -886,7 +885,7 @@ ORDER BY dim_id, updated_at DESC; } // Map Nebim tokens to PG integer ids (dimval1 namespace). - // This app uses key: dim1=, dim3= to match mmitem_dim (val1,val2). + // This app uses key: dim1=, dim3= to match mmitem_dim (val1,val3). d1 := int64(0) if id, ok := resolveDimID("dimval1", colorCode); ok { d1 = id @@ -895,7 +894,7 @@ ORDER BY dim_id, updated_at DESC; continue } d3k := int64(0) - if id, ok := resolveDimID("dimval1", dim1Code); ok { + if id, ok := resolveDimID("dimval1", dim3Code); ok { d3k = id } key := fmt.Sprintf("%d|%d|%d", itemID, d1, d3k)