← back to Dw Theme Compact Toolbar

snippets/full-monte-express.liquid

31 lines

{% comment %}
  Full Monte Express — Triggers real-time enrichment on product page load
  Checks if color_details exists, if not, fires enrichment API
  Customer sees color dots on next page load (~3 sec background process)
{% endcomment %}

{% if product %}
{% assign has_colors = product.metafields.custom.color_details %}
{% assign has_hex = product.metafields.custom.color_hex %}
{% assign has_mfr = product.metafields.custom.manufacturer_sku %}
{% assign has_width = product.metafields.specs.width %}

{% if has_colors == blank or has_hex == blank or has_mfr == blank %}
<script>
(function(){
  var img = '{{ product.featured_image | image_url: width: 800 }}';
  if (!img.startsWith('http')) img = 'https:' + img;
  fetch('https://grassclothwallpaper.com/dw-api/enrich', {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify({
      product_id: {{ product.id }},
      handle: '{{ product.handle }}',
      image_url: img
    })
  }).catch(function(){});
})();
</script>
{% endif %}
{% endif %}