Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I retrieve a specific product in Shopify Liquid?

Tags:

I have a list of product handles, and I want to fetch the product based on this handle. It seems there is no way to tell Liquid to go and get a single product. I could do this with the API, but if I use the API then I have to use JavaScript, and I would have to copy the HTML which I already have in a snippet, and copy the logic too.

A cut down version of what I am attempting:

{% assign handle = 'my-product-handle' %} {% assign product = products.handle %} {% include 'snippet-product-item' %} 
like image 374
jayshields Avatar asked Nov 07 '12 11:11

jayshields


People also ask

How do I get a product handle?

Go to a live product page on your store. The product handle is everything after product/ in the product URL.


2 Answers

You can now retrieve a product via a handle using the following:

{% assign someProduct = all_products.some-handle %} 

There's currently no documentation to back this up, but hopefully there'll be something tangible on Shopify side soon.

like image 129
Jason Avatar answered Sep 18 '22 00:09

Jason


Just to update for anyone just finding this, you can now reference products directly via handle by all_products['handle'] as per this response on their Shopify/liquid repo.

like image 20
Bryan Corey Avatar answered Sep 20 '22 00:09

Bryan Corey