You are here: Home

How to add a new field for a product in Virtuemart’s back end

Wednesday, 05 December 2012 08:59 Written by  Ed
Rate this item
(4 votes)

Anyone who uses Virtuemart 2 for their joomla ecommerce website has probably come across custom fields for products which are displayed to the user in the front end shop. In this way you can increase the functionality and depth of the Virtuemart core offering. 

Sometimes however it may be necessary to add a product field to Virtuemart’s backend. So that when a product is either added or updated in the administrative back end this new product information can be stored to the database. In this blog post we will run through the process of adding a new field to the products section of the Virtuemart backend.

One of our clients based in Cambridge commissioned us for a web design project. They wanted an ecommerce solution to sell their specialist tablet PCs online. We choose Virtuemart on the Joomla platform to provide the solution. Virtuemart provided most of the product details they required. However they wanted an extra product details field to be added – product specification – basically an extension of the product description. They wanted this to be available in Virtuemart’s backend so when they added new products they could add this new information. The field needed to be separate to the existing fields as we needed to call it through into a tab on the product page.

So how to go about changing Virtuemart’s backend? The first step was to add a new field to the database to contain the new information. We added this field to the xxxxx_products_en_gb table and called it product_specification and gave it a datatype of TEXT.

Next we added some code to the product_edit_description file located in the path /administrator/components/com_virtuemart/views/product/tmpl.
We added the code for the extra field below the code for the product description.

    <legend><?php echo JText::_('COM_VIRTUEMART_PRODUCT_FORM_DESCRIPTION') ?></legend>       

    <?php echo $this->editor->display('product_desc',  $this->product->product_desc, '100%;', '550', '75', '20', array('pagebreak', 'readmore') ) ; ?>



    <legend><?php echo JText::_('Product Specification') ?></legend>       

    <?php echo $this->editor->display('product_specification',  $this->product->product_specification, '100%;', '550', '75', '20', array('pagebreak', 'readmore') ) ; ?>


As you can see we have hardcoded the name to be displayed in Virtuemart’s backend (Product Description) – this is for the sake of clarity, it should ideally be situated as a string in the language file as is done for product description.

Next we have to add the new field to the products.php file in the path /administrator/components/com_virtuemart/tables
var $product_desc            = '';
    /** @var string File specification */
    var $product_specification;
    /** @var int File is an image or other */

Here you can see we have again added it below the product description.

The last step is to add the new field to the product details override file.  This is done in the usual way in the PHP just using the new field name

echo $this->product->product_specification;

I hope this blog post has been interesting/useful – if it has please give it a Google plus! If you have any questions you can either email of comment on this blog.

Last modified on Saturday, 08 December 2012 17:05


Leave a comment

Make sure you enter the (*) required information where indicated.
Basic HTML code is allowed.

Latest from our blog