VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: kaistudios on March 07, 2016, 21:27:51 PM

Title: sort by stock
Post by: kaistudios on March 07, 2016, 21:27:51 PM
Hello,

I'm trying to get the products in the front end sorted by in stock but I get out of stock products mixed in mostly towards the end of the list.
by availability is mixed up even more.
I could use bty sorting and just do it manually but that's time consuming the stock changes frequently on too many products.
anybody else experienced this? thank you
Title: Re: sort by stock
Post by: Studio 42 on March 08, 2016, 01:22:45 AM
You can set in VM>Configuration> Product Order Settings :
  Default product sort order : Product in stock
  Available Sort-by fields : Product in stock
This is then ordered by stock, but this not count pending product in order.
Title: Re: sort by stock
Post by: kaistudios on March 10, 2016, 00:11:07 AM
Quote from: Studio 42 on March 08, 2016, 01:22:45 AM
You can set in VM>Configuration> Product Order Settings :
  Default product sort order : Product in stock
  Available Sort-by fields : Product in stock
This is then ordered by stock, but this not count pending product in order.

Hello I wrote above that I did this already but it doesn't work. still I see out of stock products mixed in with the in stock items.
Title: Re: sort by stock
Post by: GJC Web Design on March 10, 2016, 00:26:42 AM
Action when a Product is Out of Stock -> Do not Display Product   ????
Title: Re: sort by stock
Post by: kaistudios on March 10, 2016, 02:53:33 AM
Quote from: GJC Web Design on March 10, 2016, 00:26:42 AM
Action when a Product is Out of Stock -> Do not Display Product   ????
thank you but unfortunately they want the out of stock products to show on the site with the ability to have a notify list. you know which site i'm talking about you can see what i mean ...
Title: Re: sort by stock
Post by: GJC Web Design on March 10, 2016, 11:35:43 AM
hmmm.. where do u want the out of stock to appear?  at the bottom?

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

have a look in the model products.php the query for stock to test this theory
Title: Re: sort by stock
Post by: kaistudios on March 10, 2016, 19:58:11 PM
Quote from: GJC Web Design on March 10, 2016, 11:35:43 AM
hmmm.. where do u want the out of stock to appear?  at the bottom?

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

have a look in the model products.php the query for stock to test this theory
They want out of stock products to appear at the end of the list after the in-stock products. from what I understand sort by 'availability' should be the correct choice for that so it reflects booked orders as well but that doesn't work for me either. totaly out of stock product with 0 stcok get mixed in still. it does happen after the first few rows but i dont think there is a certain patern i could point to
will look into model products.php to try different things thank you
Title: Re: sort by stock
Post by: GJC Web Design on March 10, 2016, 23:05:50 PM
yes.. but stock can also be -1, -2 etc

or are they all definitely 0?
Title: Re: sort by stock
Post by: kaistudios on March 11, 2016, 04:59:43 AM
yes they are all definitely zero. no back orders. just notify list. and very high stock change rate
Title: Re: sort by stock
Post by: GJC Web Design on March 11, 2016, 11:59:50 AM
then to solve this u need to dig into the actual queries of models product.php
Title: Re: sort by stock
Post by: Studio 42 on March 11, 2016, 13:34:35 PM
add a vmDebug or any var_dump and check the current query and result, when you use order by stock, so you see why the result is bad.
Title: Re: sort by stock
Post by: lindapowers on March 15, 2016, 01:41:54 AM
We tried doing the same but never managed to order them automatically in the desired way.

If you use child products only the parent is counted for ordering so we ended up doing it manually.
Title: Re: sort by stock
Post by: el02154 on August 09, 2022, 09:04:41 AM
Hello all,

I have exact the same problem in multiple sites. I want to sort the products based on availability but it is not working. I have tried lots of things, even disable the template but the problem still happens. For example you can see site ddc.gr. Is there anyone who can help? Does anyone face the same problem?
Title: Re: sort by stock
Post by: el02154 on August 16, 2022, 13:19:20 PM
Does anyone have the same issue?
Title: Re: sort by stock
Post by: 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.
Title: Re: sort by stock
Post by: 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?
Title: Re: sort by stock
Post by: 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
Title: Re: sort by stock
Post by: ashishgupta09229 on September 16, 2022, 15:09:18 PM
I can only assume the query is using say a stock of -3, -4 etc as a positive integer?




Title: Re: sort by stock
Post by: el02154 on September 18, 2022, 14:59:28 PM
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?
Title: Re: sort by stock
Post by: Milbo on October 02, 2022, 23:59:31 PM
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