VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: bbff on March 20, 2017, 16:07:38 PM

Title: How to sum the stock of the products in a category
Post by: bbff on March 20, 2017, 16:07:38 PM
The subject says it all. I want to sum the stock of the products in a category. For example, imagine a category with 2 products, where the stock of each is 3 and 4. I want to make a function in php where it returns 7. Can anyone help me with this?

Thank you!!
Title: Re: How to sum the stock of the products in a category
Post by: GJC Web Design on March 21, 2017, 00:41:45 AM
it is just a query..  query the stock cumulatively from a certain catid..

but you don't explain where or why or when u want this...
Title: Re: How to sum the stock of the products in a category
Post by: Studio 42 on March 21, 2017, 09:38:52 AM
Stock value is in product table, but the problem you have is when you have more then pagination limit, in this case you need to write own DB query.
To get total per product, it's product_in_stock - product_ordered.
If you want filter all product in one category you need to join the product_category table and check for virtuemart_category_id.
Without more information, we cannot help you more. But you have no existing function in virtuemart to do this.
Title: Re: How to sum the stock of the products in a category
Post by: bbff on March 21, 2017, 12:06:29 PM
In my website, I use the stock value to represent the rating of each product. For example, if a product has in stock 3, then it will be displayed an image with 3 stars. I created this thread so that I can get the average rating in a category. So, if a category has 2 products, each has in stock 3 and 4, then the category rating overall is 3,5 stars. I know it's a little farfetched, but it has been working. I'm going to try your tips! Thank you