← back to Designer Wallcoverings
color cleaner v2: store-agnostic collection resolver — verify hardcoded prod id, else resolve by handle (color/-wallpaper/-wallcovering/-wallcoverings). Fixes sandbox red+pink (prod-only ids 404'd); cream left as deliberate skip (only a combined Beige&Cream collection exists, wrong semantics)
5672b1c447b88f0834ba2c9e55433254513827c6 · 2026-06-12 14:01:49 -0700 · Steve Abrams
Files touched
M DW-Programming/color-collection-cleaner-v2.js
Diff
commit 5672b1c447b88f0834ba2c9e55433254513827c6
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Fri Jun 12 14:01:49 2026 -0700
color cleaner v2: store-agnostic collection resolver — verify hardcoded prod id, else resolve by handle (color/-wallpaper/-wallcovering/-wallcoverings). Fixes sandbox red+pink (prod-only ids 404'd); cream left as deliberate skip (only a combined Beige&Cream collection exists, wrong semantics)
---
DW-Programming/color-collection-cleaner-v2.js | 29 ++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/DW-Programming/color-collection-cleaner-v2.js b/DW-Programming/color-collection-cleaner-v2.js
index 747ef676..8cd4dd5d 100644
--- a/DW-Programming/color-collection-cleaner-v2.js
+++ b/DW-Programming/color-collection-cleaner-v2.js
@@ -141,6 +141,28 @@ async function fetchCollectionProducts(collectionId) {
}
return all;
}
+// Resolve a color's collection id for the CURRENTLY configured store.
+// COLOR_COLLECTIONS holds PROD ids; on another store (e.g. the sandbox) some of
+// those ids 404. Trust the hardcoded id when it resolves; otherwise look the
+// collection up by handle so the same script works on sandbox AND prod. (2026-06-12)
+const _cidCache = {};
+async function resolveCollectionId(color, cfg) {
+ if (_cidCache[color] !== undefined) return _cidCache[color];
+ if (cfg.collectionId) {
+ const r = await shopifyREST('GET', `/collections/${cfg.collectionId}.json?fields=id`);
+ if (r && r.collection && r.collection.id) return (_cidCache[color] = cfg.collectionId);
+ console.log(` [${color}] hardcoded id ${cfg.collectionId} not on this store — resolving by handle…`);
+ }
+ const handles = [color, `${color}-wallpaper`, `${color}-wallcovering`, `${color}-wallcoverings`];
+ for (const h of handles) {
+ for (const type of ['smart_collections', 'custom_collections']) {
+ const r = await shopifyREST('GET', `/${type}.json?handle=${encodeURIComponent(h)}&fields=id,handle,title`);
+ const hit = (r[type] || [])[0];
+ if (hit && hit.id) { console.log(` [${color}] resolved by handle '${h}' -> ${hit.id} (${hit.title})`); return (_cidCache[color] = hit.id); }
+ }
+ }
+ return (_cidCache[color] = null);
+}
const append = (f, o) => fs.appendFileSync(f, JSON.stringify(o) + '\n');
const loadProcessed = (color) => { const f = path.join(STATE_DIR, `${color}.done`); try { return new Set(fs.readFileSync(f, 'utf8').split('\n').filter(Boolean).map(Number)); } catch { return new Set(); } };
const markProcessed = (color, id) => fs.appendFileSync(path.join(STATE_DIR, `${color}.done`), id + '\n');
@@ -148,9 +170,10 @@ const markProcessed = (color, id) => fs.appendFileSync(path.join(STATE_DIR, `${c
async function processColor(color) {
const cfg = COLOR_COLLECTIONS[color];
if (!cfg) { console.log(`unknown color ${color}`); return; }
- if (!cfg.collectionId) { console.log(`[${color}] no collection id — skip`); return; }
- console.log(`\n===== ${color.toUpperCase()} (collection ${cfg.collectionId}) =====`);
- let products = await fetchCollectionProducts(cfg.collectionId);
+ const collectionId = await resolveCollectionId(color, cfg);
+ if (!collectionId) { console.log(`[${color}] no resolvable collection on this store — skip`); return; }
+ console.log(`\n===== ${color.toUpperCase()} (collection ${collectionId}) =====`);
+ let products = await fetchCollectionProducts(collectionId);
const done = loadProcessed(color);
products = products.filter(p => !done.has(p.id));
if (LIMIT) products = products.slice(0, LIMIT);
← 80b183f9 color cleaner v2: disable gemini-2.5-flash thinking budget (
·
back to Designer Wallcoverings
·
add color-clean-report.js — per-color rollup (processed/remo df20fe8c →