Author Topic: How to sum the stock of the products in a category  (Read 96 times)

bbff

  • Beginner
  • *
  • Posts: 2
How to sum the stock of the products in a category
« 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!!

GJC Web Design

  • 3rd party VirtueMart Developer
  • Hero Member
  • *
  • Posts: 7279
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.0.16
Re: How to sum the stock of the products in a category
« Reply #1 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...
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Studio 42

  • Contributing Developer
  • Full Member
  • *
  • Posts: 2070
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: How to sum the stock of the products in a category
« Reply #2 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.

bbff

  • Beginner
  • *
  • Posts: 2
Re: How to sum the stock of the products in a category
« Reply #3 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