Skip to content

Instantly share code, notes, and snippets.

@willbroderick
Last active November 13, 2017 15:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save willbroderick/d8d19b008265bd6d42b4061eae081fc6 to your computer and use it in GitHub Desktop.
Replacement for {{ product | json }} with accurate inventory information removed
{% comment %}## Add this snippet, then replace {{ product | json }} with {% include 'product-json' %} ##{% endcomment %}
{% capture product_json %}{{ product | json }}{% endcapture %}
{% assign product_json_split = product_json | split: '"inventory_quantity":' %}
{%- for str in product_json_split -%}
{%- if forloop.first -%}{{ str }}
{%- else -%}
"inventory_quantity":
{%- assign str_split = str | split: ',' -%}
{%- for str2 in str_split -%}
{%- unless forloop.first -%},{%- endunless -%}
{%- if forloop.first -%}
{%- assign str2_int = str2 | plus: 0 -%}
{%- if str2_int > 0 -%}999999{% elsif str2_int < 0 %}-1{% else %}{{ str2 }}{%- endif -%}
{%- else -%}
{{- str2 -}}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment