[object Object]

← back to Designer Wallcoverings

Harden backfill-to-catalog extractFromMetafields: unwrap {type,value} at the true origin so catalog spec columns never store the blob

98eea4a66527e5d1f495113cfe8b77442c80c34b · 2026-06-24 16:29:59 -0700 · Steve Abrams

Files touched

Diff

commit 98eea4a66527e5d1f495113cfe8b77442c80c34b
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Wed Jun 24 16:29:59 2026 -0700

    Harden backfill-to-catalog extractFromMetafields: unwrap {type,value} at the true origin so catalog spec columns never store the blob
---
 .../vendor-command-center/backfill-to-catalog.js   | 29 ++++++++++++++++++----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/DW-Agents/vendor-command-center/backfill-to-catalog.js b/DW-Agents/vendor-command-center/backfill-to-catalog.js
index 8a4194cd..94070706 100644
--- a/DW-Agents/vendor-command-center/backfill-to-catalog.js
+++ b/DW-Agents/vendor-command-center/backfill-to-catalog.js
@@ -84,6 +84,25 @@ function getVendorId(shopifyVendor) {
   return VENDOR_MAP[shopifyVendor] || shopifyVendor.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/-+$/, '');
 }
 
+// Defensive unwrap for double-encoded metafield values. A metafields export can
+// carry values shaped as the whole Shopify metafield object —
+// {"type":"single_line_text_field","value":"X"} — either as a nested object or its
+// JSON string. Storing that raw into a text spec column is the ORIGIN of the
+// {type,value} blob that later leaks onto the PDP. Return the inner value here so
+// the catalog columns (material/fire_rating/etc) never hold the blob. (2026-06-24.)
+function mfVal(v) {
+  if (v && typeof v === 'object' && typeof v.value === 'string') return v.value;
+  if (typeof v !== 'string') return v;
+  const s = v.trim();
+  if (s.startsWith('{') && s.includes('"value"')) {
+    try {
+      const o = JSON.parse(s);
+      if (o && typeof o.value === 'string') return o.value;
+    } catch (_) { /* not JSON — fall through */ }
+  }
+  return v;
+}
+
 function extractFromMetafields(metafields) {
   if (!metafields || typeof metafields !== 'object') return {};
   const specs = {};
@@ -101,11 +120,11 @@ function extractFromMetafields(metafields) {
     if (num > 0) specs.repeat_vertical_in = num;
   }
 
-  specs.material = metafields['custom.material'] || metafields['specs.material'] || null;
-  specs.fire_rating = metafields['custom.fire_rating'] || metafields['specs.fire_rating'] || null;
-  specs.pattern_name = metafields['custom.pattern_name'] || null;
-  specs.color = metafields['custom.color'] || metafields['dwc.color'] || null;
-  specs.collection = metafields['custom.collection_name'] || null;
+  specs.material = mfVal(metafields['custom.material'] || metafields['specs.material'] || null);
+  specs.fire_rating = mfVal(metafields['custom.fire_rating'] || metafields['specs.fire_rating'] || null);
+  specs.pattern_name = mfVal(metafields['custom.pattern_name'] || null);
+  specs.color = mfVal(metafields['custom.color'] || metafields['dwc.color'] || null);
+  specs.collection = mfVal(metafields['custom.collection_name'] || null);
 
   return specs;
 }

← 1d619822 China Seas mailer: move Shop-by-Theme band to bottom on whit  ·  back to Designer Wallcoverings  ·  Guard cadence-import against {type,value} blob: unwrap row.m ef5c99cb →