← back to Newmor Onboard

data/live-2026-09-09/theme/snippets/hide-browse-hidden.liquid

71 lines

{% comment %}
  Suppress showroom-only vendors from ALL browse/search grids. TK-11186.

  DATA-DRIVEN — no vendor name is hardcoded in logic. The showroom-vendor list is
  sourced (in priority order) from:
    1. shop metafield  custom.showroom_vendors   (comma-separated; store-wide, all themes)
    2. theme setting   settings.showroom_vendors  (comma-separated)
    3. a canonical fallback snapshot of ~/Projects/fix-live-board/config/showroom-vendors.json
       (last resort so suppression never silently fails if 1+2 are unset).
  Canonical source of truth = showroom-vendors.json. Set the shop metafield to that
  file's contents (metafield-update skill) and this snippet follows it automatically.

  Two layers:
    (a) RENDER-TIME: product-list-item.liquid emits NO card HTML for a showroom vendor
        (the real fix — no SEO-crawlable markup, no flash). This snippet's CSS also
        hides any card that carries data-vendor at paint time (before JS).
    (b) BACKSTOP: a JS observer catches Boost AJAX-rendered grids that bypass Liquid,
        reading the SAME injected list (case-insensitive). Kept minimal.
{% endcomment %}
{%- liquid
  assign showroom_raw = shop.metafields.custom.showroom_vendors
  if showroom_raw == blank
    assign showroom_raw = settings.showroom_vendors
  endif
  if showroom_raw == blank
    assign showroom_raw = 'Phillip Jeffries'
  endif
  assign showroom_vendors = showroom_raw | split: ','
-%}
<style>
{%- for v in showroom_vendors -%}
{%- assign vt = v | strip -%}
{%- if vt != blank -%}
[data-vendor="{{ vt | escape }}"]{display:none!important;}
{%- endif -%}
{%- endfor -%}
/* TK-11307: product-level 'Showroom' tag hook — a shared-vendor showroom line (MDC under
   'Phillipe Romano') carries this attr/class without exposing a hideable vendor name. */
[data-showroom="true"],.pr-showroom-hidden{display:none!important;}
</style>
<script>
(function(){
  var HIDDEN = [{%- for v in showroom_vendors -%}{%- assign vt = v | strip -%}{%- if vt != blank -%}{{ vt | json }}{%- unless forloop.last -%},{%- endunless -%}{%- endif -%}{%- endfor -%}].map(function(s){return String(s).trim().toLowerCase();});
  if (!HIDDEN.length) return;
  var CARD_SEL = '.product-list-item, .boost-sd__product-item, [class*="product-item"], [class*="product-card"], article, .boost-sd__product';
  function isHidden(text){ text = (text||'').trim().toLowerCase(); for (var i=0;i<HIDDEN.length;i++){ if (text.indexOf(HIDDEN[i]) > -1) return true; } return false; }
  function hideProducts(){
    document.querySelectorAll('.product-vendor, .product-list-item-vendor, [class*="vendor"]').forEach(function(el){
      if (isHidden(el.textContent)){ var c = el.closest(CARD_SEL); if (c && c.style.display !== 'none') c.style.display = 'none'; }
    });
    document.querySelectorAll('.product-list-item-title a, .boost-sd__product-title a, [class*="product-title"] a, h2 a, h3 a').forEach(function(el){
      if (isHidden(el.textContent)){ var c = el.closest(CARD_SEL); if (c && c.style.display !== 'none') c.style.display = 'none'; }
    });
    document.querySelectorAll('[data-vendor]').forEach(function(el){
      if (HIDDEN.indexOf(String(el.getAttribute('data-vendor')||'').trim().toLowerCase()) > -1){ el.style.display = 'none'; }
    });
    // TK-11307: hide any card whose product tags include 'Showroom' (shared-vendor path).
    // Covers Boost/AJAX grids where the card exposes tags via a data-tags attribute.
    document.querySelectorAll('[data-tags]').forEach(function(el){
      if (String(el.getAttribute('data-tags')||'').toLowerCase().split(/[,\s]+/).indexOf('showroom') > -1){
        var c = el.closest(CARD_SEL) || el; if (c && c.style.display !== 'none') c.style.display = 'none';
      }
    });
  }
  hideProducts();
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', hideProducts);
  setInterval(hideProducts, 2000);
  if (document.body){ new MutationObserver(function(){ setTimeout(hideProducts, 100); }).observe(document.body, { childList:true, subtree:true }); }
})();
</script>