[object Object]

← back to Sister Parish Onboarding

sp: private_label v2 — add display_variant tag + dwc.mfr_number + sample-variant check

2c68b152a7d9c60c55ee52d3a8c7d06fe6329bf0 · 2026-05-18 09:59:06 -0700 · SteveStudio2

Files touched

Diff

commit 2c68b152a7d9c60c55ee52d3a8c7d06fe6329bf0
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date:   Mon May 18 09:59:06 2026 -0700

    sp: private_label v2 — add display_variant tag + dwc.mfr_number + sample-variant check
---
 scripts/private_label.js | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/scripts/private_label.js b/scripts/private_label.js
index 92a7cb8..afb1964 100644
--- a/scripts/private_label.js
+++ b/scripts/private_label.js
@@ -3,11 +3,13 @@
  * Private-label the Sister Parish line on the DW sandbox.
  *  1. De-dupe: group live SP products by title, keep the richest row
  *     (most images, tie-break lowest id), DELETE the rest.
- *  2. Renumber: sorted by title, assign flat DWSH-10001..DWSH-100NN.
- *     roll variant  -> DWSH-100NN
- *     sample variant-> DWSH-100NN-S   (detected via /samp/i in old SKU)
- *  3. Tag each kept product with dwc.series = "Saybrook House" +
- *     dwc.series_code = "DWSH" metafields (the private-label DW collection).
+ *  2. Renumber: sorted by title, assign flat DWPH-10001..DWPH-100NN.
+ *     roll variant  -> DWPH-100NN
+ *     sample variant-> DWPH-100NN-S   (detected via /samp/i in old SKU)
+ *  3. Tag each kept product: add product tag `display_variant`; add metafields
+ *     dwc.series="Saybrook House", dwc.series_code="DWPH", and
+ *     dwc.mfr_number="SISTERPARISH-<vendor sku>" (internal reorder reference,
+ *     NOT front-facing). Warn on any product missing a sample variant.
  *  4. Write output/sku_map.json (old vendor SKU -> new DW SKU, recoverable).
  *
  * --plan  : print the dedupe + renumber plan, change nothing.
@@ -23,7 +25,7 @@ if (!SHOP || !TOKEN) { console.error('Need SHOPIFY_STORE + SHOPIFY_ADMIN_TOKEN')
 const BASE = `https://${SHOP}/admin/api/2026-01`;
 const RATE_DELAY_MS = 350;
 const SERIES = 'Saybrook House';
-const SERIES_CODE = 'DWSH';
+const SERIES_CODE = 'DWPH';
 const START = 10001;
 const PLAN = process.argv.includes('--plan');
 const sleep = ms => new Promise(r => setTimeout(r, ms));
@@ -73,6 +75,8 @@ const isSample = v => /samp/i.test(v.sku || '') || /sample/i.test(v.option3 || '
   console.log(`Unique titles: ${keepers.length}   Duplicates to delete: ${deletes.length}`);
 
   // ---- build renumber plan ----
+  const VENDOR_TOKEN = 'SISTERPARISH';
+  const recoverMfr = sku => (sku || '').replace(/^DWSP-/i, '').replace(/^SAMP[ -]+/i, '').trim();
   const map = [];
   keepers.forEach((p, i) => {
     const base = `${SERIES_CODE}-${START + i}`;
@@ -81,15 +85,25 @@ const isSample = v => /samp/i.test(v.sku || '') || /sample/i.test(v.option3 || '
     const vmap = [];
     rolls.forEach((v, j) => vmap.push({ id: v.id, old: v.sku, new: j === 0 ? base : `${base}-R${j+1}` }));
     samples.forEach((v, j) => vmap.push({ id: v.id, old: v.sku, new: j === 0 ? `${base}-S` : `${base}-S${j+1}` }));
-    map.push({ product_id: p.id, title: p.title, dw_base: base, variants: vmap });
+    const vendorSku = recoverMfr((rolls[0] || p.variants[0] || {}).sku);
+    const tags = [...new Set([...(p.tags || '').split(',').map(s => s.trim()).filter(Boolean), 'display_variant'])].join(', ');
+    map.push({
+      product_id: p.id, title: p.title, dw_base: base, variants: vmap, tags,
+      mfr_number: `${VENDOR_TOKEN}-${vendorSku}`, has_sample: samples.length > 0,
+    });
   });
+  const missingSample = map.filter(m => !m.has_sample);
+  if (missingSample.length) {
+    console.log(`\n⚠ ${missingSample.length} product(s) have NO sample variant — fix manually:`);
+    missingSample.forEach(m => console.log(`   ${m.title}`));
+  }
 
   if (PLAN) {
     console.log('\n--- DELETE ---');
     deletes.forEach(p => console.log(`  ✗ #${p.id}  ${p.title}`));
     console.log('\n--- RENUMBER ---');
     map.forEach(m => {
-      console.log(`  ${m.dw_base}  ${m.title}`);
+      console.log(`  ${m.dw_base}  ${m.title}   [mfr: ${m.mfr_number}]`);
       m.variants.forEach(v => console.log(`     ${v.old}  ->  ${v.new}`));
     });
     return;
@@ -113,10 +127,12 @@ const isSample = v => /samp/i.test(v.sku || '') || /sample/i.test(v.option3 || '
       await shopify('PUT', `/products/${m.product_id}.json`, {
         product: {
           id: m.product_id,
+          tags: m.tags,
           variants: m.variants.map(v => ({ id: v.id, sku: v.new })),
           metafields: [
             { namespace: 'dwc', key: 'series', type: 'single_line_text_field', value: SERIES },
             { namespace: 'dwc', key: 'series_code', type: 'single_line_text_field', value: SERIES_CODE },
+            { namespace: 'dwc', key: 'mfr_number', type: 'single_line_text_field', value: m.mfr_number },
           ],
         },
       });

← 386a360 sp: private_label.js — dedupe + renumber to DWSH-10001 serie  ·  back to Sister Parish Onboarding  ·  sp: enrich_metafields.js — push DW spec metafields (item_wid c283bfa →