Alphabetise Option Variants

It is possible to have the system automatically alphabetize the Option Variants? I sell candles that come in common sizes in various fragrances. I want it to alphabetaize the Fragrance options. The only thing I see that I can do is to manually do it myself by using the position function. It would seem that the system will automatically alphabetize them if you give them all a position of 0.

If you want your products to be sorted by name then go into Appearance settings and under “Customer Settings” you will see “Product list default sorting”. Set this to “Product name” then click update.



Originally it is set to sort by the product ID or basically when you enter the product.

I just checked and mine was set to Product Name. The products are sorting by name, but their Options are not.

Does anyone have any idea what file and the location I would need to look at to fix the sort issues for product variants.

This is for 1.3.5sp3, it may work for other versions. In /core/fn_catalog.php, line 916, change:


$_opts = db_get_hash_array("SELECT a.option_id, a.option_type, a.position, a.inventory, a.product_id, b.option_name, b.option_text, a.avail FROM $db_tables[product_options] as a LEFT JOIN $db_tables[product_options_descriptions] as b ON a.option_id=b.option_id AND b.lang_code='$lang_code' LEFT JOIN $db_tables[product_global_option_links] as c ON c.option_id=a.option_id WHERE (a.product_id='$product_id' OR c.product_id='$product_id') $avail $os_cond ORDER BY a.position", 'option_id');


to


$_opts = db_get_hash_array("SELECT a.option_id, a.option_type, a.position, a.inventory, a.product_id, b.option_name, b.option_text, a.avail FROM $db_tables[product_options] as a LEFT JOIN $db_tables[product_options_descriptions] as b ON a.option_id=b.option_id AND b.lang_code='$lang_code' LEFT JOIN $db_tables[product_global_option_links] as c ON c.option_id=a.option_id WHERE (a.product_id='$product_id' OR c.product_id='$product_id') $avail $os_cond ORDER BY [COLOR="Red"]b.option_name[/COLOR]", 'option_id');


This will alphabetize the product options, then at line 921, change:


$_opts[$k]['variants'] = db_get_hash_array("SELECT a.variant_id, a.position, a.modifier, a.modifier_type, a.weight_modifier, a.weight_modifier_type, $extra_variant_fields b.variant_name FROM $db_tables[product_option_variants] as a LEFT JOIN $db_tables[product_option_variants_descriptions] as b ON a.variant_id=b.variant_id AND b.lang_code='$lang_code' WHERE a.option_id='$v[option_id]' $_avail ORDER BY a.position",'variant_id');


to


$_opts[$k]['variants'] = db_get_hash_array("SELECT a.variant_id, a.position, a.modifier, a.modifier_type, a.weight_modifier, a.weight_modifier_type, $extra_variant_fields b.variant_name FROM $db_tables[product_option_variants] as a LEFT JOIN $db_tables[product_option_variants_descriptions] as b ON a.variant_id=b.variant_id AND b.lang_code='$lang_code' WHERE a.option_id='$v[option_id]' $_avail ORDER BY [COLOR="Red"]b.variant_name[/COLOR]",'variant_id');


This line wil alphabetize the option variants. In both cases the red part is the part to change.

Thank you so much! That works perfectly!