WSD Posted April 7, 2020 Share Posted April 7, 2020 Hi I have been doing some work on my site over the past few days and have noticed the the products are not displaying in the correct order and need some advice. I have them set up to show in ascending order by product name. However for example I have a listing for a d14 appering above a listing for a d3 part It looks to me like the system is not recognising that its 14 not 1 4 therfore putting the d14 above the d3. Is there anyway to sort this out? Thanks Wil Link to comment Share on other sites More sharing options...
havenswift-hosting Posted April 7, 2020 Share Posted April 7, 2020 34 minutes ago, WSD said: I have a listing for a d14 appering above a listing for a d3 part That is the "correct" sort order as it is done character by character left to right 34 minutes ago, WSD said: Is there anyway to sort this out? Yes - take a look at our enhanced sorting plugin which you can find along with all our other plugins in the extension marketplace here : https://www.cubecart.com/extensions/developer/havenswift-hosting this allow you to specify a custom sort order for products on each category page (as well as adding lots of other possible sorting options) Ian Link to comment Share on other sites More sharing options...
bsmither Posted April 7, 2020 Share Posted April 7, 2020 Not really. Regardless of the length of a string of characters, d1... comes before d3... PHP has the function natsort() which should give you what you want, but that would be PHP's job to work on the recordset fetched from the database. MySQL has no ability to sort in a natural way. Link to comment Share on other sites More sharing options...
bsmither Posted April 7, 2020 Share Posted April 7, 2020 There is a work-around, and requires the data in the column to be formatted in a common pattern. See: https://www.mysqltutorial.org/mysql-natural-sorting/ There would be two parts of the ORDER BY clause: shorter length values (such as 'd7', 'd3') followed by longer length value (such as 'd19', 'd14') would be ordered, then a regular sort. That would produce 'd3', 'd7', 'd14', 'd17', etc. This fails when a value such as 'dd2' is in the list and you want it ahead of 'd3'. Link to comment Share on other sites More sharing options...
WSD Posted April 7, 2020 Author Share Posted April 7, 2020 Ok thanks. Will take a proper look tomorrow. Thats has just fried my tired brain cells tonight Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.