Announcement

Collapse
No announcement yet.

Sorting Picklist Items by a Primary and Secondary Sort Criteria

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Sorting Picklist Items by a Primary and Secondary Sort Criteria

    Hey Everyone,
    I am trying to sort our pick list items by Warehouse Location (a custom field) and then by Product Code. I can successfully sort by one or the other, but I cannot sort by location and then code.

    Here is the code that I am attempting to run right before my order:groups for loop in our pick list Order Contents section.

    Code:
    <table class="product-info"
    <tr>
    
    <th class="code">Code</th>
    <th class="product" width=200px>Product</th>
    <th class="total">Price</th>
    <th class="quantity">Quantity</th>
    <th class="total">Total</th>
    <!--<th width=10px padding=0px>&nbsp;</th>-->
    </tr>
    
    <mvt:assign name="g.basktotal" value="0" />
    <mvt:assign name="g.baskweight" value="0" />
    
    <!-- Scott D added secondary sorts by code (Secondary Sort)-->
    <!-- This does not work in conjunction with the sort by Location below -->
    <mvt:do file="g.module_library_utilities" name="l.null" value="QuickSortArray(l.settings:order:groups, ':product:code', 1)" />
    
    <!-- Scott D added sort by location (Primary Sort)-->
    <mvt:do file="g.module_library_utilities" name="l.null" value="QuickSortArray(l.settings:order:groups, ':customfield_values:customfields:product_location ', 1)" />
    
    <mvt:foreach iterator="item" array="order:groups">
    .......
    The above code just sorts by whichever QuickSortArray call is last in line.

    Anything obvious I am missing here?

    Thank you!
    --Scott

    #2
    This will not work. You're calling the same function twice which means the second sort will always override the first sort. I cannot think of a way to fix this off the top of my head. This isn't an issue with QuickSortArray, it's more of a limitation.
    David Carver
    Miva, Inc. | Software Developer

    Comment


      #3
      You could potentially set up your own comparisons array and then call QuickSortArray_Sort...

      Code:
      <mvt:assign name="l.comparisons[ 1 ]:subelement"    value="':product:code'" />
      <mvt:assign name="l.comparisons[ 1 ]:direction"     value="1" />
      <mvt:assign name="l.comparisons[ 2 ]:subelement"    value="':customfield_values:customfields:product_l ocation'" />
      <mvt:assign name="l.comparisons[ 2 ]:direction"     value="1" />
      
      <mvt:do file="g.Module_Library_Utilities" name="l.null" value="QuickSortArray_Sort( l.settings:order:groups, miva_array_elements( l.settings:order:groups ), 2 )" />
      That should work, but I haven't tested it.
      Ryan Guisewite
      Lead UI Developer / Miva, Inc.
      www.miva.com

      Comment


        #4
        Odd. If the first QSA physically changes the array structure, why does the following QSA not work on the currently existing structure given that is now l.settings:option:groups? Would renaming the structure have any effect?
        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


          #5
          Originally posted by Bruce - PhosphorMedia View Post
          Odd. If the first QSA physically changes the array structure, why does the following QSA not work on the currently existing structure given that is now l.settings:option:groups? Would renaming the structure have any effect?
          It might be worth a try; I know this works in some cases. But there are many different sorting algorithms. Some of them shuffle the data around quite a bit before it finally settles into the new sort order.

          For what it's worth, I have this function that can do multi-column sorts. This article shows the code.

          http://themagicm.com/store/a-new-miv...-function.html

          It's written in Miva Script; I don't know if it can be converted to Store Morph code. I can provide a small utility module that includes this function, so that you can call it from page templates by using mvt:do.
          Kent Multer
          Magic Metal Productions
          http://TheMagicM.com
          * Web developer/designer
          * E-commerce and Miva
          * Author, The Official Miva Web Scripting Book -- available on-line:
          http://www.amazon.com/exec/obidos/IS...icmetalproducA

          Comment


            #6
            Originally posted by Bruce - PhosphorMedia View Post
            Odd. If the first QSA physically changes the array structure, why does the following QSA not work on the currently existing structure given that is now l.settings:option:groups? Would renaming the structure have any effect?
            Yeah, this is the exact reason I thought this would work. I guess the solution is to sort and store the array as a unique one, then sort that one again storing it as another unique array, and using that to cycle through my pick list items. The issue is, I cannot figure out how to do that. I am still pretty new to Miva coding. I really appreciate you guys hopping in here to discuss this. Thank you,
            --Scott

            Comment


              #7
              Originally posted by scottd21 View Post

              Yeah, this is the exact reason I thought this would work. I guess the solution is to sort and store the array as a unique one, then sort that one again storing it as another unique array, and using that to cycle through my pick list items. The issue is, I cannot figure out how to do that. I am still pretty new to Miva coding. I really appreciate you guys hopping in here to discuss this. Thank you,
              --Scott
              Did the solution I posted not work?
              Ryan Guisewite
              Lead UI Developer / Miva, Inc.
              www.miva.com

              Comment


                #8
                Originally posted by rguisewite View Post

                Did the solution I posted not work?
                Hey Ryan,
                Unfortunately no, it did nothing to the order of the items.
                --Scott

                Comment

                Working...
                X