Prestashop display HTML in category description

Posted by on 11 August 2010

NOTE: This post has an updated version for Prestashop 1.4.

When you enter a category into Prestashop you have the ability to enter a description. This only allows text though - no HTML. Find out how to display HTML in Prestashop's category description...

You need to make some changes to Prestashop's core code so please be advised any future upgrades may overwrite your changes. Backup all files before beginning! These changes have been tested with Prestashop version 1.3

1. [admin folder]/tabs/AdminCategories.php

First we need to add class="rte" to the text area as well as load the tinyMCE script on the edit category page in the admin area.

Approx line 212, replace

<textarea cols="40" rows="10" id="description_'.$language['id_lang'].'" name="description_'.$language['id_lang'].'">'.htmlentities(stripslashes($this->getFieldValue($obj, 'description', intval($language['id_lang']))), ENT_COMPAT, 'UTF-8').'</textarea>

with

<textarea class="rte" cols="40" rows="10" id="description_'.$language['id_lang'].'" name="description_'.$language['id_lang'].'">'.htmlentities(stripslashes($this->getFieldValue($obj, 'description', intval($language['id_lang']))), ENT_COMPAT, 'UTF-8').'</textarea>
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/tinymce/jscripts/tiny_mce/jquery.tinymce.js"></script>
  <script type="text/javascript">
  function tinyMCEInit(element)
  {
   $().ready(function() {
    $(element).tinymce({
     // Location of TinyMCE script
     script_url : \''.__PS_BASE_URI__.'js/tinymce/jscripts/tiny_mce/tiny_mce.js\',
     // General options
     theme : "advanced",
     plugins : "safari,pagebreak,style,layer,table,advimage,advlink,inlinepopups,media,searchreplace,contextmenu,paste,directionality,fullscreen",
     // Theme options
     theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
     theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,,|,forecolor,backcolor",
     theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,media,|,ltr,rtl,|,fullscreen",
     theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,pagebreak",
     theme_advanced_toolbar_location : "top",
     theme_advanced_toolbar_align : "left",
     theme_advanced_statusbar_location : "bottom",
     theme_advanced_resizing : false,
     content_css : "'.__PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/global.css",
     width: "582",
     height: "auto",
     font_size_style_values : "8pt, 10pt, 12pt, 14pt, 18pt, 24pt, 36pt",
     // Drop lists for link/image/media/template dialogs
     template_external_list_url : "lists/template_list.js",
     external_link_list_url : "lists/link_list.js",
     external_image_list_url : "lists/image_list.js",
     media_external_list_url : "lists/media_list.js",
     elements : "nourlconvert",
     convert_urls : false,
     language : "'.(file_exists(_PS_ROOT_DIR_.'/js/tinymce/jscripts/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en').'"
    });
   });
  }
  tinyMCEInit(\'textarea.rte\');
  </script>

2. classes/Category.php

Now we change the field type of description: 'description' => 'isCleanHtml' becomes 'description' => 'isString'

Approx. line 65, replace

protected 	$fieldsValidateLang = array('name' => 'isCatalogName', 'link_rewrite' => 'isLinkRewrite', 'description' => 'isCleanHtml',
'meta_title' => 'isGenericName', 'meta_description' => 'isGenericName', 'meta_keywords' => 'isGenericName');

with

protected 	$fieldsValidateLang = array('name' => 'isCatalogName', 'link_rewrite' => 'isLinkRewrite', 'description' => 'isString',
'meta_title' => 'isGenericName', 'meta_description' => 'isGenericName', 'meta_keywords' => 'isGenericName');

3. classes/ObjectModel.php

Approx. line 295, replace

if (isset($this->{$field}[$language['id_lang']]) AND !Tools::isEmpty($this->{$field}[$language['id_lang']]))
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
elseif (in_array($field, $this->fieldsRequiredLang))
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
else
$fields[$language['id_lang']][$field] = '';

with

if (isset($this->{$field}[$language['id_lang']]) AND !Tools::isEmpty($this->{$field}[$language['id_lang']])) {
if(isset($this->fieldsValidateLang[$field]) && $this->fieldsValidateLang[$field]=='isString'){
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']],'true');
}else{
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
}
}
elseif (in_array($field, $this->fieldsRequiredLang))
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
else
$fields[$language['id_lang']][$field] = '';

4. category.php

Lastly make sure we get rid of carriage returns being converted in to breaks when displaying the description.

Approx. line 49, replace

$category->description = nl2br2($category->description);

with

$category->description = ($category->description);

Thats all there is to it. If you notice any bugs or problems please drop me an email or comment.

Like to make an inquiry? Contact Us