{{ section.settings.product | json }} not returning product JSON

tobynicholas
Visitor
2 0 0

Seeing a weird issue with the Dawn theme, in its 'featured product' section where section.settings.product is of type "product", though I assume it's not limited to Dawn:

 

{%- assign product = section.settings.product -%}

{{ product.id }} -> 7071671615682

{{ product | json }} -> "my-product"

{{ all_products[product.handle] | json }} -> {"id":7071671615682,"title":"My product","handle":"my-product","description":"A picture is worth a thousand words  [snip]

 

Not sure what's going on here --  {{ product | json }} always used to work when `product` is a ProductDrop, as per the docs. Any thoughts, anyone?!

Replies 3 (3)

LitCommerce
Astronaut
2860 684 732

Hi @tobynicholas,

{%- assign product = section.settings.product -%}
This is only to get the variable in the file section. It will display the product's handle.

If you want to use it as an object, you need to set it as:
{%- assign product = all_products[section.settings.product] -%}

Hope it is clear to you.

If my answer can help you solve your issue, please mark it as a solution. Thank you and good luck.

LitCommerce - The Most Simple & Affordable Multi-channel Selling Tool.
Effortlessly sell on biggest marketplaces like Amazon, Etsy, eBay, Facebook etc with bulk listing tool, real-time sync & smart order management. Use LitCommerce free for 1-year now!
tobynicholas
Visitor
2 0 0

@LitCommerce Thanks for the reply!

I'm not sure that's correct though; the docs say that a product type setting should return a product object rather than a handle (except for in some legacy cases). Indeed section.settings.product.id and section.settings.product.handle work, so it does appear to be an object rather than a handle. The problem is just serializing to JSON, so I assume there's a bug here somewhere. I'll raise an issue with Developer Support.

LitCommerce
Astronaut
2860 684 732

Hi @tobynicholas ,

Sorry for the confusion, it works with json.

Code:

{%- assign product = all_products[section.settings.product] -%}

{{  product | json }}

 

 

anything else with object, it will work fine with code:

{%- assign product = section.settings.product -%}

so with this, it will absolutely support:

{%- assign product = all_products[section.settings.product] -%}

Hope it helps!

LitCommerce - The Most Simple & Affordable Multi-channel Selling Tool.
Effortlessly sell on biggest marketplaces like Amazon, Etsy, eBay, Facebook etc with bulk listing tool, real-time sync & smart order management. Use LitCommerce free for 1-year now!