Liquid, JavaScript, themes, sales channels
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?!
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 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.
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!
User | RANK |
---|---|
38 | |
28 | |
13 | |
13 | |
10 |
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023