News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

sort by stock

Started by kaistudios, March 07, 2016, 21:27:51 PM

Previous topic - Next topic

el02154

Quote from: Kuubs on August 22, 2022, 10:22:53 AM
I think you can make a custom sort function and sort using usort. It's not the most ideal situation, because ideally you want to do this with the query, but with usort you can sort he products in your template override.

Do you know which core file I have to change in order to achieve this?

Kuubs

Quote from: el02154 on September 02, 2022, 09:41:29 AM
Quote from: Kuubs on August 22, 2022, 10:22:53 AM
I think you can make a custom sort function and sort using usort. It's not the most ideal situation, because ideally you want to do this with the query, but with usort you can sort he products in your template override.

Do you know which core file I have to change in order to achieve this?

you can make a template override, for example the category page. and you cahgne the products.php sublayout to sort your array of products before you render them

ashishgupta09229

#17
I can only assume the query is using say a stock of -3, -4 etc as a positive integer?





el02154

Quote from: Kuubs on September 09, 2022, 15:44:33 PM
Quote from: el02154 on September 02, 2022, 09:41:29 AM
Quote from: Kuubs on August 22, 2022, 10:22:53 AM
I think you can make a custom sort function and sort using usort. It's not the most ideal situation, because ideally you want to do this with the query, but with usort you can sort he products in your template override.

Do you know which core file I have to change in order to achieve this?

you can make a template override, for example the category page. and you cahgne the products.php sublayout to sort your array of products before you render them

Hello, this is what I am trying to do but I am struggling to grab all producys before pagination. Any ideas how to grab all products and not only the ones of the current pagination page?

Milbo

#19
If you want to add your own search, then you can use 2 triggers. So a plugin is the right way to go, it is mainly a "hello world" plugin with one trigger.

so very simple to write. overtake the query completly with plgVmMySortSearchListProductsQuery or modify the existing query with plgVmBeforeProductSearch

But I think your code is interesting for the general core. Search for the line if(VmConfig::get('stockhandle_products',false)){ or in general for stockhandle_products in the product model.

Maybe you find a fix for the problem, than we can just add it to the core. Maybe just as new option of stockhandle_products
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/