License: GPL 2.0 as per included license.txt
Version: 2.0, tested on Zen Cart v1.51.
Support Thread: http://www.zen-cart.com/showthread.php?205606-Product-Listing-Sorter-Drop-Down
This mod adds a drop-down menu to the product listing and the advanced search results page that can be customised to offer any search options you want. Why? I don't use the column titles on my site design.
This is NOT a filter: all the products are displayed in the chosen order and it works in conjunction with the stock Manufacturer/Category filter drop-down and the Alpha "Sorter" (misnamed as its a filter) drop-down.
The drop-down is enabled by an admin configuration setting:
Admin->Configuration->Product Listing->Include Product
Listing Sorter Dropdown (mod)
You should completely uninstall/unmerge changes made by the the previous versions, return all files to default AND then check your site functionality BEFORE installing this version.
This version 2.0 is completely different and is not an enhancement of previous versions.
This fileset has been tested by dropping directly into a new Zen Cart 1.51 installation. You should test it similarly before integrating it into your own site.
As always, with ANY mod or plugin - BACKUP first and DO NOT INSTALL NOR TEST ON A LIVE/PRODUCTION SITE!
If any files (the overrides) already exist, you will need to merge the changes. If you are not sure what to do, install this on a new test shop and understand it before merging with your own shop development installation.
Copy/merge the files into the correct directories: the files marked with the \YOUR_TEMPLATE path need to go into your template directories or CLASSIC if you are just testing on a new installation, NOT into directories literally called "YOUR_TEMPLATE".
Copy the code from \sql\product_listing_sorter_install.sql and paste it into Admin->Install SQL Patches and Send.
This will install a new option in:
Admin->Configuration->Product Listing->Include Product
Listing Sorter Dropdown (mod)
1) the text shown and the corresponding relevant sql clauses are defined in
\includes\languages\english\extra_definitions\product_listing_sorter_en.php
define('PRODUCT_LISTING_SORTER_LIST', '
Name (asc):pd.products_name;
Name (desc):pd.products_name DESC;
Model (asc):p.products_model;
Model (desc):p.products_model DESC;
Price (low to high):p.products_price_sorter;
Price (high to low):p.products_price_sorter DESC;
Manufacturer:m.manufacturers_name;
Newest:p.products_date_added DESC;
Most Popular: p.products_ordered DESC
');
The sql clauses after the ":" are added onto the sql that produces the product listing, so making a mistake here will give you a blank white page.
Edit or comment out the lines as required.
Understanding the sorting and filtering mechanisms was difficult and so I have left many debugging statements in the code. These can be enabled by setting the variable to 1 at the start of the file:
$debug = '0';//1 or 0, show debugging information
I have tested this mod in a new Zen Cart 1.51 installation using the Classic template.
For further debugging I recommend installing the Superglobals plugin to show what variables are being set.
Copy the code from \sql\product_listing_sorter_uninstall.sql and paste it into Admin->Install SQL Patches and Send.
This will remove the option in:
Admin->Configuration->Product Listing->Include Product
Listing Sorter Dropdown (mod)
Delete the override files and unmerge the modifications to the core files.
From the community at http://www.zen-cart.com/showthread.php?205606-Product-Listing-Sorter-Drop-Down
-----------------------------------------------------------------------------------------------
I wrote this information to help my goldfish memory.
In the product listing there are two optional filters available.
1) The Category/Manufacturer filter
which displays this
2) The Product Listing Alpha filter (misnamed as an alpha sorter)
which displays this
Both can be enabled
This product listing sort order is handled by /includes/index_filters/default_filter.php using the value in $_GET['sort'].
$_GET['sort'] is not set on the initial page load so is given the default value set in the admin, or if nothing is defined, there is a hard-coded '20a' in the file.
Clicking on the product listing column headers will set a new value for $_GET['sort'] which will be used subsequently and thus override the default sort order.
In Admin->Configuration->Product Listing there are options which enable the display of the columns available.
What is not immediately apparent is that you can set the display order of those columns, eg. where Product Image is column 1, Product Name is column 2 and Product Price is column 3 as shown in the example.
The default sort order of the products
in those columns is determined by Display Product Listing Sort Order.
eg.
2a means sort by column 2 (Display Product name in this example),
descending: Z->A.
3d means sort by column 3 (Display Product Price/add to cart in this
example), ascending: low price->high price.
This value is named PRODUCT_LISTING_DEFAULT_SORT_ORDER in the database/code.
So, when $_GET['sort'] is not defined on initial page load (or is invalid/has anything other than "1-8" or "a" or "d" in it) then $_GET['sort'] will be set to the column of the Product Name and is hard-coded as ascending.
So if you've set Product Name as column 7, $_GET['sort'] will be set to 7a.
If you have switched off "Display Product Name", a hard-coded default setting of 20a is used (line 117):
// if set to nothing use products_sort_order and
PRODUCTS_LIST_NAME is off
if (PRODUCT_LISTING_DEFAULT_SORT_ORDER == '') {
$_GET['sort'] = '20a';
If something is defined in there, it is examined by the following code:
$sort_col = substr($_GET['sort'], 0 , 1);
$sort_order = substr($_GET['sort'], 1);
switch ($column_list[$sort_col-1]) {
where the column to use for sorting is extracted/identified, followed by the a or d for the sort_order.
So that's the default setting.
The drop-down adds another GET parameter to the urls that are used by the product-listing-name links and the return-to-listing button (in the prev-listing-next nav buttons) to preserve the listing sort order.
The sql for the sorted/filtered product listing is passed to a session variable for use by prev-next.
Code completely rewritten to add to rather than replace existing filters
and make use of Zen Cart 1.60 drop-down listing code.
Functionality expanded to maintain the selected filter and sort order through to
the product info page/prev-next navigation and back to the listing.
Readme updated.
Hard-coded constants removed: english and spanish defines added.
Refactored code to use overrides as much as possible.
Added code for Advanced Search Result
Added debugging.
Added new readme.
Repackaged as Product Listing Sorter instead of Product Filter Module...as
its not a filter!