Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Sort by price with column display....

Sort by price with column display....

Views: 46,932

Results 21 to 40 of 101
27 Jun 2007, 4:16 PM
#21
rvagrrl avatar

rvagrrl

New Zenner

Join Date:
Oct 2005
Posts:
90
Plugin Contributions:
0

Sort by price with column display....

manada:

OK, i just look on this problem closely. I think we could go around like this:

At the beggining of tpl_modules_product_listing.php I entered as follow:

For ascending sorting link

echo '<a href="' . zen_href_link(FILENAME_DEFAULT , "cPath=$cPath") . "&sort=2a" . '">' . "Sort By Price (Asc)" . '</a><br>';

> 
> For descending sort. link; 
> 
> ```
echo '<a href="' . zen_href_link(FILENAME_DEFAULT , "cPath=$cPath") . "&sort=2d" . '">' . "Sort By Price (Asc)" . '</a><br>';

I know , its a little bit "off-zen" but it works.

Adam

Hmm. I tried this, but it doesn't actually sort the products as intended. It seems almost random. I wonder if I need to have the product listing settings set to something in particular to get it to work?

http://craftsbury.lbdclients.com/index.php?main_page=index&cPath=4_12

27 Jun 2007, 5:45 PM
#22
rvagrrl avatar

rvagrrl

New Zenner

Join Date:
Oct 2005
Posts:
90
Plugin Contributions:
0

Re: Sort by price with column display....

Yay, I got it working! It was, in fact, that I didn't have my listing settings the same. I had the price set to 3 and not 2, so when I changed the code to 3a and 3b, that fixed it. =) Just in case that's helpful to someone else!

27 Jun 2007, 10:52 PM
#23
manada avatar

manada

New Zenner

Join Date:
Dec 2005
Posts:
35
Plugin Contributions:
0

Re: Sort by price with column display....

Yup, you right. Forgot to mentioned about price desc/asc code.
:-)

27 Jun 2007, 11:38 PM
#24
rvagrrl avatar

rvagrrl

New Zenner

Join Date:
Oct 2005
Posts:
90
Plugin Contributions:
0

Re: Sort by price with column display....

Oh, almost forgot. Both links specify that they're for "(asc)", so you have to change the second to (desc) when you implement the code. FYI!

Thanks so much, manada, for posting that code, by the way. It's super helpful. =)

2 Jul 2007, 7:21 AM
#25
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Sort by price with column display....

To have a drop down box sorter:

In includes/templates/YOUR_CURRENT_TEMPLATE
Add a file called tpl_modules_additional_listing_display_order.php (actually you can call it however you want) with this content

<?php
/**
 * Module Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_modules_additional_listing_display_order.php 3369 2006-04-03 23:09:13Z drbyte $
 */
?>
<?php
// NOTE: to remove a sort order option add an HTML comment around the option to be removed
?>

<div id="sorter">
<label for="disp-order-sorter"><?php echo TEXT_INFO_SORT_BY; ?></label>
<?php
  echo zen_draw_form('sorter_form', zen_href_link($_GET['main_page']), 'get');
  echo zen_draw_hidden_field('main_page', $_GET['main_page']);
  echo zen_draw_hidden_field('cPath', $cPath);
  // draw cPath if known
  if (!$getoption_set)
    echo zen_draw_hidden_field('cPath', $cPath);
  echo zen_hide_session_id();
?>
    <select name="sort" onchange="this.form.submit();" id="disp-order-sorter">
<?php if ($_GET['sort'] != PRODUCT_LISTING_DEFAULT_SORT_ORDER) { ?>
    <option value="<?php echo PRODUCT_LISTING_DEFAULT_SORT_ORDER; ?>" <?php echo ($_GET['sort'] == PRODUCT_LISTING_DEFAULT_SORT_ORDER ? 'selected="selected"' : ''); ?>><?php echo PULL_DOWN_ALL_RESET; ?></option>
<?php } // reset to store default ?>
    <option value="1a" <?php echo ($_GET['sort'] == '1a' ? 'selected="selected"' : ''); ?>><?php echo TEXT_INFO_SORT_BY_PRODUCTS_NAME; ?></option>
    <option value="1d" <?php echo ($_GET['sort'] == '1d' ? 'selected="selected"' : ''); ?>><?php echo TEXT_INFO_SORT_BY_PRODUCTS_NAME_DESC; ?></option>
    <option value="3a" <?php echo ($_GET['sort'] == '3a' ? 'selected="selected"' : ''); ?>><?php echo TEXT_INFO_SORT_BY_PRODUCTS_PRICE; ?></option>
    <option value="3d" <?php echo ($_GET['sort'] == '3d' ? 'selected="selected"' : ''); ?>><?php echo TEXT_INFO_SORT_BY_PRODUCTS_PRICE_DESC; ?></option>
    </select></form></div>

Then in the file tpl_index_product_list.php in the same folder, edit to add this line:

require($template->get_template_dir('/tpl_modules_additional_listing_display_order.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_additional_listing_display_order.php'); 

You can add it wherever you want to dispkay the sorter, for me I added it right above this line:

 require($template->get_template_dir('tpl_modules_product_listing.php', DIR_WS_TEMPLATE, $current_page_base,'templates'). '/' . 'tpl_modules_product_listing.php');

Good luck

9 Aug 2007, 9:28 PM
#26
pensive612 avatar

pensive612

Zen Follower

Join Date:
May 2006
Posts:
313
Plugin Contributions:
0

Re: Sort by price with column display....

Yellow,

Thanks so much for this. I seem to be having a problem that others do too. The sorts seem to be random. I've tried it with columns and rows. both the same.

ie. prices low > high - doesn't actually sort them in order. just seems to mix them up.

same with all others except product names

any ideas?

thanks again...

9 Aug 2007, 9:31 PM
#27
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Sort by price with column display....

pensive612:

Yellow,

Thanks so much for this. I seem to be having a problem that others do too. The sorts seem to be random. I've tried it with columns and rows. both the same.

ie. prices low > high - doesn't actually sort them in order. just seems to mix them up.

same with all others except product names

any ideas?

thanks again...

Can you pm me your site?

9 Aug 2007, 10:20 PM
#28
pensive612 avatar

pensive612

Zen Follower

Join Date:
May 2006
Posts:
313
Plugin Contributions:
0

Re: Sort by price with column display....

Yellow...

I PM'd you.

let me know if you have any thoughts on it.

thanks.

Adam.

9 Aug 2007, 11:30 PM
#29
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Sort by price with column display....

Admin->configuration->product listing->set Display Product Listing Default Sort Order to 1d and then see if the sorting works.

Minor bug:
in the file tpl_modules_additional_listing_display_order.php, remove the line

echo zen_draw_hidden_field('cPath', $cPath);

There are 2 lines like that in the file, remove the first one

10 Aug 2007, 12:20 AM
#30
pensive612 avatar

pensive612

Zen Follower

Join Date:
May 2006
Posts:
313
Plugin Contributions:
0

Re: Sort by price with column display....

Thanks for the bugfix.

I changed it to 1d. and it didn't really seem to change anything.

but i was never aware of the abcd after the numbers...

am i maybe missing something somewhere else?

Display Product Image 1
Display Product Manufacturer Name 3
Display Product Model 4
Display Product Name 2
Display Product Price/Add to Cart 5
Display Product Quantity 0
Display Product Weight 0 Info
Display Product Price/Add to Cart Column Width 125
Display Category/Manufacturer Filter (0=off; 1=on) 1
Prev/Next Split Page Navigation (1-top, 2-bottom, 3-both) 3
Display Product Listing Default Sort Order 1d
Display Product Add to Cart Button 1
Display Multiple Products Qty Box Status and Set Button Location 3
Display Product Description 0
Product Listing Ascending Sort Order +
Product Listing - Layout Style columns
Product Listing Descending Sort Order -
Product Listing - Columns Per Row 4
Include Product Listing Alpha Sorter Dropdown true
Include Product Listing Sub Categories Image true
Include Product Listing Top Categories Image true
Show SubCategories on Main Page while navigating

thanks again for all the help.

10 Aug 2007, 1:13 AM
#31
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Sort by price with column display....

I may have changed something else in other files. let me check again and I'll get back to you asap

10 Aug 2007, 2:22 AM
#32
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Sort by price with column display....

I must have changed something in my files, anyhow, the setting below show work for your site (tested)

<option value="2a" <?php echo ($_GET['sort'] == '2a' ? 'selected="selected"' : ''); ?>><?php echo TEXT_INFO_SORT_BY_PRODUCTS_NAME; ?></option>
    <option value="2d" <?php echo ($_GET['sort'] == '2d' ? 'selected="selected"' : ''); ?>><?php echo TEXT_INFO_SORT_BY_PRODUCTS_NAME_DESC; ?></option>
    <option value="3a" <?php echo ($_GET['sort'] == '5a' ? 'selected="selected"' : ''); ?>><?php echo TEXT_INFO_SORT_BY_PRODUCTS_PRICE; ?></option>
    <option value="3d" <?php echo ($_GET['sort'] == '5d' ? 'selected="selected"' : ''); ?>><?php echo TEXT_INFO_SORT_BY_PRODUCTS_PRICE_DESC; ?></option>

I also notice something wrong on your site: when you use the sort form, you will be redirected to something like this:

index.php?main_page=index&cPath=15&sort=2d&filter_id=&alpha_filter_id=0&main_page=index&cPath=15&sort=1d

You see, the sort parameter appears twice, same goes for the main_index and cPath. It's just that you use the sort form along with the filter form, which already has the sorter passed as hidden field, along with cPath and main_page.

You should edit /includes/templates/your_current_template/templates/tpl_modules_listing_display_order.php, comment out the line:

echo zen_draw_hidden_field('disp_order', $_GET['disp_order']);

And edit tpl_modules_additional_listing_display_order.php, comment out all the lines that draw "main_page" and "cpath" field.

10 Aug 2007, 11:57 PM
#33
pensive612 avatar

pensive612

Zen Follower

Join Date:
May 2006
Posts:
313
Plugin Contributions:
0

Re: Sort by price with column display....

Yellow,

again, thank you so much for your help.

  1. I removed cpath and mainpath sections of tpl_modules_additional_listing_display

  2. changed the option value and sorts in the same file.

  3. and the line from tpl_modules_listing_display_order.php was already commented...

it doesn't seem to be any different.

except that I think the sort redirect is fixed.

if you are out of ideas. I understand and appreciate everything you've done so far.

I am here if anything else comes to mind.

thanks again.

11 Aug 2007, 12:01 AM
#34
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Sort by price with column display....

You still have 2 sort parameters passed at the same time, check your URL:

index.php?main_page=index&cPath=23&sort=1d&sort=5a

ZenCart will pick up the first para, which is 1d and that is not what we want!

11 Aug 2007, 12:08 AM
#35
pensive612 avatar

pensive612

Zen Follower

Join Date:
May 2006
Posts:
313
Plugin Contributions:
0

Re: Sort by price with column display....

you are right!

i'll be working on it.

keep you updated.

have a good day.

18 Sep 2007, 1:22 PM
#36
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Sort by price with column display....

Someone asked me how to let customers sort the listing the way they want, so I'll just bump this thread.

PS: Please start reading from page 3-4.

14 Oct 2007, 6:42 AM
#37
fjavier avatar

fjavier

New Zenner

Join Date:
Jun 2006
Posts:
20
Plugin Contributions:
0

Re: Sort by price with column display....

Any ideas on how to display products by date added in ascending or descending order?

http://www.daddyesonusa.com/shop/index.php?main_page

Thanks in advance.

15 Oct 2007, 1:36 AM
#38
ajeh avatar

ajeh

Oba-san

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

Re: Sort by price with column display....

products_date_added from the products table is not built into the products listing ...

It can be added but you would need to include this field in the select statements, built in the title and then the sort order for it ...

The other listings, Featured, All and New Product listings each have this built in as a selection on them and might be of help to you in customizing this information ...

15 Oct 2007, 2:41 AM
#39
fjavier avatar

fjavier

New Zenner

Join Date:
Jun 2006
Posts:
20
Plugin Contributions:
0

Re: Sort by price with column display....

Can the product sorting number be used as an alternative? In another words; when adding or editing products in the admin area and manipulating the sort number field?

15 Oct 2007, 2:45 AM
#40
ajeh avatar

ajeh

Oba-san

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

Re: Sort by price with column display....

That could become a royal pain to track and maintain ...

If can be done, if not using linked products ... but it would be more logical, as you will probably want the customer to switch between sort orders including by date, to code that in as one of the fields available ...

To set the default to the products_sort_order you can set the Product Listing so that it sorts on that field set the display order to Blank, meaning nothing, in the Configuration ... Product Listing ...