Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bold-common.liquid
{%- comment -%}
--------------------------- WARNING ---------------------------
This file is auto-generated by BOLD and should not be modified.
It may be overwritten and any customizations would be lost.
--------------------------- WARNING ---------------------------
{%- endcomment -%}
<script>
{%- comment -%} common data {%- endcomment -%}
window.BOLD = window.BOLD || {};
window.BOLD.common = window.BOLD.common || {};
window.BOLD.common.Shopify = window.BOLD.common.Shopify || {};
window.BOLD.common.Shopify.shop = {
domain: '{{ shop.domain }}',
permanent_domain: '{{ shop.permanent_domain }}',
url: '{{ shop.url }}',
secure_url: '{{ shop.secure_url }}',
money_format: {{ shop.money_format | json }},
currency: {{ shop.currency | json }}
};
window.BOLD.common.Shopify.cart = {{ cart | json }};
window.BOLD.common.template = '{{ template }}';
{%- comment -%} common functions {%- endcomment -%}
window.BOLD.common.Shopify.formatMoney = function(money, format) {
function n(t, e) {
return "undefined" == typeof t ? e : t
}
function r(t, e, r, i) {
if (e = n(e, 2),
r = n(r, ","),
i = n(i, "."),
isNaN(t) || null == t)
return 0;
t = (t / 100).toFixed(e);
var o = t.split(".")
, a = o[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + r)
, s = o[1] ? i + o[1] : "";
return a + s
}
"string" == typeof money && (money = money.replace(".", ""));
var i = ""
, o = /\{\{\s*(\w+)\s*\}\}/
, a = format || window.BOLD.common.Shopify.shop.money_format || window.Shopify.money_format || "$ {% raw %}{{ amount }}{% endraw %}";
switch (a.match(o)[1]) {
case "amount":
i = r(money, 2);
break;
case "amount_no_decimals":
i = r(money, 0);
break;
case "amount_with_comma_separator":
i = r(money, 2, ".", ",");
break;
case "amount_no_decimals_with_comma_separator":
i = r(money, 0, ".", ",");
break;
case "amount_with_space_separator":
i = r(money, 2, ".", " ");
break;
case "amount_no_decimals_with_space_separator":
i = r(money, 0, ".", " ");
break;
}
return a.replace(o, i);
};
window.BOLD.common.Shopify.saveProduct = function (handle, product) {
if (typeof handle === 'string' && typeof window.BOLD.common.Shopify.products[handle] === 'undefined') {
if (typeof product === 'number') {
window.BOLD.common.Shopify.handles[product] = handle;
product = { id: product };
}
window.BOLD.common.Shopify.products[handle] = product;
}
};
window.BOLD.common.Shopify.saveVariant = function (variant_id, variant) {
if (typeof variant_id === 'number' && typeof window.BOLD.common.Shopify.variants[variant_id] === 'undefined') {
window.BOLD.common.Shopify.variants[variant_id] = variant;
}
};
{%- comment -%} product data {%- endcomment -%}
window.BOLD.common.Shopify.products = window.BOLD.common.Shopify.products || {};
window.BOLD.common.Shopify.variants = window.BOLD.common.Shopify.variants || {};
window.BOLD.common.Shopify.handles = window.BOLD.common.Shopify.handles || {};
{%- if template == 'product' -%}
window.BOLD.common.Shopify.handle = {{ product.handle | json }}
{%- endif -%}
{%- comment -%} product page {%- endcomment -%}
window.BOLD.common.Shopify.saveProduct({{ product.handle | json }}, {{ product.id | json }});
{%- for variant in product.variants -%} window.BOLD.common.Shopify.saveVariant({{ variant.id | json }}, {product_id: {{ product.id | json }}, price: {{ variant.price | json }}, group_id: '{{variant.metafields.bold_rp.rp_group_id}}'}); {%- endfor -%}
{%- comment -%} collection page {%- endcomment -%}
{%- for product in collection.products -%}
window.BOLD.common.Shopify.saveProduct({{ product.handle | json }}, {{ product.id | json }});
{%- for variant in product.variants -%} window.BOLD.common.Shopify.saveVariant({{ variant.id | json }}, {product_id: {{ product.id | json }}, price: {{ variant.price | json }}, group_id: '{{variant.metafields.bold_rp.rp_group_id}}'}); {%- endfor -%}
{%- endfor -%}
{%- comment -%} search page {%- endcomment -%}
{%- for product in search.results -%}
window.BOLD.common.Shopify.saveProduct({{ product.handle | json }}, {{ product.id | json }});
{%- for variant in product.variants -%} window.BOLD.common.Shopify.saveVariant({{ variant.id | json }}, {product_id: {{ product.id | json }}, price: {{ variant.price | json }}, group_id: '{{variant.metafields.bold_rp.rp_group_id}}'}); {%- endfor -%}
{%- endfor -%}
{%- comment -%} metafields {%- endcomment -%}
window.BOLD.common.Shopify.metafields = window.BOLD.common.Shopify.metafields || {};
{%- assign metafield_namespaces_to_load = 'bold_rp' | split: ',' -%}
{%- for namespace in metafield_namespaces_to_load -%}
window.BOLD.common.Shopify.metafields[{{ namespace | json }}] = {{ shop.metafields[namespace] | json }};
{%- endfor -%}
</script>
{{ 'https://ro.boldapps.net/v2_ui/js/ro.js' | script_tag }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.