Add a New Field to Products in Joomla! VirtueMart

Out of box, VirtueMart products have many “fields”, product name, sku, price, etc. If you need an additional field or two for your own business needs, you can do that by changing data model as well as some php code. It’s a bit of work … hope this post can help save you some time and effort.

Modify Data Model

First, data model needs to be modified to add the column. If you used the default prefix, the sql command will be something like:

alter table jos_vm_product add (
nc_product_new_field varchar(200) null
);

It’s best to name the new field with your own fix so down the road you can easily remember that it’s your field, not what comes with VirtueMart.

Admin Interface

File: /administrator/components/com_virtuemart/html/product.product_form.php

This is where the product add/edit form is coded. Find a place for your new field, and add the form input.

<tr>
<td>
<div style="text-align:right;font-weight:bold;">
CK Publication Date: (yyyy-mm-dd)
</div>
</td>
<td width="79%">
<input type="text" class="inputbox" name="ck_publication_date" value="<?php $db->sp("ck_publication_date"); ?>" size="32" maxlength="255" />
</td>
</tr>

Product Class

Most files of VirtueMart component is defined in the administrator section. In file /administrator/components/com_virtuemart/classes/ps_product.php

Modify two functions: add() and update(). Make sure the new field is included in the SQL statement.

At this point, you can add new product with this additional field and also modify the new field using VirtueMart administrator interface. Now, you will need to modify the front-end product details page to display the new field.

Product Details Page

There are two files you need to change. One is the template page. (Again, this file is in the administrator section.) In file /administrator/components/com_virtuemart/html/templates/product_details/flypage.php, you add the new field display. For example, {nc_product_new_field}.

Also you need to change file: /administrator/components/com_virtuemart/html/shop.product_details.php. You will set the value for the new field here.

$template = str_replace( "{product_weight}", $db_product->f("nc_product_new_field"), $template );

What Else?

If you like to display the new field in the browse page, etc. just find the right template as well as the corresponding php page to pull out value for the template.

Social Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Webnews
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • TwitThis
RSS 2.0 | Trackback | Comment

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>