Author Topic: Calculate data once, use site wide  (Read 100 times)

sandomatyas

  • Jr. Member
  • **
  • Posts: 233
Calculate data once, use site wide
« on: November 10, 2018, 21:49:57 pm »
There is a VirtueMart based site where I need some information about the products which are collected from VM's tables and other external tables/files aswell. These are some pieces of related metadata information and not just the products. E.g: date interval of weekly sales, categories/products which are included in the sale, discount percentage, etc etc. Some of them are not directly connected to VM but I need to display it.
I need these information site-wide like in category view, productdetails view, cart, order emails, some modules or vmcustom plugins, etc.

So the question: What is the best way to collect the information once per pageload (or perhaps per session) but use it in several parts of the site? I want to do this mainly for performance reasons and of course for a more clear code.

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8434
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.14
Re: Calculate data once, use site wide
« Reply #1 on: November 11, 2018, 10:35:54 am »
something like your own plugin with its own table then fetch/call these values and display
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
  • Sr. Member
  • *
  • Posts: 3468
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Calculate data once, use site wide
« Reply #2 on: November 11, 2018, 12:48:07 pm »
You can use Joomla cache as base, you can use it to cache HTML or code(json object, db results for eg.) or use a file cache.
If you need it per pageload, then you can use a static value or array in a class using an instance Id.