News:

Looking for documentation? Take a look on our wiki

Main Menu

Textarea product custom field

Started by MC Web Design, July 06, 2012, 19:21:22 PM

Previous topic - Next topic

MC Web Design

Hi guys. Here is a simply hack for adding a textarea custom field in the produt's details page.

First, go to "Joomla2.5_root_folder\plugins\vmcustom\textinput\textinput\tmpl\default.php" and replace the code with this one:
<!--
Just replace the file under "Joomla2.5_root_folder\plugins\vmcustom\textinput\textinput\tmpl\default.php" with this one.
You can select the desired size for the textarea by modifying the parameters cols="" and rows="".
-->
<?php
defined('_JEXEC') or die();
$class='vmcustom-textinput';
//vmdebug('$this',$viewData[0]);
//if ($field->custom_price_by_letter) $class='vmcustom-textinput';?>


<textarea name="customPlugin[<?php echo $viewData[0]->virtuemart_customfield_id ?>][<?php echo $this->_name?>][comment]" cols="30" rows="6"></textarea><br />

<?php
// preventing 2 x load javascript
static $textinputjs;
if ($textinputjs) return true;
$textinputjs true ;
//javascript to update price
$document JFactory::getDocument();
$document->addScriptDeclaration('
jQuery(document).ready( function($) {
jQuery(".vmcustom-textinput").keyup(function() {
formProduct = $(".productdetails-view").find(".product");
virtuemart_product_id = formProduct.find(\'input[name="virtuemart_product_id[]"]\').val();
Virtuemart.setproducttype(formProduct,virtuemart_product_id);
});

});
'
);


Then, go into the Virtuemart 2 backend , in the Products -> Custom Fields menu choose New and then from Custom Field Type menu select Plug-ins. From Select a plug-in menu on the bottom pick VM - Custom, customer text input .

And you're done. All you need to do now is to add this new custom field to your product.

I attached also the modifyed default.php file.

P.S.: I hope the developement team will include a textarea plugin in the future releases.
If I knew to do that, I would develop myself a plugin, but I suck at programming.  :-\

[attachment cleanup by admin]

Actlas

Good work!
The problem is we would wish a wysiwyg editor. And using this method all the textinputs become textfields too.
Any recent progress?

mcdmedia

This is a nice little hack.

Does anyone know how to make it so this field is *Required. As it is now a user can add a product to the cart without having any text in this text box.

I can't figure out how to make this a required field. If the customer doesn't put any text in the box it shouldn't allow them to still add the product to the cart.

Anyone have a solution for this?

baparks

Quote from: mcdmedia on November 16, 2012, 10:48:19 AM
This is a nice little hack.

Does anyone know how to make it so this field is *Required. As it is now a user can add a product to the cart without having any text in this text box.

I can't figure out how to make this a required field. If the customer doesn't put any text in the box it shouldn't allow them to still add the product to the cart.

Anyone have a solution for this?

We're ALSO looking for this "required field" fix!

PRO

Quote from: Actlas on January 29, 2013, 11:29:27 AM
I tried this and the text isn't added to the order.
Dit anyone have luck setting this up properly?


is it set as "cart attribute"  ?

Actlas

#5
The text appears at checkout, with spaces instead of line breaks beween each line though. Eventually the text is added to the database as:
{"textinput":{"comment":"line1\r\line2\r\nline3"}

How can I make the lines separated by </ br> ?

PRO

Quote from: Actlas on January 30, 2013, 09:27:52 AM
The text appears at checkout, with spaces instead of line breaks beween each line though. Eventually the text is added to the database as:
{"textinput":{"comment":"line1\r\line2\r\nline3"}

How can I make the lines separated by </ br> ?


is this for MULTIPLE inputs?

\plugins\vmcustom\textinput\textinput.php

in this function
   function plgVmOnViewCart($product,$row,&$html) {

change this
$html .='<span>'.JText::_($product->productCustom->custom_title).' '.$item['comment'].'</span>';

to this
$html .='<span>'.JText::_($product->productCustom->custom_title).' '.$item['comment'].'</span><br/>';

Actlas

That seems like a great solution but it doesn't seem to work. The field input isn't added to the order/database at all.
In fact this has always been the fact with the change to ...textinput\tmpl\default.php for us.

We installed this plugin:http://www.daycounts.com/shop/virtuemart-2/virtuemart-textarea-custom-field-detail
This seemed to work but it added /r/n after each line instead of <br />
I tried your last suggestion in the plugins file: \plugins\vmcustom\textareainput\textareainput.php
Now the text isn't added to the order/database anymore.

Any suggestions would be greatly appreciated.

PRO

Quote from: Actlas on January 31, 2013, 09:06:24 AM
That seems like a great solution but it doesn't seem to work. The field input isn't added to the order/database at all.
In fact this has always been the fact with the change to ...textinput\tmpl\default.php for us.

We installed this plugin:http://www.daycounts.com/shop/virtuemart-2/virtuemart-textarea-custom-field-detail
This seemed to work but it added /r/n after each line instead of <br />
I tried your last suggestion in the plugins file: \plugins\vmcustom\textareainput\textareainput.php
Now the text isn't added to the order/database anymore.

Any suggestions would be greatly appreciated.


   function plgVmOnViewCart($product,$row,&$html) {


is for the DISPLAY on the cart page ONLY.

are you sure you put it in the right place?

PRO

have you tried adjusting the css to just make it 100% width??

Actlas

PRO, It is no use displaying it right in the cart but not in the order confirmation emails and virtuemart administrator backend, right?
Could you point us where to change the code that is inserted into the database?

str_replace('\r\n', "<br/>",... perhaps

PRO

Quote from: Actlas on January 31, 2013, 20:48:24 PM
PRO, It is no use displaying it right in the cart but not in the order confirmation emails and virtuemart administrator backend, right?
Could you point us where to change the code that is inserted into the database?

str_replace('\r\n', "<br/>",... perhaps

then change the other functions

Its stored that way just the same as all joomla plugins.

function plgVmDisplayInOrderBE

^^^ backend order


Actlas

We tried this last fix but it doesn't fix it for us.

If payment is necessary to fix it we would consider this as the feature is a must for us.

Perhaps someone would be so kind to take a look?

kacper1972

Hello Pro nad Actlas

I have the same problem,
the shop where I sell clothing, customers have the option of entering their own size. Unfortunately, this option does not save the entries in the order. I use a modified file with the top of the post. Then I used the http://www.daycounts.com/shop/virtuemart-2/virtuemart-textarea-custom-field-detail
and nothing.
Please look on shop

http://czarnasukienka.pl/index.php/sklep/sukienki/sukienki-koktajlowe/wrzosowa-suknia-z-zakietem-detail.html

I will be grateful for suggestions

MC Web Design

#14
Looks like this plugin is the solution for what you are looking for: https://www.mcwebdesign.ro/2013/02/virtuemart-2-textarea-product-custom-field/