I am working with a PHP shopping cart system called Tomatocart. I am using a stripped down version where I have removed all the cart features to make an online catalogue. Here - http://www.taylor-transformers.co.uk/cat
The problem I have is I want to display the products in a certain order, but the cart has no facility for this. The way I thought of doing this was to default sort the products by using the price even though this is not displayed.
Sort order can be changed once they are displayed via a drop down menu
EG sorted by name
http://taylor-transformers.co.uk/cat/index.php?cPath=21_10&sort=name
As default when a category is selected it doesn't have EG &sort=name at the end
The code that appears in the page code is
<select name="sort" id="sort" onchange="this.form.submit()"><option value="sku">Part No. (ASC)</option><option value="sku|d">Part No. (DESC)</option><option value="name">Product Name (ASC)</option><option value="name|d">Product Name (DESC)</option></select>
The code is produced from the following PHP in a page called product-listing.php
<?php echo osc_draw_pull_down_menu('sort', $sort_array, $sort, 'onchange="this.form.submit()"'); ?>
and in helper.php
function get_products_listing_sort() {
global $osC_Language;
return array(array('id' => 'sku', 'text' => $osC_Language->get('listing_sku_heading') . ' (ASC)'),
array('id' => 'sku|d', 'text' => $osC_Language->get('listing_sku_heading') . ' (DESC)'),
array('id' => 'name', 'text' => $osC_Language->get('product') . ' (ASC)'),
array('id' => 'name|d', 'text' => $osC_Language->get('product') . ' (DESC)'));
}
Where sku is the part number. I have changed the above code. Originally it was set to sort by price and name and it works fine.
I have been trying to work out how to use a Javascript onload to do something similar to what the dropdown menu is doing, but sort products by price by default when the pages are loaded. I can get onload events to work, but not for sorting the products. Or is there an alternative way of doing this? I can usually work stuff like this out, but I'm stuck here. Any help greatly appreciated.
On product_listing.php to test things I've tried adding
<form action="" method="post" name="form1" id="sort" ><input name="" type="submit" /></form>
When this is submitted it performs the desired action. IE it sorts by sku.
I've also got
<title>onload test</title><script>
function load() {
alert("load event detected!");
}
window.onload = load;
</script>
Every time a category link is clicked, the alert pops up, so I know I have onload events working. I just can't get any of the form to submit with onload.
As I was just using these for testing, they are now disabled.