Jump to content

How to make in stock product show in first and then out of stock


mehdi.7618

Recommended Posts

I apologize for writing poorly in English,

I want to sort products in category in any type (date, name and price) accordingly:

First display the in-stock products, and then the not-in-stock products. Of course, I also edited the Category.php Class, but it didn't work again.

which code (class) must be change for category?

Thank you for your help.
 

Link to comment
Share on other sites

You have to write the PrestaShop version and write where you want to filter it.
If you want to add a filter to the category page in frontoffice.

 

Link to comment
Share on other sites

11 hours ago, Guest said:

You have to write the PrestaShop version and write where you want to filter it.
If you want to add a filter to the category page in frontoffice.

 

I want sort products in prestashop 1.6 , for example when sort by price lowest first click , products instock show first and then show outStock products

i try change category.php (getProducts()) with use sql command "case when" in order by, but not effect in sort products

I want to know which code I need to change, just one guide is enough

thank you

 

Untitled.jpg

Link to comment
Share on other sites

35 minutes ago, Guest said:

Ok, read this forum.

 

Thanks , but this not solution

if change getProducts() function to getProducts111() , category loaded without any problem, so not need this function (getProducts() only sort another products list as related products)

witch class and function related to category products sort (products in category), i cant find any solution for this problem

Link to comment
Share on other sites

add new order_by:

$order_by .= ', stock.quantity DESC';

$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) AS quantity'.(Combination::isFeatureActive() ? ', IFNULL(product_attribute_shop.id_.................

 

Link to comment
Share on other sites

1 hour ago, Guest said:

add new order_by:


$order_by .= ', stock.quantity DESC';

$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) AS quantity'.(Combination::isFeatureActive() ? ', IFNULL(product_attribute_shop.id_.................

 

thank you

where write this code, classes/category.php not effected  on category front page

same as:

sort-products-in-stock-first

Edited by mehdi.7618 (see edit history)
Link to comment
Share on other sites

I see that you probably don't understand SQL queries and PHP at all.
It's not enough to copy something somewhere.

Adding a condition to an SQL query is no problem.
You can also save an SQL query that will be processed and see how ORDER BY works.

This piece of code adds ORDER BY = bqSQL ($ order_by) and pSQL ($ order_way) = DESC or ASC to the SQL query.
DECS = from Z to A (999 to 0), ASC = from A to Z (0 to 999).
So you change this part of the code.

Original:

if ($random === true) {
            $sql .= ' ORDER BY RAND() LIMIT '.(int)$random_number_products;
        } else {
            $sql .= ' ORDER BY '.(!empty($order_by_prefix) ? $order_by_prefix.'.' : '').'`'.bqSQL($order_by).'` '.pSQL($order_way).'
			LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;
        }

 

Replace:

$my_order_by = ',stock.quantity DESC'; 

if ($random === true) {
            $sql .= ' ORDER BY RAND()'.$my_order_by.' LIMIT '.(int)$random_number_products;
        } else {
            $sql .= ' ORDER BY '.(!empty($order_by_prefix) ? $order_by_prefix.'.' : '').'`'.bqSQL($order_by).'` '.pSQL($order_way).$my_order_by.' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;
        }

 

Edited by Guest (see edit history)
Link to comment
Share on other sites

@mehdi.7618,

i've restored this thread.

All threads in this forum should be a kind of "reference book" for other users with same or similar problems.

It's not a good behavior to hide a finished thread!

regards
Whiley

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...