mirror of
https://github.com/samsonjs/spirit-tracker.git
synced 2026-03-25 09:25:51 +00:00
feat: Better legacy skus
This commit is contained in:
parent
f9769823cd
commit
2c5ee133a1
1 changed files with 15 additions and 2 deletions
|
|
@ -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 };
|
||||
|
|
|
|||
Loading…
Reference in a new issue