Jump to content

Sorting Product Options


Guest annienym

Recommended Posts

Guest annienym

After some research, I have found several ways to sort product options. In my case, I have some t-shirt sizes that need to be sorted. I noticed in the SQL database that the options have 3 variables available and one of them is a "value_id". I would like to use this to sort the options list. I'm running CC5.0.6 and unfortunately, other versions are not giving me any direction. I think the core files have changed considerably so I need a little help with this. Thank you.

Link to comment
Share on other sites

Hello annienym!

=== EDIT: This isn't working as well as I had thought. Try it at your own risk. =======

Sounds like you are familiar with editing files, so...

This is for the Option Sets and how the attributes (values) in a Set is ordered.

In the file \classes\catalogue.class.php, find the public function getProductOptions method (about halfway down). Four lines down, change just this part of the statement:

(int)$set_data['set_id'])))

to

(int)$set_data['set_id']), array('value_id' => 'ASC|DESC')))

leaving all the rest of this statement as it is. Be sure to choose the sort direction ASC or DESC.

This is for the individual Option Assignments and how the free attributes (values) are ordered.

About 47 lines down from the method start, change just this:

array('product' => (int)$product_id, 'set_member_id' => 0, 'set_enabled' => '1')))

to

array('product' => (int)$product_id, 'set_member_id' => 0, 'set_enabled' => '1'), array('value_id' => 'ASC|DESC')))

This should get you what you want. You may need to clear the cache via the admin function.

===== EDIT ============

Ok, 16 lines down from the method start, change:

array('priority' => 'DESC', 'value_name' => 'ASC')))

to

array('priority' => 'DESC', 'value_id' => 'ASC|DESC')))

Choose ASC or DESC.

Link to comment
Share on other sites

Guest annienym

Thank you bsmither. The fix was even easier than your solution. Thank you for telling me where to find it. I would have never found it on my own.

The answer is:

in /classes/catalogue.class.php on line 480 (clean install of CC5.0.6) you will find this:

if (is_array($value_id) && ($values = $GLOBALS['db']->select('CubeCart_option_value', false, array('value_id' => $value_id), array('priority' => 'DESC', 'value_name' => 'ASC'))) !== false) {

change it to this:

if (is_array($value_id) && ($values = $GLOBALS['db']->select('CubeCart_option_value', false, array('value_id' => $value_id), array('priority' => 'DESC', 'value_id' => 'ASC'))) !== false) {

You are done ... just refresh your product page and the product options will be sorted in ascending order by their value_id. You can change the value_id in your SQL database, or reload your option sets from admin in the order you want them to appear. The first option is value_id = 1, the second value_id = 2, and so on.

Thanks again for all your help. That was an easy one.

Keywords: product, products, option, options, sort, sorting, "product options sorting", "option sort", "option sorting", "options sorting", "options sort"

Link to comment
Share on other sites

  • 3 weeks later...

I haven't found that annienym's solution works. I have changed the code on line 480 of the catalogue.class.php file to the prescribed fix and nothing happens. I have cleared all caches, refreshed pages etc. Am I missing something?

Thanks for any help that anyone can throw my way.

Link to comment
Share on other sites

The section I changed currently looks like this:

/* changed to sort product options */

/*if (is_array($value_id) && ($values = $GLOBALS['db']->select('CubeCart_option_value', false, array('value_id' => $value_id), array('priority' => 'DESC', 'value_name' => 'ASC'))) !== false) {*/

if (is_array($value_id) && ($values = $GLOBALS['db']->select('CubeCart_option_value', false, array('value_id' => $value_id), array('priority' => 'DESC', 'value_id' => 'ASC'))) !== false) {

Thanks for any help you can provide.

EDIT ======================

Okay, I see the issue now. Changing line 480, as annienym says, is exactly correct, it does change the order of options as long as they are in an option set. I cannot, as near as I can tell, use option sets for the way my products are set up. I am selling quantities of different items and a quantity of item 'a' is not necessarily the same cost as the same quantity of item 'b'. In other words, the options themselves have different prices and are product specific.

Simple individual product options, the ones where you can add a price to each of them, also have a value_id in the DB. There's a way to sort on that as well just like with the option sets - I'm just not sure where to look. Any ideas?

Thanks again for the help.

Link to comment
Share on other sites

Okay, I've got it figured out. If you need to sort product options that are not in an option set - open /classes/catalogue.class.php as annienym suggests above and go to line 527 or do a search for // Get Option Values, you will see (underneath the // Get Option Values line):

if (($values = $GLOBALS['db']->select('CubeCart_option_value', false, array('option_id' => $category['option_id'], 'value_id' => $mid), array('priority' => 'DESC', 'value_name' => 'ASC'))) !== false) {

change to

if (($values = $GLOBALS['db']->select('CubeCart_option_value', false, array('option_id' => $category['option_id'], 'value_id' => $mid), array('priority' => 'DESC', 'value_id' => 'ASC'))) !== false) {

This will sort the individual options by their value_id when they are grabbed from the DB. Couldn't have gotten there without the help of annienym. Thanks!

Link to comment
Share on other sites

  • 7 months later...
Guest Golf Pro

I know nothing about code. Had to have my cart installed. Help files do not help me figure out how to set up Option Groups or Option Sets. I sell golf clubs with various shaft, grip, flex options and each shaft has different price, each grip has different price. I want to set up basic set of options for all iron models so I don't have to select 50 individual options for each one. Pick one shaft type, one grip type and flex designation, etc. for each model to get final price.

- thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...