VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: MC Web Design on July 06, 2012, 19:21:22 PM

Title: Textarea product custom field
Post by: MC Web Design on July 06, 2012, 19:21:22 PM
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]
Title: Re: Textarea product custom field
Post by: Actlas on September 10, 2012, 09:00:05 AM
Good work!
The problem is we would wish a wysiwyg editor. And using this method all the textinputs become textfields too.
Any recent progress?
Title: Re: Textarea product custom field
Post by: 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?
Title: Re: Textarea product custom field
Post by: baparks on November 19, 2012, 03:25:58 AM
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!
Title: Re: Textarea product custom field
Post by: PRO on January 29, 2013, 13:18:54 PM
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"  ?
Title: Re: Textarea product custom field
Post by: 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> ?
Title: Re: Textarea product custom field
Post by: PRO on January 30, 2013, 22:17:57 PM
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/>';
Title: Re: Textarea product custom field
Post by: 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.
Title: Re: Textarea product custom field
Post by: PRO on January 31, 2013, 15:26:41 PM
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?
Title: Re: Textarea product custom field
Post by: PRO on January 31, 2013, 15:27:09 PM
have you tried adjusting the css to just make it 100% width??
Title: Re: Textarea product custom field
Post by: 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
Title: Re: Textarea product custom field
Post by: PRO on January 31, 2013, 21:10:22 PM
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

Title: Re: Textarea product custom field
Post by: Actlas on February 04, 2013, 09:23:46 AM
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?
Title: Re: Textarea product custom field
Post by: kacper1972 on February 08, 2013, 06:39:19 AM
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
Title: Re: Textarea product custom field
Post by: MC Web Design on February 10, 2013, 01:05:07 AM
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/ (https://www.mcwebdesign.ro/2013/02/virtuemart-2-textarea-product-custom-field/)
Title: Re: Textarea product custom field
Post by: PRO on February 10, 2013, 20:10:52 PM
Quote from: Actlas on February 04, 2013, 09:23:46 AM
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?


what did you try?
Title: Re: Textarea product custom field
Post by: Actlas on February 11, 2013, 10:42:41 AM
Quote from: anonimucv on February 10, 2013, 01:05:07 AM
Looks like this plugin is the solution for what you are looking for: http://siteprezentare.ro/2013/02/virtuemart-2-textarea-product-custom-field/ (http://siteprezentare.ro/2013/02/virtuemart-2-textarea-product-custom-field/)

This is exactly what we need, great!
When we press add to cart however, we get a blank page though on every product.
Even those that don't have the plugin as custom field.

Did anybody try this?

I started a different topic here: http://forum.virtuemart.net/index.php?topic=112899.msg379823#msg379823
Title: Re: Textarea product custom field
Post by: MC Web Design on February 11, 2013, 17:18:50 PM
I've tested the plugin with Joomla 2.5.8 and VirtueMart 2.0.18. You have to overwrite cart.php file, but it works great.
Title: Re: Textarea product custom field
Post by: MC Web Design on April 28, 2013, 14:57:15 PM
The plugin works with all VirtueMart stable versions starting from 2.0.6 to 2.0.20b. Also added image upload feature (it uses image upload plugin for TinyMCE provided by http://justboil.me/).
Title: Re: Textarea product custom field
Post by: MC Web Design on June 20, 2016, 23:41:27 PM
New plugin works with Joomla 3.8.2.
Demo (Joomla 3.8.2 & VirtueMart 3.2.4): http://virtuemart-textarea.mcwebdesign.ro/ (http://virtuemart-textarea.mcwebdesign.ro/)