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!
Explore the 30-30-30 rule, a dynamic social media strategy for new businesses. Learn how t...
By Trevor Sep 20, 2023Discover how to leverage the often overlooked footer of your ecommerce site to gain custom...
By Skye Sep 15, 2023In this blog, we’ll be shining a light on Shopify Partners, Experts, and Affiliates. Who a...
By Imogen Sep 13, 2023