Page 1 of 1

Display out of stock items at the end of category

Posted: Tue Jun 11, 2013 12:09 am
by Rytis
Hello,
I wonder if there is any way to show out of stock items at the end of category?

Re: Display out of stock items at the end of category

Posted: Wed Jun 12, 2013 11:27 pm
by Rytis
There should be way... Bumping

Re: Display out of stock items at the end of category

Posted: Thu Jun 13, 2013 5:10 pm
by ogun
Have you tried searching the forums or looking at the code itself?

Only spent a few minutes on this, so there might be a more sensible place to make the edit, or this edit might be a bad one, but I gave it a very quick test and it seemed to work (only tried the first part of the IF, it would be easy enough to modify the other parts):

Code: Select all

if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
        if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
                // Original
                // $sql .= " ORDER BY LCASE(" . $data['sort'] . ")";
                // Quantity
                // $sql .= " ORDER BY IF(quantity<1,1,0),LCASE(" . $data['sort'] . ")";
                // Stock status
                $sql .= " ORDER BY CASE
                        WHEN stock_status_id = 7 THEN 0 -- In Stock
                        WHEN stock_status_id = 8 THEN 1 -- Pre-order
                        WHEN stock_status_id = 6 THEN 2 -- 2 - 3 Days
                        WHEN stock_status_id = 5 THEN 3 -- Out of Stock
                END,LCASE(" . $data['sort'] . ")";
        } elseif ($data['sort'] == 'p.price') {
                $sql .= " ORDER BY (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)";
        } else {
                $sql .= " ORDER BY " . $data['sort'];
        }
} else {
        $sql .= " ORDER BY p.sort_order";        
} 
The problem with sorting by a product's stock status is that stock status can have multiple values, so you'll need to decide what order you want all of them to appear in - and to remember to update the script if you ever modify the available stock status options.

Re: Display out of stock items at the end of category

Posted: Tue Jun 18, 2019 11:55 pm
by drakas
ogun wrote:
Thu Jun 13, 2013 5:10 pm
Have you tried searching the forums or looking at the code itself?

Only spent a few minutes on this, so there might be a more sensible place to make the edit, or this edit might be a bad one, but I gave it a very quick test and it seemed to work (only tried the first part of the IF, it would be easy enough to modify the other parts):

Code: Select all

if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
        if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
                // Original
                // $sql .= " ORDER BY LCASE(" . $data['sort'] . ")";
                // Quantity
                // $sql .= " ORDER BY IF(quantity<1,1,0),LCASE(" . $data['sort'] . ")";
                // Stock status
                $sql .= " ORDER BY CASE
                        WHEN stock_status_id = 7 THEN 0 -- In Stock
                        WHEN stock_status_id = 8 THEN 1 -- Pre-order
                        WHEN stock_status_id = 6 THEN 2 -- 2 - 3 Days
                        WHEN stock_status_id = 5 THEN 3 -- Out of Stock
                END,LCASE(" . $data['sort'] . ")";
        } elseif ($data['sort'] == 'p.price') {
                $sql .= " ORDER BY (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)";
        } else {
                $sql .= " ORDER BY " . $data['sort'];
        }
} else {
        $sql .= " ORDER BY p.sort_order";        
} 
The problem with sorting by a product's stock status is that stock status can have multiple values, so you'll need to decide what order you want all of them to appear in - and to remember to update the script if you ever modify the available stock status options.
hello, does this work on v2.1.0.1? where it needs to be placed?

Re: Display out of stock items at the end of category

Posted: Fri Jun 21, 2019 9:14 pm
by xxvirusxx

Re: Display out of stock items at the end of category

Posted: Sat Jun 22, 2019 3:49 am
by drakas
xxvirusxx wrote:
Fri Jun 21, 2019 9:14 pm
You want something like this?
https://www.opencart.com/index.php?rout ... n_id=23095
Hello, no, I want to sort catalog by product_stock_id where all products out of stock will be at the end, then 15days, then preorder and at the top in stock products.

Re: Display out of stock items at the end of category

Posted: Sat Jun 22, 2019 3:54 am
by xxvirusxx
So you just post in another topic with title...Display out of stock items at the end of category and you want something else....
Next time don't post in another topic if isn't that you need.

Try to post on Commercial section and pay a developer.
viewforum.php?f=88