Created
December 14, 2018 16:59
-
-
Save cbodtorf/b8584a9170395131137e86f895f32f28 to your computer and use it in GitHub Desktop.
Liquid to JS Shopify Product Dump for Vue Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var products = [] | |
{% for product in collections.all.products %} | |
var product = {{ product | json }}; | |
{% assign tags = product.tags | join: "," %} | |
{% if product.metafields.subscriptions != blank %} | |
product["subscription_product_id"] = {{ product.metafields.subscriptions.discount_product_id }}; | |
product["subscription"] = {% if tags contains "Portal Subscription" %}true{% else %}false{% endif %} | |
product["onetime"] = {% if tags contains "Portal One Time" %}true{% else %}false{% endif %} | |
{% else %} | |
product["onetime"] = false | |
product["subscription"] = false | |
{% endif %} | |
product['metafields'] = {{ product.metafields.sf_product_details | json }}; | |
product['subscription_metafields'] = {{ product.metafields.subscriptions | json }}; | |
product['product_details'] = {{ product.metafields.sf_product_details | json }}; | |
{% for variant in product.variants %} | |
{% assign vloop = forloop %} | |
product['variants'][{{ vloop.index0 }}]['subscription_metafields'] = {{ variant.metafields.subscriptions | json }}; | |
{% if variant.metafields.subscriptions != blank %} | |
product['variants'][{{ vloop.index0 }}]["subscription_variant_id"] = {{ variant.metafields.subscriptions.discount_variant_id }}; | |
product['variants'][{{ vloop.index0 }}]["subscription_variant_price"] = {{ variant.metafields.subscriptions.discount_variant_price }}; | |
{% endif %} | |
{% endfor %} | |
products.push(product); | |
{% endfor %} | |
window._vueproducts = products | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment