Build a product list

How can i display the list of products of a specifiy category?
All products are based on resources.

The structure looks like that:

  • category 1
    ---- product 1
    ---- product 2
    ---- product 3
  • category 2
    ---- product 4
    ---- product 5

I thought something like that would work:
[[commerce.get_products?
&products=123, 321, 213, 231
&tpl=product-item]]

But there isn’t a &parent parameter, so how can i get all the ressource id’ from category 1?

Thanks for your help.

See’ya
Leif

You’ll first need to iterate over the resources with getResources/pdoResources. Add the name of your products TV to &includeTVs.

Then in the template for that snippet, you can call commerce.get_products, passing the TV value into the &products property for get_products.

Thanks for your help. I thought that would be handled by Commerce directly.

Commerce is not quite that opinionated - it definitely could have a snippet that loops over resources and grabs all the TVs, but that locks you into a specific (resource) structure.

Now you can use the get_products snippets for anything no matter where you grab the product IDs from: on the product resource itself ([[*products]]), in a get/pdoResources listing ([[+tv.products]]), from a wishlist (cookielist or something else), or dynamically generate a list of product recommendations based on the current cart contents. Just feed the IDs into the snippet and format it any way you’d like.

One snippet to help with all of those (and many other) use cases is easier for us to maintain, and easier for users to learn :wink:

Hi @signalfeuer !

did you find a way to do it ?

i’m struggling with the same problem.
if you could share your code, that would be very helpfull ! :slight_smile:

Of course… :wink:

[[pdoResources?
            &parents=`[[*id]]`
            &depth=`0`
            &includeTVs=`product_name,product_image,product_badge,product_category`
            &tpl=`productItemTpl`
        ]]

thanks !
ok, my problem is that i want to display products from different categories like you, but display on the homepage, so &parents=[[*id]] don’t work

Can’t you enter the ids of your “product folders” instead?

yeah but it doesn’t work the way i want, have to dig a bit deeper

just solved it !

i’ve got categories without articles and articles are in sub-categories. i want to display 3 products only, not every product from every categories.

on homepage :

[[pdoResources?

     &parents=`404,424,426` 

&resources=-430,-431,-432,-433,-425,-434,-436,-437,-438,-439
&showHidden=1
&includeTVs=products
&depth=2
&processTVs=1
&limit=3
&tpl=ProductItemHomeDetailCarousel
]]

in ProductItemHomeDetailCarousel :

[[commerce.get_product?
&product=[[+tv.products]]
&tpl=ProductItemHomeImage
]]

and in ProductItemHomeImage :

[[+sku]]