Author Topic: How to make custom HTML-capable product fields  (Read 11394 times)

AndyNZL

  • Beginner
  • *
  • Posts: 32
    • IPO Digital Design
How to make custom HTML-capable product fields
« on: April 01, 2009, 08:13:09 am »
For those that want to be able to display additional HTML capable fields on their product pages - here's a tutorial for VM 1.13 and JM 1.5.9 ...

Adding an HTML capable custom field to VM products

1: Create the new field in jos_vm_product table of the database (type:text, not null) . In this example we call it “ custom_field_1”.
2: The first thing we need is to read values in from the database for use in Virtuemart. Find the file administrator/components/com_virtuemart/html/shop_browse_queries.php, and around line 37 there should be an array called $fieldnames that is being populated with a list of database fields. Simply add ‘custom_field_1’ to the comma separated list.

3: Next comes the part where that database fields value needs to be read into VM. Find the file administrator/components/com_virtuemart/classes/ps_product.php and around line 273 should be a commented area called “Insert into DB”. After the entry for “product unit” add the following...
'custom_field_1' => vmRequest::getVar('custom_field_1', '', 'default', '', VMREQUEST_ALLOWHTML),
Further down that same page is another commented area – also called “insert into DB” – around line 475. Add the same code there.
4: Now let’s display that value in the VM product admin area so that we can edit the values. Find the file administrator/components/com_virtuemart/html/product.product_form.php and add the following lines around line 135 (above where  it asks for the manufacturer ID’s  - note this may already have been done since new versions of VM sometimes have 2 spare fields).
$db2->query("SELECT custom_field_1 FROM #__{vm}_product WHERE product_id='$product_id'");
$db2->next_record();
$custom_field_1 = $db2->f("custom_field_1");
And then further down that page (around line 370 after the above code is added) you should see where the table is displaying the input field for the shirt description. Add a new table row for your custom field (the class “row0” or “row1” refer to whether the row has shading).
<tr class="row0">
      <td width="29%" valign="top"><div style="text-align:right;font-weight:bold;">My HTML  custom field:</div>
      </td>
      <td width="71%"  valign="top">
          <textarea class="inputbox" name="custom_field_1" id="custom_field_1" cols="35" rows="6" ><?php echo $db->sf("custom_field_1"); ?></textarea>
      </td>
    </tr>

5: That should take care of “adding to” and “reading out” information from the database field, but we also need to display that information in our templates and to do that we need to make it part of VM’s understanding of a products attributes. Find the file administrator/components/com_virtuemart/html/shop.browse.php and around line 449 VM is adding individual product attributes to an array called $products. Simply add …
$products[$i]['custom_field_1'] = $db_browse->f("custom_field_1");
The only remaining step before a template can display it is to convert the array field to a template variable. Find the file administrator/components/com_virtuemart/html/shop.product_details.php and declare a new blank template variable - around line 110 add the following …
$custom_field_1 = $db_product->f("custom_field_1");
… And then further down (around line 415) set the template understanding of that new variable ..
$tpl->set('custom_field_1', $custom_field_1);

6: Now we have a custom field that can be edited via the normal VM product admin and displayed anywhere in your view templates with … <?php echo $custom_field_1 ?>

Diconn_kz

  • Beginner
  • *
  • Posts: 6
Re: How to make custom HTML-capable product fields
« Reply #1 on: April 02, 2009, 13:13:59 pm »
Hello AndyNZL,
I followed your instruction and it looks OK. I've got HTML custom field in product admin page. I can add some html code and I saw there is a record in data base table (custom_field_1)with this code. I've added this code.....   <?php echo $custom_field_1?>   ..... to browse_1.php file, but there is nothing  on a front page for that product. What am doing wrong?

Thanks. 

Diconn_kz

  • Beginner
  • *
  • Posts: 6
Re: How to make custom HTML-capable product fields
« Reply #2 on: April 02, 2009, 13:48:12 pm »
Well. I found a problem. This last code need to be added to flypage.php and it starts to work. Now I can start to test this new feature.

macallf

  • Full Member
  • ***
  • Posts: 2411
    • Mark Callf Design
Re: How to make custom HTML-capable product fields
« Reply #3 on: April 02, 2009, 14:08:39 pm »
Or you could read this and find out vm has in built custom fields, more powerful and no editing of many files.

I even have a modification to allow easier placement in the flypages.

More info here http://forum.virtuemart.net/index.php?topic=53087.0
Mark
All of My old mods are now available on my website.
Mark Callf Designs

If you like the work I've done for VM please fell free to Donate

Please Note: I am no longer actively developing or involved with VM development.

Ninjab

  • Jr. Member
  • **
  • Posts: 78
Re: How to make custom HTML-capable product fields
« Reply #4 on: April 03, 2009, 10:52:00 am »
Sorry Mark but I went to the link you pasted and I dont see anything in the thread about being able to add custom fields?

By the way guys, I followed Andy's instructions and all is working fine. You can also add a html editor if you dont want to paste code into the box. I put this just above the product description for mine instead of the textarea:

<table class="adminform">
    <tr class="row1">
      <td valign="top" width="15%"><div style="font-weight:bold;"> Specs:</div></td>
      <td width="85%"><?php
        editorArea( 'editor1', htmlspecialchars( $db->sf("custom_field_1"), ENT_QUOTES ), 'custom_field_1', '550', '300', '55', '25' )
   ?></td>
    </tr>
  </table>

However one bug I have found is I realised that the code <p>&nbsp;</p> it does not like. Lets say I had some code or text etc and then in the middle of all that or in a table or wherever it may be displayed I add a <p>&nbsp;</p>, anything after that will not display and will jumble some of the page.

But its also the same if I use the product_desc editor also.

macallf

  • Full Member
  • ***
  • Posts: 2411
    • Mark Callf Design
Re: How to make custom HTML-capable product fields
« Reply #5 on: April 03, 2009, 11:34:35 am »
Well, lets say it again. Product types are custom fields!

They are just called product types, or custom fields for use with certain types of products.

So a product type is a group of custom fields that you can assign to a product. You can also have more than 1 product type assigned to a product or none at all. No adjusting the core, just administration in the backend.

So the time it takes to add 1 custom field, adjust the db tables then the frontend files to display the product type. I could have created a product type with 10 fields and assigned it to all my products!

Which was all explained in my link!
Mark
All of My old mods are now available on my website.
Mark Callf Designs

If you like the work I've done for VM please fell free to Donate

Please Note: I am no longer actively developing or involved with VM development.

Zabava

  • Beginner
  • *
  • Posts: 3
Re: How to make custom HTML-capable product fields
« Reply #6 on: April 11, 2009, 09:37:22 am »
Hello AndyNZL,
Your instruction is very helpful.
Thank you, very much!
I added some text fields, all correct and works ok.
Now I need to display dropdown list field on my vm product page. I need to be able to display this fields on vm adminpanel (like your text HTML custom field), and put its value  on a category browse-page(browse_1 etc..) for that category. Not only a fly-page.
Could you help my, please, with this?
Thanks!

TomC

  • Jr. Member
  • **
  • Posts: 215
Re: How to make custom HTML-capable product fields
« Reply #7 on: August 27, 2009, 07:05:23 am »
BEST THREAD EVER !!!

 ;D

QubeSys Technologies

  • Jr. Member
  • **
  • Posts: 288
  • Joomla & Magento Services
Re: How to make custom HTML-capable product fields
« Reply #8 on: June 01, 2010, 08:44:16 am »
I just created the product type and want to assign it to all of my already created 50 products, so that I can then goto each product  and enter my info to it.
How to assign all the products to that product_type created ??

Well, lets say it again. Product types are custom fields!

They are just called product types, or custom fields for use with certain types of products.

So a product type is a group of custom fields that you can assign to a product. You can also have more than 1 product type assigned to a product or none at all. No adjusting the core, just administration in the backend.

So the time it takes to add 1 custom field, adjust the db tables then the frontend files to display the product type. I could have created a product type with 10 fields and assigned it to all my products!

Which was all explained in my link!
Blissful!

QubeSys Technologies

  • Jr. Member
  • **
  • Posts: 288
  • Joomla & Magento Services
Re: How to make custom HTML-capable product fields
« Reply #9 on: June 01, 2010, 09:03:36 am »
Ok I just selected all the products and then clicked on ADD TO PRODUCT TYPE and it did the trick.

Thanks.
Blissful!

QubeSys Technologies

  • Jr. Member
  • **
  • Posts: 288
  • Joomla & Magento Services
Re: How to make custom HTML-capable product fields
« Reply #10 on: June 01, 2010, 09:09:02 am »
Sorry, another issue.

I have created a Product Type and then created a Paramter with text .
Now I have assigned all of my products to that product type and entered text for all of those products.

Now, i want to show this info on the product flypage.

So, I just went to the flypage.tpl.php in my custom VM theme folder and entered this  <?php echo $product_more_info ?>
, just after the description bloc, so it appears below it.


But it doesnt show anything.

But If I put this,
<?php echo $product_type ?>

It works.

But it shows this way,


I dont want that strings to come ,
"Parameters of Product: Product Info
Product More Info"

Where can I remove it ?

And why <?php echo $product_more_info ?> this doesnt work ?
 
Blissful!

bigballa0831

  • Beginner
  • *
  • Posts: 1
Re: How to make custom HTML-capable product fields
« Reply #11 on: July 22, 2010, 21:29:48 pm »
Awesome! Thanks for the tut on how to add custom descriptions to products.  

Would you be able to put up a tut on how to create the new descriptions fields into CSVI, so thay the descriptions can easily be uploaded into the database during a batch process.

unitherm

  • Beginner
  • *
  • Posts: 1
Re: How to make custom HTML-capable product fields
« Reply #12 on: September 28, 2010, 15:14:02 pm »
I followed these steps and everything works except the page that lays out all the products in the category. It doesn't show any of the product information. The product fly pages still work though.

Dieda12

  • Beginner
  • *
  • Posts: 5
Re: How to make custom HTML-capable product fields
« Reply #13 on: May 16, 2011, 17:26:49 pm »
Hi all,

Sorry for bringing up this old post but I found it extremely useful with Virtuemart 1.1.7.

Anyhow, now I have updated to VM 1.1.8 and now I have the same problem of unitherm, i.e. the code:

Code: [Select]
<?php echo $custom_field_1 ?>

works fine inside flypage.php but not anymore inside browse_2.php (the page I have chosen as default).

Does anyone know why this happens ?

Thanks in advance

Elena

Dieda12

  • Beginner
  • *
  • Posts: 5
[UP] Re: How to make custom HTML-capable product fields
« Reply #14 on: May 31, 2011, 11:50:42 am »
UP!!!