product doesn't seem to be in all_products usage

Solved
New Member
7 0 0

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

 

0 Likes
Highlighted

Success.

Shopify Expert
2000 82 1452

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

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
1 Like
New Member
7 0 0

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.

0 Likes
New Member
7 0 0

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?

 

 

0 Likes
New Member
7 0 0

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.

0 Likes