News:

Looking for documentation? Take a look on our wiki

Main Menu

Can I override products.php (or extend it's variables somehow)?

Started by OriyanJ, January 27, 2016, 15:08:31 PM

Previous topic - Next topic

OriyanJ

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

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

AH

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
Regards
A

Joomla 4.4.5
php 8.1

OriyanJ

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

Customfields have their uses

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

Joomla 4.4.5
php 8.1