Using object handle to get product details

Using object handle to get product details

ced--ced
Shopify Partner
20 0 3

Hi,

How can I retrieve the product details (name, image, url etc) for an object handle?

Thanks

Replies 5 (5)

miniscript
Shopify Partner
32 1 11

Hi 

You can do it via liquid objects like below are some examples 

<h1 class="title">{{ product.title }}</h1>
<a href="{{ product.url }}">URL of Product</a>
<img src="{{ product.featured_image }}" alt="Product Image" />

 
You can read about this more at here - https://shopify.dev/docs/themes/liquid/reference/objects/product 

There is one Shopify Cheat sheet where you can find all the object at one place - https://www.shopify.in/partners/shopify-cheat-sheet 

Thank you 🙏 

ced--ced
Shopify Partner
20 0 3

Hi @miniscript,

I have coded a section with this schema:

{% schema %}
{
  "name": {
    "en": "Featured reviews"
  },
  "class": "featured-reviews",
  "max_blocks": 12,
  "blocks": [
    {
      "type": "custom",
      "name": {
        "en": "Product review"
      },
      "settings": [
        {
          "type": "product",
          "id": "feature_product",
          "label": {
            "en": "Product"
          }
        }
      ]
    }
  ]
}
{% endschema %}

 

But when I try {{ block.settings.feature_product.title }}, I don't get anything.

ced--ced
Shopify Partner
20 0 3

Any idea guys?

miniscript
Shopify Partner
32 1 11

You’re doing it wrong in Schema -  Here is the correct code for that 

{% for block in section.blocks %}
{{ block.feature_product.title }}
{% endfor %}

 
If you're using section block for that you need to loop through this first.  

HKR
New Member
18 0 0

{% assign pdt = all_products[handle] %}

<a href="youwebsite.com/product/{{ handle }}">

<img src="{{ pdt.featured_image | img_url: 'medium' }}" alt="{{ pdt.title }}">
<p>{{ pdt.title }}</p>

</a>