I've created a shop (using Bert's
SimpleCart plugin), the plugin uses standard resources and lets site builders make categories in any way they see fit.
So I've created a category using getResources and then used the getUrlParam snippet to pass various options to the getResources call. This way the shop can have "sort by newest first", "sort by oldest first", "sort by price highest to lowest", "sort by price lowest to highest", etc filtering options. Here's an example getResources call:
[[!getResources?
&parents=`1`
&tpl=`shop.product.summary`
&limit=`[[!getUrlParam:default=`12`? &name=`limit`]]`
&sortbyTV=`[[!getUrlParam:default=`publishedon`? &name=`sortby`]]`
&sortdirTV=`[[!getUrlParam:default=`DESC`? &name=`sortdir`]]`
&sortdir=`[[!getUrlParam:default=`DESC`? &name=`sortdir`]]`
&sortbyTVType=`decimal`
]]
Then I can make buttons on the page to pass the values to the URL, like this
<a href="[[~1? &scheme=`full`]]?sortby=publishedon&sortdir=DESC">Newest First</a>
<a href="[[~1? &scheme=`full`]]?sortby=product-price&sortdir=ASC">Price Lowest to Highest</a>
Here every time the page is loaded the getUrlParam will check the URL and change the getResources output. However, when I try to cache the getResources snippet using something like getCache the page no longer works, I presume because it would need to cache all the various combinations of the output.
My actual code is more complex than this because I'm also passing the &limit parameter to the URL as well as some others for tagging/categories, and there's also pagination too for multiple pages.
Has anybody got a better, more efficient way of achieving this?