Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Dec 2014
    Location
    North Platte, NE & Fountain Valley, CA
    Posts
    37
    Plugin Contributions
    0

    Default Random Sort Order

    Trying to set up all products list to sort products randomly. Used the information in this thread

    https://www.zen-cart.com/showthread....o-Random-Order


    It doesn't seem as if there are any errors, and the page is showing up just fine. Could it be a version issue why this isn't working with 154?

    Or does someone have a similar solution to doing this?

  2. #2
    Join Date
    Sep 2008
    Posts
    210
    Plugin Contributions
    21

    Default Re: Random Sort Order

    If you want to do this, you can not do it in admin. You must edit code from any listing.
    Our Site: http://zucando.com
    Marketing Plugins: Marketing Modules
    Free Response Templates: Responsive Templates

  3. #3
    Join Date
    Dec 2014
    Location
    North Platte, NE & Fountain Valley, CA
    Posts
    37
    Plugin Contributions
    0

    Default Re: Random Sort Order

    Quote Originally Posted by cvhainb View Post
    If you want to do this, you can not do it in admin. You must edit code from any listing.
    I did edit the code using the thread I posted the link to. It didn't cause any issues, but even when calling for the RAND in admin, it's not randomizing. I know nothing about sessions, and I know this is suppose to be written to read the session, and only randomize once, that way the same products won't show up on page 2. It randomizes all products, and then saves them that way for the entire visit. (or at least that's how I understand it).

  4. #4
    Join Date
    Sep 2008
    Posts
    210
    Plugin Contributions
    21

    Default Re: Random Sort Order

    You can not use rand() for your listing, it can makes your site with duplicate content. You should use rand() for a block products (example new products, featured products and specials)
    Our Site: http://zucando.com
    Marketing Plugins: Marketing Modules
    Free Response Templates: Responsive Templates

  5. #5
    Join Date
    Dec 2014
    Location
    North Platte, NE & Fountain Valley, CA
    Posts
    37
    Plugin Contributions
    0

    Default Re: Random Sort Order

    Quote Originally Posted by cvhainb View Post
    You can not use rand() for your listing, it can makes your site with duplicate content. You should use rand() for a block products (example new products, featured products and specials)
    Have you looked over the thread link I've posted? I'm not good enough at coding to tell exactly what it's doing, but it's supposed to just randomize once, that way you don't get duplicate listings, and then can be used on all products. It randomizes, and then spreads them out over the pages.

  6. #6
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,542
    Plugin Contributions
    19

    Default Re: Random Sort Order

    This got my attention and I decided to do it... Here's what you need to do.

    Go to includes/index_filters/ and create a new directory for your template override and copy the default_filter.php to the new directory. Now you'll have something like includes/index_filters/YOUR_TEMPLATE/default_filter.php
    Now edit that file and find around line 94
    Code:
    if (isset($column_list)) {
    Add after:
    Code:
    // BOF randomize sort order 1/2
       if ($_GET['sort'] == 'RAN') {
    		$seed = preg_replace("/[^0-9]/", "", $_SESSION['securityToken']);
    		$seed = substr($seed, 0, 5);
    		$seed = (int)$seed;
    		echo $seed;
    		$listing_sql .= " order by p.products_sort_order desc, rand($seed)";
    	} else {
    	// EOF randomize sort order 1/2
    Next, around line 148 find 3 closing brackets and just add one more.

    This is how your code will look:
    Code:
    // set the default sort order setting from the Admin when not defined by customer
      if (!isset($_GET['sort']) and PRODUCT_LISTING_DEFAULT_SORT_ORDER != '') {
        $_GET['sort'] = PRODUCT_LISTING_DEFAULT_SORT_ORDER;
      }
    
      if (isset($column_list)) {
       // BOF randomize sort order 1/2
       if ($_GET['sort'] == 'RAN') {
    		$seed = preg_replace("/[^0-9]/", "", $_SESSION['securityToken']);
    		$seed = substr($seed, 0, 5);
    		$seed = (int)$seed;
    		echo $seed;
    		$listing_sql .= " order by p.products_sort_order desc, rand($seed)";
       } else {
       // EOF randomize sort order 1/2
        if ((!isset($_GET['sort'])) || (isset($_GET['sort']) && !preg_match('/[1-8][ad]/', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($column_list)) ) {
    	  for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
            if (isset($column_list[$i]) && $column_list[$i] == 'PRODUCT_LIST_NAME') {
              $_GET['sort'] = $i+1 . 'a';
    		  
              $listing_sql .= " order by p.products_sort_order, pd.products_name";
              break;
            } else {
    // sort by products_sort_order when PRODUCT_LISTING_DEFAULT_SORT_ORDER is left blank
    // for reverse, descending order use:
    //       $listing_sql .= " order by p.products_sort_order desc, pd.products_name";
              $listing_sql .= " order by p.products_sort_order, pd.products_name";
              break;
            }
          }
    // if set to nothing use products_sort_order and PRODUCTS_LIST_NAME is off
          if (PRODUCT_LISTING_DEFAULT_SORT_ORDER == '') {
            $_GET['sort'] = '20a';
          }
        } else {
          $sort_col = substr($_GET['sort'], 0 , 1);
          $sort_order = substr($_GET['sort'], 1);
          switch ($column_list[$sort_col-1]) {
            case 'PRODUCT_LIST_MODEL':
              $listing_sql .= " order by p.products_model " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
              break;
            case 'PRODUCT_LIST_NAME':
              $listing_sql .= " order by pd.products_name " . ($sort_order == 'd' ? 'desc' : '');
              break;
            case 'PRODUCT_LIST_MANUFACTURER':
              $listing_sql .= " order by m.manufacturers_name " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
              break;
            case 'PRODUCT_LIST_QUANTITY':
              $listing_sql .= " order by p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
              break;
            case 'PRODUCT_LIST_IMAGE':
              $listing_sql .= " order by pd.products_name";
              break;
            case 'PRODUCT_LIST_WEIGHT':
              $listing_sql .= " order by p.products_weight " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
              break;
            case 'PRODUCT_LIST_PRICE':
              $listing_sql .= " order by p.products_price_sorter " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
              break;
          }
        }
       // BOF randomize sort order 2/2
       }
       // EOF randomize sort order 2/2
      }
    // optional Product List Filter
      if (PRODUCT_LIST_FILTER > 0) {
    Next, go to your admin->Configuration->Product Listing and set "Display Product Listing Default Sort Order" to RAND.

    Don't get confused with the code above using 'RAN' - this is on purpose because the very beginning of the default_filter.php strips the $_GET parameter down to 3 characters... Basically, you can enter RANDOM in the admin, it won't make any difference. Heck, you could even put RANCH...

    There's no mention of duplicate content since the sort order is passed on to all pages and products will not be duplicated. It will only randomize the sort order based on session parameter which is randomly generated by Zen Cart...
    Last edited by balihr; 27 Aug 2015 at 04:23 PM. Reason: styling

  7. #7
    Join Date
    Dec 2014
    Location
    North Platte, NE & Fountain Valley, CA
    Posts
    37
    Plugin Contributions
    0

    Default Re: Random Sort Order

    Quote Originally Posted by balihr View Post
    This got my attention and I decided to do it... Here's what you need to do.
    I did this and I still can't get it to function. Do I need to delete the original default filter file? If the template one is meant to override it, I wouldn't think I would need to, but that's the only thing I can think of. If you want to check it out, i'll post the site. its
    wearspeedmachine . com/index.php and then click on all products. they're still sorting by alpha order.

    I really appreciate the help. thank you

  8. #8
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,542
    Plugin Contributions
    19

    Default Re: Random Sort Order

    Quote Originally Posted by Craig Freeburg View Post
    and then click on all products.
    Hehe, you should've mentioned you were specifically doing this for the products_all page - I thought you were referring to the standard product_listing page... Let me see what I can do.

  9. #9
    Join Date
    Dec 2014
    Location
    North Platte, NE & Fountain Valley, CA
    Posts
    37
    Plugin Contributions
    0

    Default Re: Random Sort Order

    Quote Originally Posted by balihr View Post
    Hehe, you should've mentioned you were specifically doing this for the products_all page - I thought you were referring to the standard product_listing page... Let me see what I can do.
    I thought of that afterwards. haha. sorry.

  10. #10
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,542
    Plugin Contributions
    19

    Default Re: Random Sort Order

    First of all, a correction for my previous post - I forgot to remove the echo line...

    Here's how the first block should (default_filter.php) look like:
    Code:
    // BOF randomize sort order 1/2
       if ($_GET['sort'] == 'RAN') {
    		$seed = preg_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 randomize sort order 1/2
    As for your request on products_all page, here's what you need to do:
    edit your includes/modules/pages/products_all/header_php.php
    Find around line 23:
    Code:
    $products_all_query_raw = "SELECT p.products_type.....
    and add BEFORE:
    Code:
    // bof - randomize sort order
      if(PRODUCT_LISTING_DEFAULT_SORT_ORDER == 'RAND') {
    	  $seed = preg_replace("/[^0-9]/", "", $_SESSION['securityToken']);
    	  $seed = substr($seed, 0, 5);
    	  $seed = (int)$seed;
    	  $order_by = " order by rand($seed), pd.products_name";
      }
      // eof - randomize sort order
    Since there are no available inputs to set any sort for the products_all page, I've used the one for product_listing pages (PRODUCT_LISTING_DEFAULT_SORT_ORDER). You'll need to set that in the admin as mentioned in the previous post. This time, it must say RAND.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v151 Product Sort within Category - having problems changing the default sort order
    By Don Wagner in forum Customization from the Admin
    Replies: 4
    Last Post: 21 Oct 2012, 03:03 AM
  2. Index page sort order is Random
    By nabrown78 in forum Basic Configuration
    Replies: 11
    Last Post: 20 Feb 2010, 11:02 PM
  3. Sort Order Issues (items keeps rotating at random)
    By datatv in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 12 Dec 2009, 03:08 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