Product Object Bug in Liquid?

This morning I tried to access a product object from section settings and noticed that the output of the object is the product handle, not the product object. For now i have patched it with a workaround but i’m pretty sure this is a bug in liquid. Here is my setup:

Context: Featured product section

Section schema input for product:

{
  “type”: “product”,
  “id”: “product”,
  “label”: “t:sections.featured_product.product”
}

Tried printing it like this:

{{ section.settings.product | json }}

Output:

"product-handle-here"

Expected Output: Product object

{ "id: 111", etc }

Observations:

I have noticed that the product attributes are indeed accessible with liquid so the examples below seem to be accessible

{{ section.settings.product.id }} 
{{ section.settings.product.title }}
etc

Therefore my current workaround is this:

{%  if product == product.handle %}
  {% assign product = all_products[product.handle] %}
{% endif %}

However, i’m pretty sure this is a bug in liquid. Unless i totally miss something. Tried this across multiple themes as well.

Pretty sure you managed to work around the limitation but it’s not a bug, it’s a feature :joy:

3 Likes

Hi @Octavian

I’m not seeing other reports of this - when I add {{ product | json }} I’m seeing the full product object being returned (but it’s not appearing on the rendered page:

is it the same when you attempt to print the product objects from customizer? such as:

{{ section.settings.product | json }}

You will get the same result but you can be crafty like so:

{{ section.settings.product.variants.first.product | json }}

It’s a stretch, but it works ! As long as you can come back to the product reference, you won’t have to deal with the legacy behavior. Hope it helps !

1 Like

oh, i love this approach - clean AF

1 Like

We really do need some sort of mnemonic or some better education/tooling for this and the .value trip up.

I have some things for this kind of oddities, what could be a good domain name for this ?

liquiderror(s), liquidlifeguard?? Not sure that type of naming-is-hard is a name beginners would stumble onto for a question they’d never even know to ask, AND not trigger shopify-partner terms.

liquified if you ask me

1 Like