From 2c5ee133a1c32131ceb63675c0dc3137f3e1b984 Mon Sep 17 00:00:00 2001 From: "Brennan Wilkes (Text Groove)" Date: Sat, 31 Jan 2026 16:33:12 -0800 Subject: [PATCH] feat: Better legacy skus --- src/stores/legacyliquor.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/stores/legacyliquor.js b/src/stores/legacyliquor.js index db57a89..d424e80 100644 --- a/src/stores/legacyliquor.js +++ b/src/stores/legacyliquor.js @@ -1,6 +1,6 @@ "use strict"; -const { normalizeCspc } = require("../utils/sku"); +const { normalizeCspc, normalizeSkuKey } = require("../utils/sku"); const { humanBytes } = require("../utils/bytes"); const { padLeft, padRight } = require("../utils/string"); @@ -12,6 +12,19 @@ function kbStr(bytes) { return humanBytes(bytes).padStart(8, " "); } +function normalizeLegacySku(rawSku, { storeLabel, url }) { + const raw = String(rawSku ?? "").trim(); + if (!raw) return ""; + + const cspc = normalizeCspc(raw); + if (cspc) return cspc; + + const m = raw.match(/\b(\d{1,11})\b/); + if (m && m[1]) return `id:${m[1]}`; + + return normalizeSkuKey(raw, { storeLabel, url }); +} + function secStr(ms) { const s = Number.isFinite(ms) ? ms / 1000 : 0; const tenths = Math.round(s * 10) / 10; @@ -158,7 +171,7 @@ function legacyProductToItem(p, ctx) { cad(p?.priceTo) || ""; - const sku = normalizeCspc(v?.sku || "") || normalizeCspc(url) || ""; + const sku = normalizeLegacySku(v?.sku, { storeLabel: ctx.store.name, url }) || normalizeLegacySku(url, { storeLabel: ctx.store.name, url }) ||""; const img = normalizeAbsUrl(v?.image || ""); return { name, price, url, sku, img };