0

Magento CE 1.9.1 - I have a custom attribute (Scott #) which essentially is a stamp catalog number. When the frontend sorts the display by Scott #, it was fine until I hit number 100. Now, it is putting catalog number 101 after number 1, rather than after number 99. How can I fix this? Thank you!

  • This sort is made by MySQL ORDER BY. You need natural sort but MySQL doesn't support it. That's why you have to make some workarounds on the MySQL query which is a little bit ugly. Or to sort the collection with php natsort(). Or the easiest solution - just add zeros before the numbers (i.e. 1 to become 001). – michael Dec 31 '14 at 18:05
  • @michael great answer, please add it as an actual answer so OP can accept it if it works – Sander Mangel Dec 31 '14 at 19:01
  • @Sander Mangel, thank you. I added it as an answer but I don't think it's great. But I will be glad if it's a little helpful. – michael Dec 31 '14 at 19:53
1

This sort is made by MySQL ORDER BY. You need natural sort but MySQL doesn't support it. That's why you have to make some workarounds on the MySQL query which is a little bit ugly. Or to sort the collection with php natsort(). Or the easiest solution - just add zeros before the numbers (i.e. 1 to become 001).

  • Just tried adding the zeroes. It's a pain, but it works. Thanks! – Larry Dec 31 '14 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.