5

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!

Mageician
  • 2,918
  • 9
  • 43
  • 69

2 Answers2

1

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.

Joe Mastey
  • 26,809
  • 13
  • 80
  • 104
  • Thanks @joseph-mastey, but unfortunately that didn't seem to work. I tried your suggestion on the current attribute and it is, in fact, a **varchar**. However, I tried creating a new attribute, this time selecting "Integer" for the "Input Validation" option, but it is once again a **varchar**. I also tried getting all attributes who's **backend_type** is **int**. The results are all _Dropdown_ & _Yes/No_ attribute types, but I can't use those in this case. Is there a way to have a _Text Field_ style attribute(in terms of how you enter the value) that is actually an _Integer_ value? – Mageician Mar 16 '11 at 21:02
  • 1
    BTW, I was able to fix the sorting issue by padding the strings with leading '0's so that they sort properly...but I don't like this solution, so if anyone knows the proper way, please let me know :) – Mageician Mar 16 '11 at 21:19
  • Brian, what do you mean by padding the strings with leading '0's? I'm also having this problem! – Adam Moss Oct 31 '11 at 11:42
  • Actually, I think I know what you mean: 0010 0020 0030 etc up to 9999 – Adam Moss Oct 31 '11 at 11:47
1

I found my solution here: http://www.magentocommerce.com/bug-tracking/issue?issue=7204

Basically, use the 'price' attribute type because the system sees it as an integer. Not pretty, but it works a treat!

Adam Moss
  • 5,582
  • 13
  • 46
  • 64