Build a product list


(Leif Langsdorf) #1

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


(Mark Hamstra) #2

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.


(Leif Langsdorf) #3

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


(Mark Hamstra) #4

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:


(Julien Studer) #5

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:


(Leif Langsdorf) #6

Of course… :wink:

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

(Julien Studer) #7

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


(Leif Langsdorf) #8

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


(Julien Studer) #9

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


(Julien Studer) #10

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]]