Sort by Custom Field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gulfcoast
    Mivite

    • Mar 2006
    • 213

    #1

    Sort by Custom Field

    I have the sort option on category pages and wanted to add the ability to sort by a custom product field. I have tried the following but it lacks something:

    <mvt:if expr="g.Sort_By EQ 'customfield_values:customfields:brand'">
    <option value="brand" selected="selected">Brand</option>
    <mvt:else>
    <option value="brand">Brand</option>
    </mvt:if>

    If someone could point me in the right direction it would be greatly appreciated. Thank you.



    Tim S. Raisbeck, owner
    Charlotte’s Saddlery Inc.

    11623A Katy Freeway
    Houston, Texas 77079
    1.800.231.6530

    http://www.charlottes-saddlery.com
    Proudly Serving the Equine Industry for Over 35 Years.
  • Bruce - PhosphorMedia
    Developer Partner











    • Mar 2006
    • 11257

    #2
    AFAIK, you cannot sort by custom field.
    Bruce Golub
    Phosphor Media - "Your Success is our Business"

    Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
    phosphormedia.com

    Comment

    • Brennan
      Super Moderator









      • Jun 2009
      • 3481

      #3
      There is nothing built in to sort by a custom field, but you can do it with some template code.

      You'll first need to add the custom field the products array so you can later sort on it. This code should go above your category product list loop.

      Code:
      <mvt:foreach iterator="product" array="category_listing:products">
      
          <mvt:assign name="g.brand" value="''" />
          <mvt:item name="customfields" param="Read_Product_Code( l.settings:product:code, 'brand', g.brand )" />
          
          <mvt:if expr="NOT ISNULL g.brand">
              <mvt:assign name="l.settings:product:brand" value="g.brand" />
          </mvt:if>
      
      </mvt:foreach>
      
      <mvt:if expr="g.Sort_By EQ 'Brand'">
          <mvt:do file="g.module_library_utilities" name="l.null" value="QuickSortArray(l.settings:products, '', 1)" />
      </mvt:if>

      Last edited by Brennan; 07-22-16, 09:35 AM.
      Brennan Heyde
      VP Product
      Miva, Inc.
      [email protected]
      https://www.miva.com

      Comment

      • Gulfcoast
        Mivite

        • Mar 2006
        • 213

        #4
        Thanks for your help Brennan. The bottom expression would go with the sort function. The top expression I wasn't sure what you meant by "category product list loop" placement?
        Tim S. Raisbeck, owner
        Charlotte’s Saddlery Inc.

        11623A Katy Freeway
        Houston, Texas 77079
        1.800.231.6530

        http://www.charlottes-saddlery.com
        Proudly Serving the Equine Industry for Over 35 Years.

        Comment

        • Jim Cockerham
          Mighty Mivite




          • Mar 2006
          • 755

          #5
          Originally posted by Gulfcoast View Post
          Thanks for your help Brennan. The bottom expression would go with the sort function. The top expression I wasn't sure what you meant by "category product list loop" placement?
          Gulfcoast did you have any luck with this yet? I am trying to get it working too.
          Highly caffeinated
          http://www.coffeehouseexpress.com

          Comment

          • Gulfcoast
            Mivite

            • Mar 2006
            • 213

            #6
            I have not Jim. I never got a response from Brennan.
            Tim S. Raisbeck, owner
            Charlotte’s Saddlery Inc.

            11623A Katy Freeway
            Houston, Texas 77079
            1.800.231.6530

            http://www.charlottes-saddlery.com
            Proudly Serving the Equine Industry for Over 35 Years.

            Comment

            • netblazon
              Developer Partner




              • Mar 2006
              • 717

              #7
              Is there now some way to do this out of the box? The thread is three years old, but I can't find any new references.
              Thanks,
              Susan
              Susan Petracco
              NetBlazon

              1.866.400.2444

              _____________________________________________

              Like us on Facebook

              Comment

              • Bruce - PhosphorMedia
                Developer Partner











                • Mar 2006
                • 11257

                #8
                Apparently its as easy as

                Code:
                      <mvt:do file="g.module_library_utilities" name="l.success" value="QuickSortArray(l.settings:subcats, ':customfield_values:customfields:CatPaperType' , 1)" />
                where

                ':customfield_values:customfields:CatPaperType'

                is the custom field variable string used as a literal (and yes, with a colon in front--yea, weird).

                the 1 is sort direction so you have 1 or -1.

                Scott Shepard figured this out, I just use it...so bug him if it doesn't work for you :)
                Bruce Golub
                Phosphor Media - "Your Success is our Business"

                Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                phosphormedia.com

                Comment

                • netblazon
                  Developer Partner




                  • Mar 2006
                  • 717

                  #9
                  Bruce, thanks. Unfortunately that only works if you don't use pagination, as it only sorts the products set to show on a given page. I appreciate the input, however.

                  PS Brennan said it's still not available out of the box in any other way.
                  Susan Petracco
                  NetBlazon

                  1.866.400.2444

                  _____________________________________________

                  Like us on Facebook

                  Comment

                  • Bruce - PhosphorMedia
                    Developer Partner











                    • Mar 2006
                    • 11257

                    #10
                    Wouldn't this work if you do this in a component module and replace the existing array?

                    (i mean, you do know how to write modules :) )
                    Bruce Golub
                    Phosphor Media - "Your Success is our Business"

                    Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                    phosphormedia.com

                    Comment

                    • netblazon
                      Developer Partner




                      • Mar 2006
                      • 717

                      #11
                      Yes, I can add it to the CSSUI Product List module, and that's what I suggested to the client. They just don't like the idea of having to maintain it when Miva updates the stock version. It's always a trade-off though, and I tried to explain that.
                      Susan Petracco
                      NetBlazon

                      1.866.400.2444

                      _____________________________________________

                      Like us on Facebook

                      Comment

                      • Bruce - PhosphorMedia
                        Developer Partner











                        • Mar 2006
                        • 11257

                        #12
                        You could write it as an 'overlay' module. So long as you stick with APIs it should survive all but the most apocalyptic updates.

                        Bruce Golub
                        Phosphor Media - "Your Success is our Business"

                        Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                        phosphormedia.com

                        Comment

                        Working...
                        X