Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting on Custom Attribute

I have an attribute I created called "sales_rank" that I have set to use as a sortable attribute. However, when I choose it from the product list, it is not sorting how I expect. On further inspection, it appears that it's sorting as a text field and not as a number. This means that it will go 101, 1014, 102, 1035, 104, 11, 1204, etc....

How do I fix this? When creating the attribute, there's no way to tell it it's a number. You can select "Integer" from the "Input Validation" box, so is that the answer? I haven't tried it yet...

Any thoughts?

Thanks!

like image 683
Mageician Avatar asked Nov 05 '22 01:11

Mageician


1 Answers

Try that and come back if it continues not to work. Data fields can be saved in several tables, and it sounds like you are saving this field as a string (as evidenced by the alphabetical sort).

If you really want to know where it is saved, run this query against your database:

select backend_type from eav_attribute where attribute_code = 'sales_rank';

You want that to say number/integer, etc.

like image 101
Joe Mastey Avatar answered Nov 15 '22 04:11

Joe Mastey