Categories
Product Page Shopify Tech

Use all_products in a Shopify Theme

In this liquid Shopify post, we’ll be looking at a way to access product information using all_products. Here’s a quick example:

{{ all_products["product-handle"].id}}

Note

all_products uses product handle as its arguement. While creating the product the handle is created automatically, but if the product title changed the handle is not updated automatically it needs to be changed and do the changes wherever neccessary.

By using all_products one can access any product related property:

all_products["product-handle"].handle
all_products["product-handle"].tags
all_products["product-handle"].template_suffix
all_products["product-handle"].title
all_products["product-handle"].type
all_products["product-handle"].url
all_products["product-handle"].variants
all_products["product-handle"].vendor
all_products["product-handle"].id
all_products["product-handle"].featured_image
all_products["product-handle"].images
all_products["product-handle"].image
all_products["product-handle"].available
all_products["product-handle"].collections
all_products["product-handle"].compare_at_price_max
all_products["product-handle"].compare_at_price_min
all_products["product-handle"].compare_at_price_varies
all_products["product-handle"].content
all_products["product-handle"].description
all_products["product-handle"].first_available_variant
all_products["product-handle"].options
all_products["product-handle"].price
all_products["product-handle"].price_max
all_products["product-handle"].price_min
all_products["product-handle"].price_varies
all_products["product-handle"].selected_variant
all_products["product-handle"].selected_or_first_available_variant

When to use all_products

all_products makes a great option when you have need of outputting a single, or small number of products, that won’t frequently change.

You can explore more by going through this article in detail

Categories
Product Page Shopify Tech

Add 3 or more specific related products to a product page using only Liquid

We’ll be looking at a way to access product information for adding specific related products on a product detail page. 

We can achieve this by using all_products

Let us have a quick look at what’s happening. the syntax is pretty simple, all_products takes product handle as its arguement.

For this week’s Liquid Shopify tutorial, we’ll be looking at a way to access product information using all_products and metafields to add specific related products.

EXAMPLE for related products.

The logic for this code is pretty simple

  • get the metafield
  • split the metafield value
  • loop the array
  • use all_products to reference a product, and show title on the page.
{%- comment -%}
  Grab product handles from metafield.
  Loop the handles, showing the product title.
  The metafields fields value to be stored:
  Namespace: related
  Key: products
  Value: (comma separated String value)
{%- endcomment -%}

{%- if product.metafields.related.products != blank -%}
  <ul>
    {%- assign relatedProductArray = product.metafields.related.products | split:',' -%}
    
    {%- for relatedProductValue in relatedProductArray -%}
    {%- assign b = all_products[relatedProductValue] -%}
    <li><a href="/products/{{ relatedProductValue }}">{{ b.title }}</a></li>
    {%- endfor -%}
  </ul>
{%- endif -%}

Also look at the post Create customizable products