Add a New Field to Products in Joomla! VirtueMart

June 10th, 2008

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.

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

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, {my_publication_date}.

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( "{my_publication_date}", $db_product->f("my_publication_date"), $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.

47 Responses to “Add a New Field to Products in Joomla! VirtueMart”

  1. Pooja says:

    I m really thank full for this article as it helped me in locating where exactly the product insert query is being executed..

    Thanks a lot 🙂

  2. Sheena says:

    You are awesome! This is exactly what I needed. I started trying to track this down myself and realized it could take me all night to figure this out.

  3. Michael says:

    Could you publish your code for the two functions: add() and update() in ps_product.php ?

    My modifications do not seem to work, maybe because of syntax differences between VM 1.0 and 1.1 ?

    Thank you.


  4. Alexwebmaster says:

    Hello webmaster
    I would like to share with you a link to your site
    write me here

  5. Daniel says:

    This tutorial was soooooooooooo helpful. Thank you.
    You mentioned at the bottom that you can display the info in other pages such as the “browse” page.
    I want to do exactly that, but can’t quite get it to work? Which files need to be modified, and what are the mods?
    your help is very appreciated… thank you again for this great tutorial.


  6. Lin says:


    Glad that you found this post helpful.

    I didn’t have chance to try the code out for adding the new field to the browse page, but here is what I think you should do … please post back after you try out and let us know if it works.

    Thanks. — Lin

    There are two files you need to change. Similarly, one is the template page (in the administrator section). In file /administrator/components/com_virtuemart/html/templates/browse/browse_1.php (the browse template you have opted to use, configurable through virtuemart interface), you add the new field display. For example, {my_publication_date} to where you see appropriate.

    Then change file: /administrator/components/com_virtuemart/html/shop.browse.php. You will set the value for the new field here.

    Look for:
    /*** Start printing out all products (in that category) ***/
    while ($db_browse->next_record()) {

    within this while loop, add:
    $my_publication_date = $db_browse->f(“my_publication_date”);

    then look for the code for $product_cell, and add:
    $product_cell = str_replace( “{my_publication_date}”, $my_publication_date, $product_cell );

  7. Stanley says:

    I tried it, but it not works. I have VM 1.1.2
    By adding new product, it wrote that adding was unsuccessfull. And product was not saved.
    By editing existing product it wrote that update was success, but when I reopen same produt, i do not see any changes. My new added field is null.
    I saw into database, and result was the same, my field was null.

    Can anybody help me please ? Thanks

  8. Luc says:


    I was so happy when reading this post, finally I will have an answer to my problem.
    I’ve tried to implement it but unfortunately it doesn’t work 🙁
    When I updade my record manually in the DB, I can retrieve the information in my back office (step 1) but when I want to update it via the back office, I always get an empty value in the record.

    Does somebody had the same problem and solved it?

    thanks for the help.


  9. Lin says:


    I would check the name of the new input box in file: /administrator/components/com_virtuemart/html/product.product_form.php, make sure the name matches the new field as in the SQL statement in the add() and update() in file /administrator/components/com_virtuemart/classes/ps_product.php.

    — Lin

  10. Luc says:

    hello Lin,

    thanks a lot for your quick reply!
    Regarding the product.product_form.php, I’m sure I’m using the right name as the backoffice is showing me the information I encoded manually in the DB.

    Regarding the ps_product.php, I update the Add() and update () sections, by adding in both
    'product_year' => vmRequest::getFloat('product_year'),

    Do I need to update something else?

    thanks again for your reply

  11. Luc says:

    hello Lin

    you were right! in the /administrator/components/com_virtuemart/html/, I didn’t pay attention enough the name attribute!

    So, thank you so much for taking the time to write this procedure. I’ve been searching so much for this, and today I got it .
    All kudos are for you!

    have a nice day

  12. Lin says:

    Thanks Luc for the update and for your kind words. I am glad that it worked for you.

    — Lin

  13. Marco2x says:

    it’s very nice…….
    thx a lot

  14. Thanks for sharing these precious bits of knowlegde !!! Your article has been quite useful. Regards from Italy

  15. Hartmut says:

    thanks for this post. It helped me a lot. All is working for me in the admin area. But it’s not possible for me to get access from the template browsepage. I can get product_weight, product_hight … but not my own fields. I have VM 1.1.3.
    I edited /administrator/components/com_virtuemart/html/shop.browse.php, but /administrator/components/com_virtuemart/html/templates/browse/browse_1.php is not available. My browsepage is in the theme directory.
    Can you please give a hint wehre i can search!
    Regards Hartmut

  16. babycatface says:

    Hi, thank you so much for this hack and I follow you step by step and for the flypage I’ve done something like this

    What I want to achieve is instead of Product Dimension & Weight have Car specifications as is gonna be for a garage. Therefor, as a test, I’ve created product_color in db, and Ive added it to all these files

    Good back and front end, seems that the site transfers the data properly, the big thing is that in the Color field I can only fill with a number, if I enter blue for instance it would come back with 0 (zero).

    In the db have created the field like this:

    product_color varchar(200) utf8_general_ci Yes NULL (actions: primary, index, unique, fulltext all checked).

    Why can I only enter a number value?


  17. Lin says:


    Maybe you can check the add() and update() functions to see if the data type there for the new fields was correct … if need further help, please feel free to post your SQL statement here.


    — Lin

  18. Lin says:


    I don’t think that I have VM 1.1.3. I will try to find the answers for you and post here if I could. If you find the answers, please post as well.


    — Lin

  19. K says:

    Hey there,

    Great blog – really helpful. I was just curious, I have done your fix, but have a CSV file I’m trying to import with CSV Improved – it doesn’t recognise my new fields as available fields ??

    Anythoughts you might could share ?

    Thanks for your post

  20. Germain says:


    I found those information very interresting, but I’m a bit lost.
    I’ve done most of the things explained here, but I’m not sure where to update the add() and update().

    It would be very kind of you if you could take some time to explain me or give me an even more detail tutorial.



  21. theresa says:

    These functions are not in /administrator/components/com_virtuemart/classes/ps_product.php:
    add() and update() … I try to search for them in all files and can’t find add() or update() … I am using 1.1.4 version. So, I am lost like Germain …. any help much appreciated

  22. goyo says:

    Wonderful help…

    Much appreciated!

  23. Arsalan says:


  24. Bart says:

    This help did save me a lot of time sofar, but do I overlook something?
    I could create some extra product fields. insert/update in database works fine.
    I did adjust the flypage so the extra fields will show, but they don’t.
    I’m using VM 114. Can anyone help me with the last step?

    Kind regards,

  25. web designer says:

    If someone creates and extension for VM that does this it will be fantastic. I can see use for something like this beyond regular e-commerce.
    Simply using the the cataloging function alone, you can turn it into something useful for other verticals like real estate, auto etc..


  26. Garfield says:

    Hey I was wondering if anyone was successful in getting the new filed to publish on the product listing and product detail views.

    If so, can you provide some insight as to how it’s done.

  27. zaheer abbas says:

    Really good yar

  28. zaheer abbas says:

    Really good yar dfasdfasdf

  29. Martin says:

    Thanks a million! You saved me the effort of finding where the add and updates were done!

  30. kol says:

    This blog article sounds really good. I’ve wanted to add couple of fields for sometime now. Finally found your article.

    Will implement it and if it works i’ll be jumping up and down.

    Many thanks.

  31. John says:

    Data is in the database and it will not show up.

    VirtueMart 1.1.5


    This is what I added
    $tpl->set( “show_date”, $show_date );

  32. John says:

    This is what I added

    $productArray[“show_date”] = $show_date; //not sure if I needed that.
    $tpl->set( “show_date”, $show_date );


  33. bojnin says:

    Thank you so much !

    Well written and efficient.

    You made my morning !

  34. Satya says:

    Hi thank you very much for great help! if anyone can explain how to print reports in Inventory section with required fields in VM will be great!

  35. Clonidine Illegal Drugs – nolvadex online
    Doctors usually take great care in prescribing Novaldex because they know that it can cause some serious side effects cannot be ignored. [url=]nolvadex 20mg[/url]

  36. Prashesh says:

    For those who have faced problem to display newly added field on product details page, I have solution. I have successfully display my new field by add below code into your flypage.

    (in reference of above article)

    I have used Virtuemart version 1.1.6

  37. Prashesh says:

    For those who have faced problem to display newly added field on product details page, I have solution. I have successfully display my new field by add below code into your flypage.

    echo $nc_product_new_field;

    (in reference of above article)

    I have used Virtuemart version 1.1.6

  38. Dallas says:

    I know this is an old post but most of it still applies, however, in Vmart 1.1.9 this file no longer exists: /administrator/components/com_virtuemart/html/templates/product_details/flypage.php

    I have done the other steps and added to my flypage but it doesn’t yet work. Can anyone tell me what is different for v1.1.9?

  39. Guert says:

    wow thank you for such a nice post…. i really close to my goal, maybe you can still help me:

    i want to sell airtime.


  40. Nick says:

    Hey I am having the same problem also in VM 1.1.8.

    The flypage.php file not appear in the administrator area. Perhaps the “the field display” that is supposed to be added in this none-existent file should be added elsewhere in the administrator area?

    Please help. Thanks!

  41. Nick says:

    Found solution with missing flypage.php in admin section of VM!

    Since /administrator/components/com_virtuemart/html/templates/product_details/flypage.php doesn’t exists anymore in these latest versions, ignore this edit.

    Change $template = str_replace( “{my_publication_date}”, $db_product->f(“my_publication_date”), $template );
    $tpl->set(‘my_publication_date’, $my_publication_date);

    …and then you can add this to the flypage in the components->virtuemart->themes->flypage you are using section.
    echo $my_publication_date;

    This is for VM 1.1.8 and later (possibly earlier versions).

  42. Gina says:

    This article was a LIFESAVER! I have been struggling with a work around to this very problem that used the custom attributes field. It was not working very well. This is working perfectly! Thank you, Thank you, Thank you!

  43. Caroline says:

    This was extremely helpful. Thank you very much!

    I don’t suppose you have any idea how to build a search form that searches on these new fields do you?!

  44. Yan says:

    Hi !

    This is very great, I just add a technical description for my product table.

    If you know about how to make a quick order form to let the customer quick add the product to their cart.

    let me know , thank very much !

  45. 5j7Eeg says:

    588199 983911I notice there is surely lots of spam on this weblog. Do you need to have support cleaning them up? I may possibly support between courses! 77832

  46. ent says:

    is there a tutorial for v 2.x

Please add your comment