Y
Y
Yuri Gubkin2015-09-18 13:40:28
MySQL
Yuri Gubkin, 2015-09-18 13:40:28

How to sort by SKU (sku) in Opencart?

In the database, the SKU field has the varchar type, so sorting by article does not work correctly:
1,10,11,2,20,21
How to sort the article as a number?
1,2,10,11,20,21
Which query in /catalog/model/catalog/product.php should be changed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Gubkin, 2015-09-19
@uraaa

I figured it out for those who are interested:
On 1.5.3.1
File /catalog/model/catalog/product.php
In this condition:
Add:

elseif ($data['sort'] == 'p.sku') {
         $sql .= " ORDER BY CAST(" . $data['sort'] . " as unsigned)";
        }

M
Max, 2015-09-18
@MaxDukov

instead of ORDER BY xxx
ORDER BY CAST(xxx AS SIGNED)
or ORDER BY xxx+0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question