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.phpAfter: <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: <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: // Insert into DB
$fields = array ( 'vendor_id' => $vendor_id,
'product_parent_id' => vmRequest::getInt('product_parent_id'),
'product_sku' => vmGet($d,'product_sku'),
Insert: '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.phpAfter: 'PHPSHOP_PRODUCT_FORM_SKU' => 'SKU',
Insert: '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.phpAfter:$search_sql .= "#__{vm}_product.product_sku LIKE '%$keyword%' OR \n";
Insert:$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.phpAfter: $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: $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#msg2217901. 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
[attachment cleanup by admin]