[object Object]

← back to Designer Wallcoverings

pattern page: self-heal colorway images from live product.js

67c25a46784e03f3a0941e17ef555aad717c0977 · 2026-06-26 07:44:01 -0700 · Steve

Files touched

Diff

commit 67c25a46784e03f3a0941e17ef555aad717c0977
Author: Steve <steve@designerwallcoverings.com>
Date:   Fri Jun 26 07:44:01 2026 -0700

    pattern page: self-heal colorway images from live product.js
---
 shopify/_cwGRID/sections/pattern-page.liquid | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/shopify/_cwGRID/sections/pattern-page.liquid b/shopify/_cwGRID/sections/pattern-page.liquid
index 8f11c31a..df2bac94 100644
--- a/shopify/_cwGRID/sections/pattern-page.liquid
+++ b/shopify/_cwGRID/sections/pattern-page.liquid
@@ -102,6 +102,22 @@
 
   function skel(n) { var h=''; for (var i=0;i<n;i++) h+='<div class="dw-pattern__skel"></div>'; grid.innerHTML=h; }
 
+  // Self-heal stale/missing colorway images from the LIVE Shopify product.
+  function fixImg(img) {
+    if (!img || img.dataset.fb) { if (img) img.classList.add('dw-pattern__img--gone'); return; }
+    img.dataset.fb = '1';
+    var h = img.getAttribute('data-handle');
+    if (!h) { img.classList.add('dw-pattern__img--gone'); return; }
+    fetch('/products/' + encodeURIComponent(h) + '.js', { credentials: 'omit' })
+      .then(function (r) { return r.ok ? r.json() : Promise.reject(); })
+      .then(function (p) { var s = p.featured_image || (p.images && p.images[0]); if (s) img.src = (s.indexOf('//')===0?'https:':'') + s; else img.classList.add('dw-pattern__img--gone'); })
+      .catch(function () { img.classList.add('dw-pattern__img--gone'); });
+  }
+  grid.addEventListener('error', function (e) {
+    var t = e.target; if (t && t.classList && t.classList.contains('dw-pattern__img')) fixImg(t);
+  }, true);
+  function healEmpty() { grid.querySelectorAll('.dw-pattern__img').forEach(function (img) { if (!img.getAttribute('src')) fixImg(img); }); }
+
   function card(c) {
     var img = c.image_url ? esc(c.image_url) : '';
     var dot = c.color_hex ? '<span class="dw-pattern__dot" style="background:' + esc(c.color_hex) + '"></span>' : '';
@@ -136,6 +152,7 @@
       document.title = (d.pattern || 'Pattern') + ' — ' + (cw.length) + ' Colorways · Designer Wallcoverings';
       subE.textContent = (d.vendor ? d.vendor + ' · ' : '') + cw.length + (cw.length === 1 ? ' Colorway' : ' Colorways');
       grid.innerHTML = cw.length ? cw.map(card).join('') : '<div class="dw-pattern__empty">No colorways found for this pattern.</div>';
+      healEmpty();
 
       // Seed the WS-4 Similar Designs section from the representative colorway,
       // then dispatch a custom event the similar-designs IIFE can pick up. The

← 24ecdb0b auto-save: 2026-06-26T07:43:29 (9 files) — package-lock.json  ·  back to Designer Wallcoverings  ·  China Seas image-corruption repair: authoritative re-scrape 003b6f72 →