[object Object]

← back to Dw Pairs Well

Design Coordinate: loadSource falls back dw_sku -> handle (fix theme MFR-sku-as-dw_sku breakage)

e22bffccf10c169b560fa53dd25353814115fb70 · 2026-06-27 11:04:05 -0700 · Steve Abrams

Files touched

Diff

commit e22bffccf10c169b560fa53dd25353814115fb70
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Sat Jun 27 11:04:05 2026 -0700

    Design Coordinate: loadSource falls back dw_sku -> handle (fix theme MFR-sku-as-dw_sku breakage)
---
 server.js | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/server.js b/server.js
index a139b85..e8be29c 100644
--- a/server.js
+++ b/server.js
@@ -73,29 +73,29 @@ const SOURCE_COLS = `
   sce.dominant_hex, sce.background_hex, sce.hex_codes, sce.color_family
 `;
 
-async function loadSource({ dw_sku, handle }) {
-  let q, params;
-  if (dw_sku) {
-    q = `SELECT ${SOURCE_COLS}
-         FROM shopify_products sp
-         LEFT JOIN shopify_color_enrichment sce ON sce.shopify_id = sp.shopify_id
-         WHERE sp.dw_sku = $1
-         LIMIT 1`;
-    params = [dw_sku];
-  } else if (handle) {
-    q = `SELECT ${SOURCE_COLS}
-         FROM shopify_products sp
-         LEFT JOIN shopify_color_enrichment sce ON sce.shopify_id = sp.shopify_id
-         WHERE sp.handle = $1
-         LIMIT 1`;
-    params = [handle];
-  } else {
-    return null;
-  }
-  const r = await pool.query(q, params);
+async function loadOne(col, val) {
+  const q = `SELECT ${SOURCE_COLS}
+       FROM shopify_products sp
+       LEFT JOIN shopify_color_enrichment sce ON sce.shopify_id = sp.shopify_id
+       WHERE sp.${col} = $1
+       LIMIT 1`;
+  const r = await pool.query(q, [val]);
   return r.rows[0] || null;
 }
 
+// Resolve the source product. 2026-06-27 (vp-dw-commerce): the DW theme passes
+// data-product-sku = custom.manufacturer_sku as ?dw_sku=, which never matches
+// shopify_products.dw_sku (a DWxx key) — so a wrong dw_sku used to short-circuit
+// (else-if) the handle path and return "source not found", breaking the whole
+// Design-Coordinate panel. Fix: TRY dw_sku, and if it doesn't resolve, FALL BACK
+// to handle. A bad sku can no longer block a good handle.
+async function loadSource({ dw_sku, handle }) {
+  let src = null;
+  if (dw_sku) src = await loadOne('dw_sku', dw_sku);
+  if (!src && handle) src = await loadOne('handle', handle);
+  return src;
+}
+
 // "Coordinate" patterns in the interior-design sense — what a designer uses to
 // COORDINATE a hero pattern. Stripes/plaids/checks/tartans/gingham/ticking only.
 // Florals coordinate against florals visually compete; stripes never do.

← 13c4dfe auto-save: 2026-06-26T13:03:32 (3 files) — tools/ci-hash-bui  ·  back to Dw Pairs Well  ·  auto-save: 2026-07-07T08:56:34 (1 files) — tools/pattern-id- d53de9e →