Page 1 of 1

Order Option Values in Admin Panel by Sort Order

Posted: Sat Aug 31, 2013 5:02 am
by billynoah
Ever notice that when you are editing option values in the admin panel they don't seem to appear in any particular order? Personally, I'd like the admin panel to respect the sort order I've set for option values.

This just replaces the admin database query with the slightly more complex catalog database query which sorts your option values properly when you edit a product in the admin panel.

Cheers.

Code: Select all

	<file name="admin/model/catalog/product.php">
		<operation>
			<search position="replace"><![CDATA[$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "'");]]></search>
				<add><![CDATA[
			$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_id = '" . (int)$product_id . "' AND pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ov.sort_order");
			]]></add>
		</operation>
	</file>

Re: Order Option Values in Admin Panel by Sort Order

Posted: Tue Oct 08, 2013 8:08 am
by billynoah
The above post orders options while editing a product. Here's another bit to order them while editing the options themselves.

Code: Select all

	<file name="admin/model/catalog/option.php">
		<operation>
			<search position="replace"><![CDATA[$option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "option_value WHERE option_id = '" . (int)$option_id . "'");]]></search>
			<add><![CDATA[$option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "option_value WHERE option_id = '" . (int)$option_id . "' ORDER BY sort_order ASC");]]></add>
		</operation>
	</file>

Re: Order Option Values in Admin Panel by Sort Order

Posted: Fri Oct 18, 2013 6:08 am
by js132
Thanks for the mods ... they work great!

Re: Order Option Values in Admin Panel by Sort Order

Posted: Tue Oct 22, 2013 3:59 am
by billynoah
you're most welcome, glad this works for you. I've got 60+ option values for a few of mine and sorting them this way helped me a lot.

Re: Order Option Values in Admin Panel by Sort Order

Posted: Wed Jan 08, 2014 9:27 pm
by Ben1989
Where do I put this code?

Re: Order Option Values in Admin Panel by Sort Order

Posted: Wed Jan 08, 2014 10:08 pm
by webvet
Ben1989

Firstly, you need to have installed vQmod

Secondly, you need to create an xml file using the guidance here: http://code.google.com/p/vqmod/wiki/Scripting

Drop this into your vqmod/xml folder and hey presto!

Hope that helps...

Re: Order Option Values in Admin Panel by Sort Order

Posted: Mon Mar 02, 2015 7:30 pm
by -Monique-
Thanks for the code to change the order of option values in the admin panel. It works great! I was wondering if it is also possible to sort the option values by name from A-Z when editing a product in the admin panel.

Hopefully someone can help me with this.