We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46309
    • 79 Posts
    Hi everyone,

    I'm building an e-commerce site using Minishop2 and need to add a field with sorting by price.
    Does anybody know how to do that?
    I know there is such a possibility with mSearch2 module, but it's paid.
    I tried something like that but it's not working:
    <a href="[[~[[+id]]]]&sortby=Data.price&sortdir=[!sortdir? &sortby=`Data.price` &sdir=`ASC`!]">Price</a>


    I sorted the products on the page like this:
    [[!msProducts?
            &sortby=`{
    		"price":"desc"
    	}`]]

    and it just shows me the products on the page from lower to higher price (or from higher to lower price with price:asc), but how can I make it with choosing both of the options as sorting link on the page, respectivly from lower to higher price and from higher to lower price?
      peace&love / bike&ride
      • 42046
      • 436 Posts
      I haven't tried it but you could use gerURLParam http://rtfm.modx.com/extras/revo/geturlparam to inject the sort order into the msProducts call.

      The link:

      <a href="[[*id]]&sort=asc">Sort by asc</a>


      msProducts call:

      [[!msProducts?
              &sortby=`{
              "price":"[[!getUrlParam? &name=`sort`]]"
          }`]]
        • 46309
        • 79 Posts
        Thank you Dan, it works like a charm smiley
        Here's my code in case somebody is having the same issue (there can be also other sorting options depending on product properties):

        <div>
                Sort by:
                    <select name="sortby" onChange="window.location.href=this.value">
                    <option value="[[~[[*id]]]]&date=asc">Date: new to old</option>
                    <option value="[[~[[*id]]]]&date=desc">Date: old to new</option>
                    <option value="[[~[[*id]]]]&price=asc">Price: low to high</option>
                    <option value="[[~[[*id]]]]&price=desc">Price: high to low</option>
                    </select>
                </div>
            <div>
                <ul>
                [[!msProducts?
                &sortby=`{
                "price":"[[!getUrlParam? &name=`price`]]",
                "publishedon":"[[!getUrlParam? &name=`date`]]"
            }`]]
                </ul>
            </div>


        It could be done also with drop down menu for example using list and links. I don't know which way is better, it's all matter of choice...

        One more time, thank you for the help Dan!
          peace&love / bike&ride
          • 9995
          • 1,613 Posts
          thanks for sharing. I really need to check out minishop2. Looks like its the best ecommerce choise for modx.
            Evolution user, I like the back-end speed and simplicity smiley
            • 46309
            • 79 Posts
            You are welcome fourroses! Yeah, Minishop2 looks pretty well, I've checked also Shopkeeper, but for me Minishop2 was better choice.
            About the code above. Actually there is a problem with selected option values from the code above:
            When I choose some of the options it returns the right product sorting, but in the selected field remains the first value. In my case, when I choose for example "Price:low to high" it reloads the page with sorted products price from low to high, but in the select field remains the first value "Date:new to old".
            Does anybody have an idea how to solve this?
              peace&love / bike&ride
              • 9995
              • 1,613 Posts
                Evolution user, I like the back-end speed and simplicity smiley
                • 46309
                • 79 Posts
                Thank you fourroses, but I can not make it working (off course I've changed your values of "fruit" to mines "sortby" and added id="sort by")...
                Where and how should I place the JavaScript code (I'm not very familiar with JavaScript)?
                Thank you in advance!
                  peace&love / bike&ride
                  • 9995
                  • 1,613 Posts
                  Hmm didn't know it uses mootools and you don't want to use that;
                  http://fiddle.jshell.net/Lyxut/6/show/

                  I'm not sure but I think local storage only works with html5 so you might wanna look for cookies.

                  I guess a further search is needed.
                  http://goo.gl/w4LjXB
                    Evolution user, I like the back-end speed and simplicity smiley