VirtueMart 1.1.x [ Old version - no longer supported ] > Frequently Asked Questions VM 1.1

Guide:How to add new field in admin panel/VirtueMart/article

(1/1)

Ventsi Genchev:
How to add new field after field SKU: in VirtueMart admin panel / Products (look attached picture)? It's very easy.  :wink:

1. Create new field in database / table jos_vm_product (for example by phpMyAdmin). In the example I will call my_code. If you choose any other name, change it everywhere in the codes listed below.

2. For this field to visualize, in administrator / components / com_virtuemart / html / change file product.product.form.php

After:

--- Code: (text) ---    <tr class="row1">
      <td width="21%" ><div style="text-align:right;font-weight:bold;"><?php echo $VM_LANG->_('PHPSHOP_PRODUCT_FORM_SKU') ?>:</div>
      </td>
      <td width="79%" height="2">
        <input type="text" class="inputbox"  name="product_sku" value="<?php $db->sp("product_sku"); ?>" size="32" maxlength="64" />
      </td>
    </tr>
--- End code ---
Insert:

--- Code: (text) ---    <tr class="row1">
      <td width="21%" ><div style="text-align:right;font-weight:bold;"><?php echo $VM_LANG->_('PHPSHOP_PRODUCT_FORM_MY_CODE') ?>:</div>
      </td>
      <td width="79%" height="2">
        <input type="text" class="inputbox"  name="my_code" value="<?php $db->sp("my_code"); ?>" size="32" maxlength="64" />
      </td>
    </tr>
--- End code ---

3. To enable this field to update with database, in administrator / components / com_virtuemart / classes / change file ps_product.php in two places.

3.1 In function:
    * Function to add a new product into the product table

After:

--- Code: (text) ---        // Insert into DB
      $fields = array ( 'vendor_id' => $vendor_id,
      'product_parent_id' => vmRequest::getInt('product_parent_id'),
      'product_sku' => vmGet($d,'product_sku'),
--- End code ---
Insert:

--- Code: (text) ---                'my_code' => vmGet($d,'my_code'),
--- End code ---

3.2 And do the same in function:
    * Function to update product $d['product_id'] in the product table

4. To fix the name of the field, in administrator / components / com_virtuemart / languages / product / change file english.php

After:

--- Code: (text) ---   'PHPSHOP_PRODUCT_FORM_SKU' => 'SKU',
 
--- End code ---
Insert:

--- Code: (text) ---   'PHPSHOP_PRODUCT_FORM_MY_CODE' => 'MY CODE',
 
--- End code ---

We already have a new field in which change is recorded in the database. You can include a template for the CSV Improved import / export data.


Little extras and additions:

1. If you want this field to be included in the search engine in the admin panel with a list of products, in administrator / components / com_virtuemart / html / change file product.product.list.php

After:

--- Code: (text) ---$search_sql .= "#__{vm}_product.product_sku LIKE '%$keyword%' OR \n";
 
--- End code ---
Insert:

--- Code: (text) ---$search_sql = " (#__{vm}_product.my_code LIKE '%$keyword%' OR \n";
--- End code ---

2. If you want the data in this field are unique and not duplicate, in administrator / components / com_virtuemart / classes / edit file ps_product.php

After:

--- Code: (text) ---      $q = "SELECT product_id,product_thumb_image,product_full_image FROM #__{vm}_product WHERE product_sku='";
      $q .= $d["product_sku"] . "'";
      $db->setQuery($q); $db->query();
      if ($db->next_record()&&($db->f("product_id") != $d["product_id"])) {
         $vmLogger->err( "A Product with the SKU ".$d['product_sku']." already exists." );
         $valid = false;
      }
--- End code ---
Insert:

--- Code: (text) ---          $q = "SELECT product_id,product_thumb_image,product_full_image FROM #__{vm}_product WHERE my_code='";
      $q .= $d["my_code"] . "'";
      $db->setQuery($q); $db->query();
      if ($db->next_record()&&($db->f("product_id") != $d["product_id"])) {
         $vmLogger->err( "A Product with the code ".$d['my_code']." already exists." );
         $valid = false;
      }
--- End code ---


I hope this guide is useful.

How to show the new fields?
You can use the instruction of rb « Reply #1 on: February 14, 2010, 23:35:12 pm »

http://forum.virtuemart.net/index.php?topic=67123.msg221790#msg221790


--- Quote from: rb on February 14, 2010, 23:35:12 pm ---1. In shop_browse_queries.php, add your 2 fields to the line that start with:   $fieldnames =

2. In shop.browse.php, find this line:
     $product_s_desc = $db_browse->f("product_s_desc");
   Duplicate that line twice, and in the first line, replace product_s_desc TWICE with field1, and then in the second line, twice with field2

3. Still in shop.browse.php, find this line:
     $products[$i]['product_s_desc'] = $product_s_desc;
   Duplicate that line twice, and in the first line, replace product_s_desc TWICE with field1, and then in the second line, twice with field2

--- End quote ---

[attachment cleanup by admin]

dudemeister:
Thank you so much for this guide!

I have one question though. When I put in your code to test everything works fine, but the database does not seem to update the information nor does it show up when I refresh the product page. All that shows up is: "0.00". Does the field have to have any special type...VARCHAR, Decimal, ect?

dudemeister:
This is what I'm showing:

Ventsi Genchev:
If you do not know how to set the field in the database, look at another type of field. If you would like SKU, see its data. I attached a picture 1.
If you want field like price, see picture 2.

Are you add code in
* Function to update product $d['product_id'] in the product table
(section 3.2 of the guide)


[attachment cleanup by admin]

Navigation

[0] Message Index

Go to full version