Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sandipklevu/2d8b72da9cd00ff946cbf689eee90213 to your computer and use it in GitHub Desktop.
Save sandipklevu/2d8b72da9cd00ff946cbf689eee90213 to your computer and use it in GitHub Desktop.
Product Information for current product in JS function from BigCommerce
<script type="text/javascript">
var productMediaGalleryImages = [];
{{#each product.images}}
productMediaGalleryImages.push("{{getImageSrcset this (cdn ../theme_settings.default_image_product) 1x=../theme_settings.zoom_size}}");
{{/each}}
var productCustomFields = [];
{{#if product.custom_fields}}
{{#each product.custom_fields}}
productCustomFields.push({ key: "{{name}}", value: {{{json value}}}, encoding:"",});
{{/each}}
{{/if}}
var currentProductInfoFromBigCommercePDP = {
itemId: "{{product.id}}",
itemGroupId: "{{product.id}}",
itemVariantId: "{{product.id}}",
locale: "{{ locale_name }}",
title: {{{JSONstringify product.title}}},
url: "{{product.url}}" ? "{{product.url}}" : window.location.href,
priceMax: "{{#if product.price.price_range.max.with_tax}}{{product.price.price_range.max.with_tax.value}}{{else}}{{product.price.price_range.max.without_tax.value}}{{/if}}",
currency: "{{currency_selector.active_currency_code}}",
description: {{{json (ellipsis (sanitize product.description) 4000) }}},
gtin: "{{product.gtin}}",
mpn: "{{product.mpn}}",
upc: "{{product.upc}}",
weight: "{{product.weight}}",
itemCondition:"{{product.condition}}",
availability:"{{#if product.pre_order}}OUT_OF_STOCK_CONTINUE_SELLING{{else if product.out_of_stock}}OUT_OF_STOCK{{else if product.can_purchase '===' false}}OUT_OF_STOCK{{else}}IN_STOCK{{/if}}",
brand: {{{JSONstringify product.brand.name}}},
sku: "{{product.sku}}",
warranty: {{{JSONstringify product.warranty}}},
priceMin: "{{#if product.price.price_range.min.with_tax}}{{product.price.price_range.min.with_tax.value}}{{else}}{{product.price.price_range.min.without_tax.value}}{{/if}}",
options: [
{{#each product.options}}
{
name: {{{JSONstringify this.display_name}}},
values: [{{#each this.values}}{{{JSONstringify this.label }}}{{#unless @last}},{{/unless}}{{/each}}]
}
{{#unless @last}},{{/unless}}
{{/each}}
],
images: productMediaGalleryImages,
customFields: productCustomFields,
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment