Solved

product doesn't seem to be in all_products usage

Robert222
Tourist
12 0 1

Hi.

I have been stuck on this issue for a few days and seem to be stuck.  What I am trying to do is list though all the variants of a product.  


{% assign all_shirts= all_products['shirts'].variants %}
{% for shirt in all_shirts%}
<li> {{ shirt.price | money_with_currency }} </li>
{% endfor %}

 

This works for some products and not others.  The problem seems to be in the all_products[handle].variants object.  It acts as if the handle is not defined.   I have checked the handle ID of the product and it is correct.   The products are not customer visible but that should not matter?

 

Are there any cases in which products will not be in the all_products structure?    The products it is not working for have been recently added so not sure if this has anything to do with it as I can find them as a product when I do an AddItem call.

 

Thanks for your help in advance.

Robert

 

Accepted Solution (1)

Jason
Shopify Expert
11190 225 2283

This is an accepted solution.

If the product is not published you shouldn't expect Liquid to return an object.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★

View solution in original post

Replies 6 (6)

Jason
Shopify Expert
11190 225 2283

This is an accepted solution.

If the product is not published you shouldn't expect Liquid to return an object.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
Robert222
Tourist
12 0 1

Thanks Jason.  Can you tell me why I can add it with AddItem but not find with with all_products?  I don't want anyone to add this to their cart, its a hidden item.   It is an item I automatically add to the cart based on some criteria.  I don't want people to be able to add it to their cart.

Robert222
Tourist
12 0 1

I am adding an item to the customers cart but before I do that, I was using all_products to get information and show them what item I am adding to the cart.  While I can add the item no problem, I can't show them before hand because I can't access the product in this manner.  Maybe there is another way to do this?

 

 

Robert222
Tourist
12 0 1

Hi Jason,  I figured it out.  I made the product available and will now look into how to make sure on one can add it to there cart...

 

Thank you.

KuznetsEnvy
Shopify Partner
38 0 10

I'm facing the same problem, but making products active doesn't help.
all_products[handle] works for some products and returns empty value for others on the same page.
All products are active and available on the "Online store" channel.

Are there any other reasons why all_products[handle] can fail to work?

Drew_K
Shopify Partner
23 5 0

For me, all_products is not working at all. Not listing even a single product. What can be the issue? I have products published in my store.

Shopify and web developer
Get a free store review or consultation here: https://drew-k.com