News:

Support the VirtueMart project and become a member

Main Menu

Change Product description length (or other fields)

Started by Marttyn, July 30, 2013, 21:17:07 PM

Previous topic - Next topic

Marttyn

Ive been al day trying to solve this, and i found the answer!
I will explain so maybe its useful to someone.

I have some lengthy descriptions for my products. And when saving, the text is cut, because it exceed the maximum length for "product_desc" field in the database.
By default my VM 2.0.22a has a 18400 char max length. And i wanted to increase a little.
If i go to my DB and look for the virtuemart_product_en_gb (or the language you installed) table, you can see that "product_desc" field is 18400. And if you try to modify you will get an error. This error is because any ROW of a table can be longer than 65535 bytes. Each character with UTF8 encoding use up to 3 bytes, all the columns of a single row should be no more than 65535 bytes, so the 18400 char default is chosen to fit this limit.
To increase the size of a field, you should decrese the size of other field to be always bellow the limit. So you can shorten your "product_s_desc" from 2000 to 500, and now you can increase "product_desc" to 19900.

BUT you cant do that in the DB, because VM is smarter than you and will change it back again to the default values. So you will have to go to administrator/components/com_virtuemart/helpers/tableupdater.php and find this lines and modify with the values you want.
$fields['product_s_desc'] = 'varchar('.VmConfig::get('dbpsdescsize',2000).') '.$linedefault;
$fields['product_desc'] = 'varchar('.VmConfig::get('dbpdescsize',18400).') '.$linedefault;


for example to this:
$fields['product_s_desc'] = 'varchar('.VmConfig::get('dbpsdescsize',400).') '.$linedefault;
$fields['product_desc'] = 'varchar('.VmConfig::get('dbpdescsize',20000).') '.$linedefault;


With this mod, now you will have to go to your VM config page, and click "Apply". With this the tables will update to the new size!!

Other option, that does not involve changing PHP files would be to declare 'dbpsdescsize' and 'dbpdescsize' and assign  your value to them. I read that should be declared on virtuemart.cfg but i cant make it work  :(

I hope this is useful to someone, as i spent 1 day to figure it out  ;D

serge-web54

i changed this line  :
$fields['product_desc'] = 'varchar('.VmConfig::get('dbpdescsize',18400).') '.$linedefault;

into

$fields['product_desc'] = 'longtext '.$linedefault;

when you have a long text it seems better.

sandomatyas

Is there any way to set text or longtext to product_desc field officially?
There is code in tableupdater.php
if(VmConfig::get('dblayoutstrict',true)){
if($table=='products'){
$fields['product_s_desc'] = 'varchar('.VmConfig::get('dbpsdescsize',2000).') '.$linedefault;
$fields['product_desc'] = 'varchar('.VmConfig::get('dbpdescsize',18400).') '.$linedefault;

But it'll be always varchar. What if I need some longer content?

Milbo

Should I fix your bug, please support the VirtueMart project and become a [url=http://extensions.virtuemart.net/support/virtuemart-supporter-membership-detail]member[/url]
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

jflash

I tried set dblayoutstrict=0 but still 18412 characters saved in description...
Joomla 3.8.12 and VM 3.2.14