4

I've bunch of products, Which names start with word "Bai" and afterwards some digits.

Like, Bai-10, Bai-11, Bai-15 etc.

I've set Default product listing sort by to "use config setting" and at global level I've set it to "Product Name".

When I visit category page, I can see something like this.

enter image description here

Take a look at second row after Bai-10, Bai-14 should come but Bai-103 comes up.

Has anybody faced this type of issue ? Looks like its small thing but I'm not getting it.

Any help would be really appreciated.

1
  • please reindexing and flush caching after check and also check Log File. Nov 27, 2019 at 9:41

1 Answer 1

3

That is lexicographic sorting which means basically the language treats the variables as strings and compares character by character "200" is greater than "19999" because '2' is greater than '1'. So in your case Bai-10, Bai-103, then Bai-14 because of Bai-10 is common and then again sorting is check so 0 (03 Bai-103) is come before (4 Bai-14).

The sorting is strictly alphabetical (and happens left-to-right, one character at a time): 1, 2, 10 makes sense to you but not to a computer that only knows alphabetic comparison. There's no way in that kind of simple comparison to know that a one followed by a 0 actually comes after a four.

2
  • 1
    nice answer.!!!! keep posting answer bro..! Nov 27, 2019 at 9:48
  • I would suggest parsing the sort field into two separate ones. The first, obviously alphabetical, the second, numerical, preferably integer based. Nov 27, 2019 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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