Post by Rytis » Tue Jun 11, 2013 12:09 am

Hello,
I wonder if there is any way to show out of stock items at the end of category?

Newbie

Posts

Joined
Sat Jul 25, 2009 1:12 am

Post by Rytis » Wed Jun 12, 2013 11:27 pm

There should be way... Bumping

Newbie

Posts

Joined
Sat Jul 25, 2009 1:12 am

Post by ogun » 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.

Active Member

Posts

Joined
Tue Aug 14, 2007 6:04 am

Post by drakas » Tue Jun 18, 2019 11:55 pm

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?

Newbie

Posts

Joined
Sun Mar 13, 2016 4:14 pm

Active Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm

Post by drakas » Sat Jun 22, 2019 3:49 am

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.

Newbie

Posts

Joined
Sun Mar 13, 2016 4:14 pm

Post by xxvirusxx » Sat Jun 22, 2019 3:54 am

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

My Extensions | OC 3.0.3.1, 3.0.2.0, 2.3.0.2 with bugs fixed | 2.3.0.2 Custom version | Buy me a beer or coffee


Active Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Who is online

Users browsing this forum: Bing [Bot] and 88 guests