Guide:How to add new field in admin panel/VirtueMart/article
Venci Gentchev:
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>
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>
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'),
Insert:
Code: (text)
'my_code' => vmGet($d,'my_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',
Insert:
Code: (text)
'PHPSHOP_PRODUCT_FORM_MY_CODE' => 'MY 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";
Insert:
Code: (text)
$search_sql = " (#__{vm}_product.my_code LIKE '%$keyword%' OR \n";
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;
}
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;
}
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, 16: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
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:
Venci Gentchev:
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)
dudemeister:
This is what I have and what's showing up:
product.product_form.php:
Code:
<tr class="row0">
<td width="21%"><div style="text-align:right;font-weight:bold;"><?php echo $VM_LANG->_('PHPSHOP_PRODUCT_FORM_MAP') ?>:</div></td>
<td width="79%"><input type="text" class="inputbox" name="my_code" value="<?php $db->sp("product_map"); ?>" size="32" maxlength="64" /></td>
</tr>
ps_product.php:
* Function to add a new product into the product table
Code:
'product_order_levels' => $d['order_levels'],
'product_map' => vmGet($d,'product_map') );
Function to update product $d['product_id'] in the product table
Code:
'product_order_levels' => $d['order_levels'],
'product_map' => vmGet($d,'product_map') );
Added:
Code:
$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;
}
$q = "SELECT product_id,product_thumb_image,product_full_image FROM #__{vm}_product WHERE product_map='";
$q .= $d["product_map"] . "'";
$db->setQuery($q); $db->query();
if ($db->next_record()&&($db->f("product_id") != $d["product_id"])) {
$vmLogger->err( "A Product with the code ".$d['product_map']." already exists." );
$valid = false;
}
english.php
Code:
'PHPSHOP_PRODUCT_FORM_BOX_DESCRIPTION' => 'Here you can fill in a number unit in box. (max. 65535)',
'PHPSHOP_PRODUCT_FORM_MAP' => 'Minimum Advertised Price',
product.product_list.php:
Code:
$search_sql .= "#__{vm}_product.product_sku LIKE '%$keyword%' OR \n";
$search_sql = " (#__{vm}_product.product_map LIKE '%$keyword%' OR \n";
$search_sql .= "#__{vm}_product.product_s_desc LIKE '%$keyword%' OR \n";
SQL:
VM Admin Product Page:
Any ideas, what I might be missing?
Navigation
[0] Message Index
[#] Next page