From 643bcdf030ddaa5f37e75d04244cc8d61d18457c Mon Sep 17 00:00:00 2001 From: "Brennan Wilkes (Text Groove)" Date: Thu, 29 Jan 2026 10:00:04 -0800 Subject: [PATCH] feat: Better synth sku production --- src/utils/sku.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/utils/sku.js b/src/utils/sku.js index 9d488f8..5b8d3f9 100644 --- a/src/utils/sku.js +++ b/src/utils/sku.js @@ -16,9 +16,35 @@ function fnv1a32(str) { } function makeSyntheticSkuKey({ storeLabel, url }) { - const store = String(storeLabel || "store"); - const u = String(url || ""); + const store = String(storeLabel || "store").trim().toLowerCase(); + let u = String(url || "").trim(); if (!u) return ""; + + // Normalize common "same product, different slug" cases. + // This is intentionally conservative and forward-only: it only changes the + // *synthetic* ID when we otherwise have no real SKU. + try { + const U = new URL(u); + // drop query/hash + U.search = ""; + U.hash = ""; + + // normalize path + let p = U.pathname || ""; + + // Common pattern: /product/preorder-/ becomes /product// + p = p.replace(/\/product\/preorder-([a-z0-9-]+)\/?$/i, "/product/$1/"); + + // also normalize trailing slash + if (!p.endsWith("/")) p += "/"; + + U.pathname = p; + u = U.toString(); + } catch { + // If URL() parsing fails, do a minimal string normalize. + u = u.replace(/\/product\/preorder-([a-z0-9-]+)\/?$/i, "/product/$1/"); + } + return `u:${fnv1a32(`${store}|${u}`)}`; }