News:

Support the VirtueMart project and become a member

Main Menu

How to sum the stock of the products in a category

Started by bbff, March 20, 2017, 16:07:38 PM

Previous topic - Next topic

bbff

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!!

GJC Web Design

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...
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Studio 42

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.

bbff

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