Skip to content

products global within shopify #438

@reggi

Description

@reggi

Note, this issue is specifically for Shopify's implementation of liquid on their website.

We should be able to do this:

{{ products["austin-leaf-map-poster"].url }}

But we (developers) don't have access to a products global.

Instead of having access to the global. I have to hack something together like this:

function.get_product.liquid

{% assign return = false %}
{% if pass_product_handle and collections["all"] %}
  {% for product in collections["all"].products %}
    {% if pass_product_handle == product.handle %}
      {% assign return = product %}
    {% endif %}
  {% endfor %}
{% endif %}

usage.liquid

{% assign pass_product_handle = "austin-leaf-map-poster" %}
{% include "function.get_product" %}
{% assign product = return %}
{{ product.url }}

{% assign pass_product_handle = "boston-leaf-map-poster" %}
{% include "function.get_product" %}
{% assign product = return %}
{{ product.url }}

It can't be good for Shopify to have to interpret this loop every time I need product information, no?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions