Retrieve a number of randomly-chosen products in Shopify

Enercos - Single Product eCommerce Shopify Theme

I need a solution for retrieve a number of randomly-chosen products on my homepage (or any pages). I read in here: Featuring a number of randomly-chosen products on your homepage. But I think It’s not good with me. I continue read an article in here: Featuring one randomly-chosen product on your homepage. I think it’s a good solution. Really this solution support retrieve only a product, but I can get more if i change variant for “limit”. Good…. But after that I found issue with it.

Example: That collection has 10 products and I want retrieve 5 products. All are OK if index number is 1 or 2 or 3 or 4 or 5 but if index number is greater than 5 We will miss some products.

I thinking… and after I have solve for this issue. Sharing with everybody.

Get index number:

Count product missing

Now we can show products

If current index don’t take enough of the products. We need add below code:

Huynh Mai Anh Kiet

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *