Anupam Mistry
Anupam Mistry

Reputation: 421

How can I call product image, details, and price on the section page in Shopify?

{% for block in section.blocks %}
{% for image in product.images %} {{ image.src | product_img_url: 'grande' }} {% endfor %}
{{block.settings.product.title}}
{{all_products[product].price | money_without_trailing_zeros }}
{% endfor %}

{% schema %}
{
"name": "Demo",
"blocks": [
{
"type": "new-arrival",
"name": "New Arrival",
"settings": [
{
"type": "product",
 "id": "product",
"label": "Product"
}

]
 }
]
}
{% endschema %}

Can anyone tell me how can I call multiple product images, product details, and product prices on the section page? Here some code that I try but it's not correct.

Upvotes: 1

Views: 3250

Answers (2)

Onkar
Onkar

Reputation: 2584

when using the input type product into Shopify schema, you need to use the all_products object to get the details of the selected product, you need to get the details and assign it to a variable, something like this one.

{% assign product = all_products[block.settings.product] %}

Then you can use the other properties of the same object. so your code is looking.

{% for block in section.blocks %}
   {% assign product = all_products[block.settings.product] %}
   {% for image in product.images %} 
     <!-- list images -->
      {{ image.src | product_img_url: 'grande' }} 
     <!-- product title -->
      {{product.title}}
     <!-- product price -->
      {{ product.price | money_without_trailing_zeros }}
     <!-- product description -->
      {{product.description}}
   {% endfor %}   
{% endfor %}

{% schema %}
{
   "name": "Demo",
   "blocks": [
      {
         "type": "new-arrival",
         "name": "New Arrival",
         "settings": [
            {
               "type": "product",
               "id": "product",
               "label": "Product"
            }

         ]
      }
   ]
}
{% endschema %}

You can check and read more about object all_products Link

Upvotes: 2

Anupam Mistry
Anupam Mistry

Reputation: 421

Thank You for guide Onkar. I update a little bit now it properly works.

{% for block in section.blocks %}
   {% assign product = all_products[block.settings.product] %}
   {% for image in product.images %} 
        <img src="{{ image.src | product_img_url: 'grande' }}" >
      {{product.title}}
      {{ product.price | money_without_trailing_zeros }} 
      {{product.description}}
   {% endfor %}
   
{% endfor %}

Upvotes: 2

Related Questions