We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 436 ☆ A M B ☆
    • 265 Posts
    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?
      MODX Ambassador for Thailand. Managing Director at Monogon, a web design and development studio based in Bangkok, Thailand. - Follow me on Twitter.
      • 4172
      • 5,888 Posts
      I think, I would put the whole logic into a wrapper-snippet, which runs getResources internally (or may be a better choice to use pdoResources, which seems to have some cache-features included) and have links like that:

      <a href="[[~1? &scheme=`full` &sortmode=`newestfirst`]]">Newest First</a>
      <a href="[[~1? &scheme=`full` &sortmode=`pricelowtohigh`]]">Price Lowest to Highest</a>


      and let getCache cache by the sortmode - urlparam (I'm sure getCache can do that, but not sure about the needed configuration out of my head now)


        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 436 ☆ A M B ☆
        • 265 Posts
        Thanks for the reply Bruno - have you had much experience using pdoResources? It doesn't seem like its a simple drop-in replacement for getResources and all the documentation I can find is in Russian.
          MODX Ambassador for Thailand. Managing Director at Monogon, a web design and development studio based in Bangkok, Thailand. - Follow me on Twitter.