Welcome, Guest. Please login or register.
Login with username, password and session length


It's a release candidate! VirtueMart 2.0 RC - the next generation VirtueMart - is available! Read more....

  Advanced search

247038 Posts in 67506 Topics- by 258314 Members - Latest Member: aniketana
VirtueMart ForumVirtueMart 1.1.xFrequently Asked QuestionsGuide:How to add new field in admin panel/VirtueMart/article
Pages: [1]   Go Down
Print
Author Topic: Guide:How to add new field in admin panel/VirtueMart/article  (Read 25497 times)
Venci Gentchev
Jr. Member
**
Posts: 52



WWW
« on: August 19, 2009, 12:39:00 PM »

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

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


* my_code.png (18.31 KB, 517x221 - viewed 2008 times.)
« Last Edit: May 10, 2010, 07:34:27 AM by Venci Gentchev » Logged

dudemeister
Newbie
*
Posts: 16


« Reply #1 on: August 19, 2009, 14:20:19 PM »

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?
« Last Edit: August 19, 2009, 14:44:35 PM by dudemeister » Logged
dudemeister
Newbie
*
Posts: 16


« Reply #2 on: August 19, 2009, 14:53:55 PM »

This is what I'm showing:

Logged
Venci Gentchev
Jr. Member
**
Posts: 52



WWW
« Reply #3 on: August 20, 2009, 00:06:08 AM »

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)


* my_code_field.png (12.09 KB, 404x326 - viewed 1605 times.)

* my_code_field2.png (11.47 KB, 403x317 - viewed 1241 times.)
« Last Edit: August 20, 2009, 01:47:28 AM by admns » Logged

dudemeister
Newbie
*
Posts: 16


« Reply #4 on: August 21, 2009, 01:41:40 AM »

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?
Logged
Venci Gentchev
Jr. Member
**
Posts: 52



WWW
« Reply #5 on: August 21, 2009, 03:54:59 AM »

Read carefully:

If you choose any other name, change it everywhere in the codes listed below.

You have an error in product.product_form.php
Change name="my_code"

If you use the box for a price, not recommend you do it unique. So you can not duplicate the prices in this field. Don't use Little extras and additions - section 2 of the guide.
« Last Edit: August 21, 2009, 04:10:09 AM by admns » Logged

dudemeister
Newbie
*
Posts: 16


« Reply #6 on: August 21, 2009, 16:56:47 PM »

Thank You!

I'm so blind sometimes.  I changed all the names but didnt see the custom name in the input box! Smiley This guide is really helpful. Thanks again.

Now, my only question is how easy is it to call the field into a function. For example, on my product flypages I want to be able to have something simple like:

Code:
<?php

if ('product_map'=="")
    echo 
$product_price;
elseif (
'product_map' 'product_price' 'product_price' .1)
    echo 
"Add to Cart To See Price";
else
    echo 
$product_price;

?>

I'm a former ASP guy, and I've been trying to figure out how VM and Joomla call fields from the Database, but have had no success so far. Any help you can pass on to a VM, Joomla and PHP noob would be much appreciated. Thanks again.
Logged
Venci Gentchev
Jr. Member
**
Posts: 52



WWW
« Reply #7 on: August 22, 2009, 00:38:26 AM »

This issue is more complex, because obviously you want this field to not only see in flypage, but also to participate in the purchase. He wants more time and tests. Unfortunately at the moment so I have no time.
Run a new topic with this question. Maybe someone will show decision.
Logged

dudemeister
Newbie
*
Posts: 16


« Reply #8 on: August 23, 2009, 18:16:34 PM »

I figured it out and will post it in the Modifications since several people have been asking for this mod.
Logged
allado
Newbie
*
Posts: 1


« Reply #9 on: September 25, 2009, 04:13:51 AM »

ohh.. thank you... good guide.
Logged
lolanto
Newbie
*
Posts: 4


« Reply #10 on: November 03, 2009, 15:04:58 PM »

Hi,

Good guide

Anyone knows how to make the custom field appear in the admin order print. (order.order_printdetails.php)

Thanks in advance for your help
Logged
taddy
Newbie
*
Posts: 5


« Reply #11 on: November 18, 2009, 10:49:58 AM »

@Venci Gentchev  <-- u just dont know how you saved me a lot! you are my savior thanks for this great tutorial!
Logged
Venci Gentchev
Jr. Member
**
Posts: 52



WWW
« Reply #12 on: November 18, 2009, 11:34:32 AM »

I'm glad that it was so useful for you.  Smiley
Logged

Pages: [1]   Go Up
Print
Jump to: