Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Reverse sort order of products

Reverse sort order of products

Views: 1,313

Results 1 to 6 of 6
2 Mar 2011, 5:25 PM
#1
tecbrat avatar

tecbrat

Zen Follower

Join Date:
Feb 2005
Posts:
239
Plugin Contributions:
0

Reverse sort order of products

If I understand correctly, when no product sort order is given, the items will display in oldest to newest order when viewing the list of items in a category. I'd imagine if I knew exactly what file to edit, and what MySQL command to edit, it'd be a simple switch of an "ORDER BY" to make it show newest first instead.

If I'm right, can anyone point me to the right spot on the right file? If I'm missing it, is there another way besides retroactively placing a sort order on every product, then re-number them constantly to keep the newer products at the top of the list? (Will a negative sort order work? That might be the simple alternative. It wouldn't re-order the items with a 0 sort order, but I could put new items above the zeros anyway.)

2 Mar 2011, 6:11 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Reverse sort order of products

There is a setting in the Configuration ... Product Listing ...

Display Product Listing Default Sort Order
Product Listing Default sort order?
NOTE: Leave Blank for Product Sort Order. Sort the Product Listing in the order you wish for the default display to start in to get the sort order setting. Example: 2a

to know the setting you want to use, go to the Product Listing in your shop and click on the titles until you have the display order the way you want them and look in the URL and see what the setting is for the:
sort=

is set to ... that is the setting you would use to display the Products in the order that you want to see them ...

4 Mar 2011, 5:50 PM
#3
tecbrat avatar

tecbrat

Zen Follower

Join Date:
Feb 2005
Posts:
239
Plugin Contributions:
0

Re: Reverse sort order of products

Thanks. I hadn't seen that particular setting, but having seen it, I think I am missing something.
First, let's make sure we are talking about the same page. It would be like "?main_page=index&cPath=13_14" where the items are displayed.

Then, let's make sure I communicated correctly that I have many existing items that currently have no sort order on them, and I want to make them display in reverse order of their creation date.

Reading the default instructions on that setting, and reading your answer, left me scratching my head. I am not new to zen, but could you answer this question as if I were a complete noob?

(I should specify the cart is ver 1.3.8a)

4 Mar 2011, 6:10 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Reverse sort order of products

That would be a problem as the products_date_added is not one of the built in choices for the Product Listing ...

You could add that and customize the initial sort order when a sort order has not been selected by the customer yet ...

Look in the file:
/includes/index_filters/default_filter.php

and you can customize the code for:

// 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;

The current Products Sort Order, Products Name can be adjusted to something like the Date that the Product was added and Products Name ...

4 Mar 2011, 10:17 PM
#5
tecbrat avatar

tecbrat

Zen Follower

Join Date:
Feb 2005
Posts:
239
Plugin Contributions:
0

Re: Reverse sort order of products

Thanks Linda. I'll check that out next week. I should be able to manage that. I just didn't know what file to look in. When I'm successful, I'll post some code.

11 Mar 2011, 8:39 PM
#6
tecbrat avatar

tecbrat

Zen Follower

Join Date:
Feb 2005
Posts:
239
Plugin Contributions:
0

Re: Reverse sort order of products

TecBrat:

...When I'm successful, I'll post some code.

This seems to have worked:

// 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";
// zencart default is:
//        $listing_sql .= " order by p.products_sort_order, pd.products_name";
// sort by products_date_added, descending to put new items at the beginning of the list.
          $listing_sql .= " order by p.products_date_added DESC";