Products sorting on product listing

  • Posts: 1119
  • Thank you received: 114
5 years 5 months ago #300291

Hi,

It could be that this was answered but couldn't find any topic which will answer my question.

Is there a way to sort out of stock products to the end of the product listing?
What we would like is to show newest first and out of stock at the end. Cause now to put out of stock products to the end is only possible using product quantity in ordering field settings via menu.

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 81484
  • Thank you received: 13062
  • MODERATOR
5 years 5 months ago #300296

Hi,

There is no option for that. However, there is an options in the listing menus/modules to not display on the listings the products without stock. The product pages will still be online though (so if someone searches for the product through google it will still find them).
Now you can also write a small plugin and implement in it the onBeforeProductListingLoad trigger:
www.hikashop.com/support/documentation/6...reProductListingLoad
with the $order variable you can modify the sorting done in the MySQL query loading the products.

Please Log in or Create an account to join the conversation.

  • Posts: 1119
  • Thank you received: 114
5 years 4 months ago #301452

Hi,

I am now thinking to look into plugin. The only concer that i am not sure how should i go about products filtering. Basically we need to put all out of stock products to the end even after filtering. As example if filter by price, out of stock products still should go to the end...

How should we go about that?

Also any quick example would be really welcome.

Thank you

Last edit: 5 years 4 months ago by kyratn.

Please Log in or Create an account to join the conversation.

  • Posts: 81484
  • Thank you received: 13062
  • MODERATOR
5 years 4 months ago #301462

Hi,

Well, it's not as easy as I though, It would first require to change the $select variable to calculate whether the product has stock or not as a new column so that you could apply the sorting on it. Otherwise, if you apply the sorting directly on the product_quantity column, it will just order the products based on the stock and that's not what you want.
So it's possible with a plugin, but it will require a bit more work. I would recommend to hire a developer to work on that.
Basically, as a developer, you want to var_dump the content of the different variables of that function, and get the whole MySQL query from the debug data at the bottom of the page when you activate the debug setting of the Joomla config.
Then, you want to change the $order variable like that:
$order = 'alias_column ASC, '.$order;
and you want to change the $select variable to calculate the "alias_column to be 0 or 1 based on the product_quantity column with a "case": dev.mysql.com/doc/refman/5.7/en/case.html

Please Log in or Create an account to join the conversation.

Time to create page: 0.060 seconds
Powered by Kunena Forum