Hi,
I've just been working on something like this.
I needed multiple categories to apply to products.
Probably too much to post here, but press me for details if needed - I appreciate this post might be a bit wooly...
Your idea is along the right lines, but it kind of depends on the complexity and scale of the catalogue + products. Yes, you could 'Bind' the TV to a simple query to build the links...
Definitely worth taking the time to find a good solution, rather than winging it and getting into hot water once the site goes live (and thousands of products/categories start getting pumped into it!).
I would say that having the Categories as child Resources of a Container Resource is a nice easy way for your client to work with them in the CMS, but using a whole Resource to denote a category is overkill… (I think all MODXers come up against this at some point).
Have you looked into using an XPDO package and custom tables?
It sounds like hard work, but its trivial enough to do… You'll never look back.
I can help you with this on ground level if needed.
As a simplified starting point...
Three custom tables within an XPDO package called 'Catalogue'
Product (PK = product_id)
Category (PK = category_id)
ProductCategory (product_id + category_id)
This DB architecture would allow you to assign multiple Categories to Products using ProductCategory.
From there, you'd could create a custom snippet to replace 'getResources' (e.g, getProducts) that you would use in combination with 'getPage' on your 'category landing pages'.
http://mysite.com/category/?category=foo
]] getPage? &element=`getProducts` &tpl=`categoryListItem` [[
'getProducts' would look at your $_GET params and then use them as a basis for the query, with a join onto ProductCategory as a filter (getPage just splits this into 'offset' + 'limit' queries for paging).
(pseudo code)
select
x,
y,
z
from `product` p
join `product_category` pc
on (`pc`.`product_id` = `p`.`product_id`)
join `category` c
on (`c`.`category_id` = `pc`.`category_id`)
where `p`.`active` = '1'
if($_GET['category']) {
and `c`.`alias` = 'foo'
}
Please note, there are native/better XPDO methods for doing the above query, but you get the idea.
Any requests without a category will get all of the products.
You could also take things a step further to use URLs like:
http://mysite.com/category/foo/
This could be done with webserver rewrites, or by using the MODX 'PageNotFound' event.
Sorry if this is all a bit vague - its fairly simple once you get a foot in the door.
Hopefully, someone else will post a better response for you!
I would definitely recommend getting to grips with the XPDO core of Modx.
Feel free to message me if you need more details, code examples etc...