New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Option Attributes Have 0 for Priority #1248
Comments
I will assert the mentioned issues are not related to this issue. |
I see, you're talking about the screen where one actually adds the option values ('attributes') themselves, my mistake. Unfortunately one cannot have multiple auto-increment columns in a single table and CubeCart_option_value 'value_id' is already auto-incrementing. Another solution would be to allow NULL for the priority and have that as the default, then use a query such as On second thought, |
Re: only one AUTO_INCREMENT, I find that my database designer does, in fact, only allow one column to have this attribute. Prior to actually trying this, all my research never explicitly said this restriction exists. I'm also finding restrictions on trying to SELECT MAX(priority) on an INSERT query. But there are hints on how this can be done successfully. |
This seemed to work:
From: http://dev.mysql.com/doc/refman/5.7/en/subquery-restrictions.html |
Perhaps defining the desired behavior will help us reach a solution. From what I understand, the goals are as follows:
Using the following data:
Number 1 seems to work properly: 'Three', 'Four', and 'Five' are ordered according to how they were entered, i.e. by their Number 3 doesn't work at all for Number 2 seems to be the tricky problem, but it can be solved by changing the sort query on line 241 of That change would also guarantee the ordering expected by number 1 and allow number 3 to potentially function if we decide to both keep and fix secondary sorting by Screenshot after the above fix: Setting priority to a non-zero or non-null value by default, on the other hand, would preclude us from ever implementing number 3 unless we also created a method of setting priority values of equal value. There could also be other unknown ramifications affecting e.g. plugins. Furthermore, should it ever need to be known, it would then be impossible to determine which entries were explicitly assigned priorities. I therefore maintain that setting priority upon insert is not an appropriate solution. |
@bhsmither Does my proposed solution resolve the issue for you? If so, I'll make a PR; if not, please discuss in what ways it does not meet your needs. Proposed solution:
|
I'm going to assert that This SQL function as a proxy for a column name would work, however, if it were passed to |
You are correct - further testing revealed that the sort was being completely ignored, despite my initial (false) positive. I wasn't aware that Removing line 241 and changing line 254 (now 253) to include it as a string literal as you suggested has given expected results in several tests.
I note however that there is still an edge case of sorts where an option value with priority of 0 will sort before a value with priority less than or equal to the first value's id. E.g. value_1 {id=1, priority=0} appears before value_2 {id=2, priority=1}. I don't believe this is a realistic possibility, however, as the priority for all existing option values is updated any time any priority is set via the admin panel. Any new option values added with a priority of 0 will sort by their value_id which is guaranteed to be higher than the highest existing priority. In other words, I think the solution above will be acceptably functional. |
Fixed with briansandall@81f4311 |
Newly created options with no assigned priority failed to sort properly in the options matrix. Applying the same fix from cubecart#1248 resolves this issue.
In
product.options.inc.php
, line 107, new attributes are databased without a priority.In
Catalogue->getProductOptions()
, the query specifies a SORT BY priority then by value_name.So, even if a number of attributes are meticulously added in a desired order, that order is ignored - which may confuse the new admin.
Only when the Option Attributes are saved a second time does CC apply the priority (see lines 128-148). And, once the priority has been determined, the SORT BY value_name expression in the query becomes meaningless, as it seems the priority update results in a straight, non-repeating (and non foreign-keyed) sequence.
Perhaps a better approach is to make the database table Cubecart_option_value, 'priority' column have an AUTO_INCREMENT characteristic. This will, at the start, after adding new attributes, at least keep the order of these attributes in the order entered.
The text was updated successfully, but these errors were encountered: