Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2006
    Location
    minneapolis
    Posts
    67
    Plugin Contributions
    0

    Default Set Product Listings to Random Order?

    I want my product listings to sort randomly, and can't figure out how to do this. Is there an easy way? I don't mind changing a few lines of code, but I can't figure out where to look. I know how to do a simple Order by Rand(). Do I look under "index filters?" Can someone show me what file to change and/or what to add?

  2. #2
    Join Date
    Jun 2003
    Posts
    33,715
    Plugin Contributions
    0

    Default Re: Set Product Listings to Random Order?

    Probably a silly question - but why?
    Please do not PM for support issues: a private solution doesn't benefit the community.

    Be careful with unsolicited advice via email or PM - Make sure the person you are talking to is a reliable source.

  3. #3
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Set Product Listings to Random Order?

    Quote Originally Posted by minneapolis_dan View Post
    I want my product listings to sort randomly, and can't figure out how to do this. Is there an easy way? I don't mind changing a few lines of code, but I can't figure out where to look. I know how to do a simple Order by Rand(). Do I look under "index filters?" Can someone show me what file to change and/or what to add?
    Also, when you do rand, think about this:
    I go to the 2nd page, and because of rand, I see the products I saw from the first page. Am I happy?
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  4. #4
    Join Date
    Jan 2006
    Location
    minneapolis
    Posts
    67
    Plugin Contributions
    0

    Default Re: Set Product Listings to Random Order?

    The reason is this: I built a site that sells customer-supplied products, all in the same category. I don't want to give the advantage to anyone who happens to name their product "aaa-something". You can see the site at the following, it's not official yet: http://yarnfind.com

    Maybe there's another solution besides random order, but it seemed to make sense to me.

    But if the random order can't be carried over multiple pages, as was suggested above, of course that wouldn't work:
    [ ...I go to the 2nd page, and because of rand, I see the products I saw from the first page ]

    But why would that have to be the case? Isn't the query only made once for a product category, and then the results paginated? I think I could write a query that does what I'm wanting, but I'm trying to stay within the Zen Cart system as much as possible, and I don't understand how it does queries. A query such as SELECT * from PRODUCTS WHERE category=x ORDER BY rand() LIMIT $start,$display_number , just an example how I would select products randomly and then spread the results out over multiple pages.

    I know a little programming, but not much.

  5. #5
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Set Product Listings to Random Order?

    Yes it uses:
    SELECT * from PRODUCTS WHERE category=x ORDER BY rand() LIMIT $start,$display_number

    Thus, for every page, the query is run once --> The result is not carried over, rand() is run every page.

    Here is something that may work for you:
    Add an additional field to the products, assign random number/string to them, then sort by that field.
    Every once in a while you can reset that field with new data to change the sort order.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  6. #6
    Join Date
    Jan 2006
    Location
    minneapolis
    Posts
    67
    Plugin Contributions
    0

    Default Re: Set Product Listings to Random Order?

    Thanks, I never thought of that. I'll check that out. Appreciate your help.

  7. #7
    Join Date
    Nov 2004
    Location
    Glasgow, Scotland
    Posts
    251
    Plugin Contributions
    0

    Default Re: Set Product Listings to Random Order?

    Hello,

    Not sure if you still need this but I've got the random order working across multiple pages on one of my sites. I used RAND() to randomise the output but I supply it with a seed derived from the session id so that the output is repeatable. That way when I go to the second page I can re order the products in the same way as the first page but take the next n products so that each product only appears once in the list.

    I derive the seed from the session ID so that the order is the same for the entire session but each visitor/visit sees the products in a different order.

    You can see it working here http://www.bigwowweddings.co.uk/musi...-c-30_231.html
    just delete the cookie and reload the page to have the products re randomised.

    Let me know if you still need this and I'll dig out the code

    Cheers.

  8. #8
    Join Date
    Jan 2006
    Location
    minneapolis
    Posts
    67
    Plugin Contributions
    0

    Default Re: Set Product Listings to Random Order?

    Yes duncanad, that sounds awesome, can you show me how to do it?

  9. #9
    Join Date
    Nov 2004
    Location
    Glasgow, Scotland
    Posts
    251
    Plugin Contributions
    0

    Default Re: Set Product Listings to Random Order?

    Hey,

    OK I'll try and make the instructions make sense but it should be pretty simple. If anyone has any suggestions on a better way to do this I'm happy to hear them but this works for me at the mo.

    The file you need to edit is includes/index_filters/default_filter.php

    Line 91 should read if (isset($column_list)) {

    Immediately after that line insert the following few lines.

    // bof randomise listing after sort by sort order
    if ($_GET['sort'] == 'RAND')
    {
    $seed = ereg_replace("[^0-9]", "", $_SESSION['securityToken']);
    $seed = substr($seed, 0, 5);
    $seed = (int)$seed;
    $listing_sql .= " order by p.products_sort_order desc, rand($seed)";
    }
    else
    {
    // eof randomise

    Now to activate it do the following

    1. Log in to Admin.
    2. Configuration>Product Listing>Display Product Listing Sort Order
    3. Enter 'RAND' (needs to be capitals).
    4. Click 'Update'

    You should now have the product listing order randomised for each separate session but the order will not change during a session meaning that you won't have the problem of products appearing more than once or even missing from the listings when navigating through multiple pages.

    Hope that helps.

  10. #10
    Join Date
    Feb 2009
    Location
    Cincinnati, OH
    Posts
    25
    Plugin Contributions
    0

    Default Re: Set Product Listings to Random Order?

    Quote Originally Posted by duncanad View Post
    Hey,

    OK I'll try and make the instructions make sense but it should be pretty simple. If anyone has any suggestions on a better way to do this I'm happy to hear them but this works for me at the mo.

    The file you need to edit is includes/index_filters/default_filter.php

    Line 91 should read if (isset($column_list)) {

    Immediately after that line insert the following few lines.

    // bof randomise listing after sort by sort order
    if ($_GET['sort'] == 'RAND')
    {
    $seed = ereg_replace("[^0-9]", "", $_SESSION['securityToken']);
    $seed = substr($seed, 0, 5);
    $seed = (int)$seed;
    $listing_sql .= " order by p.products_sort_order desc, rand($seed)";
    }
    else
    {
    // eof randomise

    Now to activate it do the following

    1. Log in to Admin.
    2. Configuration>Product Listing>Display Product Listing Sort Order
    3. Enter 'RAND' (needs to be capitals).
    4. Click 'Update'

    You should now have the product listing order randomised for each separate session but the order will not change during a session meaning that you won't have the problem of products appearing more than once or even missing from the listings when navigating through multiple pages.

    Hope that helps.
    This was exactly what I was looking for. My only question or comment was that I had to change:

    Line 91 should read if (isset($column_list)) {

    to

    Line 91 should read if (isset($column_list))

    And then add the code to get it to work. Otherwise when it loaded the site it was a blank white screen. I have not seen any other anomolies. Do you think there is a problem with that solution?

    TIA

 

 

Similar Threads

  1. Random Listings Required
    By peanut77 in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 20 Aug 2008, 01:18 PM
  2. Order of columns for Product Listings
    By lbowenc in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 28 Jan 2008, 06:58 PM
  3. Sort order in product listings
    By jjem in forum Basic Configuration
    Replies: 5
    Last Post: 3 Feb 2007, 02:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR