Shopify themes, liquid, logos, and UX
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
Solved! Go to the solution
This is an accepted solution.
If the product is not published you shouldn't expect Liquid to return an object.
This is an accepted solution.
If the product is not published you shouldn't expect Liquid to return an object.
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.
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?
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.
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?
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.
From the docs:
'The all_products object has a limit of 20 unique handles per page. If you want more than 20 products, then consider using a collection instead.'
https://shopify.dev/docs/api/liquid/objects/all_products
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024