VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: OriyanJ on January 27, 2016, 15:08:31 PM

Title: Can I override products.php (or extend it's variables somehow)?
Post by: OriyanJ 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.
Title: Re: Can I override products.php (or extend it's variables somehow)?
Post by: GJC Web Design on January 27, 2016, 16:15:56 PM
Don't think so.. why did u not use custom fields?

or maybe unused current fields?
Title: Re: Can I override products.php (or extend it's variables somehow)?
Post by: AH on January 27, 2016, 17:47:04 PM
QuoteWHAT 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.


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

Add them after:-

/** @var int published or unpublished */
var $published = 1;


and before:-

function __construct($db) {


Quotethey'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.

$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
Title: Re: Can I override products.php (or extend it's variables somehow)?
Post by: OriyanJ 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.
Title: Re: Can I override products.php (or extend it's variables somehow)?
Post by: AH on January 28, 2016, 10:11:56 AM
Customfields have their uses

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