0
votes

When I try to get all products, I get a list of "ProductDrop" why is this happening?

{% for product in collections.all.products %}
products.push('{{ product }}')
{% endfor %}

enter image description here

1
And what is your question?drip
@drip why is this happening? because the result should be a list of productsLuis Montano
Nope, products return an object. If you say {{ product.title }} for example it will return a string. Write this and check your console and you will see what the object product returns: <script>{{ product | json }}</script>.drip
@drip thanks really, your help was useful! I just added {{ collections.all.products | json }} and it works!Luis Montano

1 Answers

1
votes

ProductDrop is like a Product Object. Javasript is not aware that a productdrop is an object in liquid. You have to treat it as a string and specify the attribute of the product you would like.

{{ product.title }} {{ product.id }}

If you are looking to grab the information for use later I would push the product.id and then use the ajax api to grab the product info as json. https://help.shopify.com/themes/development/getting-started/using-ajax-api#get-product