Index  Previous: PRODUCT PRICING   Next: SHIPPING

SORTING

MiniVend has standard sorting options for sorting the search lists, loop lists, and item lists based on the contents of database fields. In addition, adds list slices for limiting the displayed entries based on a start value and chunk size (or start and end value, from which a chunk size is determined). All accept a standard format sort tag which must be directly after the list call:

    [loop 4 3 2 1]
    [sort -2 +2]
        [loop-code]
    [/loop]
 
    [search-list]
    [sort products:category:f]
        [item-price] [item-description]<BR>
    [/search-list]
 
    [item-list]
    [sort products:price:rn]
        [item-price] [item-code]<BR>
    [/item-list]
 
    [loop search="ra=yes"]
    [sort products:category products:title]
    [loop-field category] [loop-field title] <BR>
    [/loop]

All sort situations -- [search list] , [loop list] , [tag each table], and [item-list], take options of the form:

  [sort database:field:option* -n +n =n-n ... ]
database

The MiniVend database identifier. This must be supplied, and should normally be 'products' if you are using the default name for the database.

field

The field (column) of the database to be sorted on.

option

None, any, or combinations of the options:

  f   case-insensitive sort (folded) (mutually exclusive of n)
  n   numeric order (mutually exclusive of f)
  r   reverse sort
-n

The starting point of the list to be displayed, beginning at 1 for the first entry.

+n

The number of entries to display in this list segment.

=n-n

The starting and ending point of the list display -- this is an alternative to -n and +n. You should specify in only one form -- if both are specified the last one will take effect.

...

Don't really put ... in. This just means that you may specify as many sort levels as you wish. Lots of sort levels with large databases will be quite slow.

Multiple levels of sort are supported, and you can cross database boundaries on different sort levels. Cross-database sorts on the same level are not supported, so if you use multiple product databases you will have to sort with embedded Perl. This is actually a feature in some cases, since you can then display all items in a used database before or after your new ones in products.

Examples, all based on the simple demo:

Loop list

    [loop 00-0011 19-202 34-101 99-102]
    [sort products:title]
        [loop-code] [loop-field title]<BR>
    [/loop]
 
Will display:

    34-101 Family Portrait
    00-0011 Mona Lisa
    19-202 Radioactive Cats
    99-102 The Art Store T-Shirt

If you instead do:

    [loop 00-0011 19-202 34-101 99-102]
    [sort products:title -3 +2]
        [loop-code] [loop-field title]<BR>
    [/loop]
 
you will see:

    19-202 Radioactive Cats
    99-102 The Art Store T-Shirt

The tag [sort products:title =3-4] is equivalent to the above.

Search list

A search of all products (i.e. http://yoursystem.com/cgi-bin/simple/scan/ra=yes):

    [search-list]
    [sort products:artist products:title:rf]
        [item-field artist] [item-field title]<BR>
    [/search-list]
 
will display:

    Gilded Frame
    Grant Wood American Gothic
    Jean Langan Family Portrait
    Leonardo Da Vinci Mona Lisa
    Salvador Dali Persistence of Memory
    Sandy Skoglund Radioactive Cats
    The Art Store The Art Store T-Shirt
    Vincent Van Gogh The Starry Night
    Vincent Van Gogh Sunflowers

Note the reversed order of the title for Van Gogh, and the presence of the accessory item Gilded Frame at the front of the list (it has no artist field, and as such sorts first).

Adding a slice option:

    [search-list]
    [sort products:artist products:title:rf =6-10]
        [item-field artist] [item-field title]<BR>
    [/search-list]
 
will display:

    Sandy Skoglund Radioactive Cats
    The Art Store The Art Store T-Shirt
    Vincent Van Gogh The Starry Night
    Vincent Van Gogh Sunflowers

If the end value/chunk size exceeds the size of the list, only the elements that exist will be displayed, starting from the start value.

Shopping cart

    [item-list]
    [sort products:price:rn]
        [item-price] [item-code]<BR>
    [/item-list]
 
will display the items in your shopping cart sorted on their price, with
the most expensive shown first. (Note that this is based on the database field,
and doesn't take quantity price breaks or discounts into effect.) B<NOTE:> You 
cannot sort on modifier values or quantities.
Complete database contents

    [tag each products]
    [sort products:category products:title]
    [loop-field category] [loop-field title] <BR>
    [/tag]

A two level sort, that will sort products based first on their category then on their title within the category.

Note that large lists may take some time to sort -- if you have a product database with many thousands of items, it is not recommended that you use the [tag each products] sort unless you are planning on caching or statically building your pages.




Index  Previous: PRODUCT PRICING   Next: SHIPPING