Author Topic: Can I override products.php (or extend it's variables somehow)?  (Read 1417 times)

OriyanJ

  • Jr. Member
  • **
  • Posts: 83
  • A beginner
Can I override products.php (or extend it's variables somehow)?
« on: January 27, 2016, 15:08:31 pm »
VirtueMart 3.0.12

WHAT I NEED TO ACCOMPLISH?
I'd like to add new variables to the product's class, I've noticed that administrator\components\com_virtuemart\tables\products.php extends VmTable and I'd like to know if there's any way I can add my own variables by override or extending it while they'll be safe from VirtueMart updates.

WHY?
I've added new database fields to the product's table and at VirtueMart's back-office.
VirtueMart 3.2.2

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10415
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Can I override products.php (or extend it's variables somehow)?
« Reply #1 on: January 27, 2016, 16:15:56 pm »
Don't think so.. why did u not use custom fields?

or maybe unused current fields?
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

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3510
  • VirtueMart Version: 3.8.9
Re: Can I override products.php (or extend it's variables somehow)?
« Reply #2 on: January 27, 2016, 17:47:04 pm »
Quote
WHAT I NEED TO ACCOMPLISH?
I'd like to add new variables to the product's class, I've noticed that administrator\components\com_virtuemart\tables\products.php extends VmTable and I'd like to know if there's any way I can add my own variables by override or extending it while they'll be safe from VirtueMart updates.
Code: [Select]
WHY?
I've added new database fields to the product's table and at VirtueMart's back-office.

Yes you can add your variables to products.php if you like,  that is the joy of open source!

Add them after:-

Code: [Select]
/** @var int published or unpublished */
var $published = 1;

and before:-

Code: [Select]
function __construct($db) {

Quote
they'll be safe from VirtueMart updates

You will have to re-apply your changes to this file after every VM update as the code changes will be overwritten.

I have my own set of around 10 fields that I "manage" in this manner - updates have never affected them in the database - Give them some unique field prefix just to make sure!


You should then add some overrides to the product admin template to allow these variables to be seen/adjusted:-

I would put them in their own tab:-


To add a new tab

Edit this file:-

administrator\templates\isis\html\com_virtuemart\product\product_edit.php

Add the new tab name and the file it should open.

Code: [Select]
$tabarray['mynewstuff'] = 'MY new stuff'; //added by you
To get the new stuff into that tab

Create yourself the file to load the new fields - using the "mynewstuff" example from above, the file will be named:-

administrator\templates\isis\html\com_virtuemart\product\product_edit_mynewstuff.php


Then add your data to this tab  (follow the example of one of the existing tabs)


To get at your new  variables in the front end:

$this->product->your_new_field
Regards
A

Joomla 3.9.27
php 7.4

OriyanJ

  • Jr. Member
  • **
  • Posts: 83
  • A beginner
Re: Can I override products.php (or extend it's variables somehow)?
« Reply #3 on: January 28, 2016, 08:05:36 am »
Well, GJC Web Design, custom field are a real pain in the ass. I wont be the only administrator working with VirtueMart and I want it to be simple and easy. I appreciate your reply, you help me with almost every topic I open :)
And thanks AH, I've already done that, just thought there's a way to override/extend the product's variables without concerns. Guess that's impossible.
VirtueMart 3.2.2

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3510
  • VirtueMart Version: 3.8.9
Re: Can I override products.php (or extend it's variables somehow)?
« Reply #4 on: January 28, 2016, 10:11:56 am »
Customfields have their uses

But "adding" to the product database is sometimes the optimal solution :-)
Regards
A

Joomla 3.9.27
php 7.4