I’ve not found a built in way to control sorting the product attributes yet. There’s probably a contribution to do this however considering it’s only a single line change which took me about 5 minutes to find I figured it wasn’t a concern to find a contribution for it. At present there is no ordering of the attributes when they’re pulled from the database. Regardless of how you enter them in the retrieval seems to just randomly make its own mind up about how they should be displayed! When a client first brought this to my attention and said they’d been inputting them in the correct order, and the order of the attributes where in the same order as the order id’s (ie. lowest id for the first item and highest id for the last item) it made me wonder just how it was coming out. Usually when you run a SELECT statement in MySQL if you don’t give it an order it comes out in the row order. But at the same time this often isn’t the same order as the items were added.

Anyhow, so which line do you change? Under the products_info.php file find the line:
$products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");

and at the end of the SQL statement add (for ordering by id)
ORDER BY pov.products_options_values_id ASC

giving you
$products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "' ORDER BY pov.products_options_values_id ASC");

This method orders the attributes by id number, the number you see at the start of the attribute line in the admin section. If you wanted it ordered alphabetically you could use (untested!)
ORDER BY pov.products_options_values_name ASC

or by price
ORDER BY pa.options_values_price ASC

  4 Responses to “Sorting Attributes”

  1. después de mucho buscar y encontrar paginas que decían tenían la solucion para ordenar los productos, encontré esta que realmente me funciono.
    gracias

    En:
    After a long time searching the way to sort by id or price, I find this page that really help me.
    thanks

  2. Hey Jorge, glad you got things working :)

  3. WORKED PERFECTLY!!!
    Many thanks!

  4. Thank goodness there’s someone out there helping people! This did exactally what I wanted to.

 Leave a Reply

(required)

(required)

* Copy this password:

* Type or paste password here:

2,239 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2011 osCommerce Templates Suffusion theme by Sayontan Sinha