Author Topic: Textarea product custom field  (Read 12777 times)

MC Web Design

  • 3rd party VirtueMart Developer
  • Beginner
  • *
  • Posts: 23
Textarea product custom field
« 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:
Code: [Select]
<!--
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

  • Jr. Member
  • **
  • Posts: 69
Re: Textarea product custom field
« Reply #1 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?

mcdmedia

  • Beginner
  • *
  • Posts: 8
Re: Textarea product custom field
« Reply #2 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?

baparks

  • Beginner
  • *
  • Posts: 10
Re: Textarea product custom field
« Reply #3 on: November 19, 2012, 03:25:58 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

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10352
  • VirtueMart Version: 3+
Re: Textarea product custom field
« Reply #4 on: January 29, 2013, 13:18:54 pm »
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"  ?
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Actlas

  • Jr. Member
  • **
  • Posts: 69
Re: Textarea product custom field
« Reply #5 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> ?

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10352
  • VirtueMart Version: 3+
Re: Textarea product custom field
« Reply #6 on: January 30, 2013, 22:17:57 pm »
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/>';
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Actlas

  • Jr. Member
  • **
  • Posts: 69
Re: Textarea product custom field
« Reply #7 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.

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10352
  • VirtueMart Version: 3+
Re: Textarea product custom field
« Reply #8 on: January 31, 2013, 15:26:41 pm »
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?
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10352
  • VirtueMart Version: 3+
Re: Textarea product custom field
« Reply #9 on: January 31, 2013, 15:27:09 pm »
have you tried adjusting the css to just make it 100% width??
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Actlas

  • Jr. Member
  • **
  • Posts: 69
Re: Textarea product custom field
« Reply #10 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

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10352
  • VirtueMart Version: 3+
Re: Textarea product custom field
« Reply #11 on: January 31, 2013, 21:10:22 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

J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Actlas

  • Jr. Member
  • **
  • Posts: 69
Re: Textarea product custom field
« Reply #12 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?

kacper1972

  • Beginner
  • *
  • Posts: 34
Re: Textarea product custom field
« Reply #13 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

MC Web Design

  • 3rd party VirtueMart Developer
  • Beginner
  • *
  • Posts: 23
Re: Textarea product custom field
« Reply #14 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/