Jump to content

[SOLVED] Add a second category description


andycatax

Recommended Posts

I am trying to increase my content on category pages as we only have a small area at the top of our pages for the category description for around 70 words and would like to add a second description to the bottom of the pages which we can add 200 - 400 words.

 

Any ideas how i could do this?

 

Thanks

Andy

Edited by andycatax (see edit history)
Link to comment
Share on other sites

For this you can maybe add a new field to the table ps_category_lang, and modify a few files:

(in example below: Code from PS1.5.5.0)

 

Go to your cPanel, go to phpMyAdmin and Run SQL  (to do this, go to any table, and click SQL tab):
ALTER TABLE `ps_category_lang` ADD `long_description` text AFTER `description`;
and press GO.

 

Edit file: classes/Category.php:   (Backup first...)

at the top, just under:

     /** @var string Description */
     public $description;
Add:

     /** @var string long_description */
     public $long_description;



in  public static $definition = array( , just under:

               'description' =>           array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),

add:
               'long_description' =>           array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),




edit file themes/<your theme folder>/category.tpl:   (Backup first...)
just under: (almost at end of file) (add red text)

			<div class="content_sortPagiBar">
				<div class="sortPagiBar clearfix">
					{include file="./product-sort.tpl" paginationId='bottom'}
					{include file="./product-compare.tpl" paginationId='bottom'}
					{include file="./nbr-product-page.tpl" paginationId='bottom'}
				</div>
				{include file="./pagination.tpl" paginationId='bottom'}
			</div>
		{/if}

               {if $category->long_description}
                    <div class="cat_desc">
                    {if strlen($category->long_description) > 500}
                         <p id="category_long_description_short">{$category->long_description|truncate:500}</p>
                         <p id="category_long_description_full" style="display:none">{$category->long_description}</p>
                         <a href="#" onclick="$('#category_long_description_short').hide(); $('#category_long_description_full').show(); $(this).hide(); return false;" class="lnk_more">{l s='More'}</a>
                    {else}
                         <p>{$category->long_description}</p>
                    {/if}
                    </div>
               {/if}



	{elseif $category->id}
		<p class="warning">{l s='This category is currently unavailable.'}</p>
	{/if}
{/if}

-- END OF FILE --



Edit file: controllers/admin/AdminCategoriesController.php  (Backup first...)
just under:

				array(
					'type' => 'textarea',
					'label' => $this->l('Description:'),
					'name' => 'description',
					'autoload_rte' => true,
					'lang' => true,
					'rows' => 10,
					'cols' => 100,
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),

add:

                    array(
                         'type' => 'textarea',
                         'label' => $this->l('Long description:'),
                         'name' => 'long_description',
                         'autoload_rte' => true,
                         'lang' => true,
                         'rows' => 10,
                         'cols' => 100,
                         'hint' => $this->l('Invalid characters:').' <>;=#{}'
                    ),
 

 

That should do the trick.

pascal

 

!!!!

N.B. Be careful when updating PrestaShop, as the ps_category_lang may be overwritten. So save your table field contents before updating!

 

post-455771-0-31697100-1378356587_thumb.jpg

post-455771-0-63073100-1378356602_thumb.jpg

 

 

  • Like 5
Link to comment
Share on other sites

  • 2 weeks later...

Awesome Pascal, works very well!

 

I removed the red lines to get rid or the "read more" and the "..." so it shows all content instead. I bet it's not the right way of doing it ;-) Can confirm that?

 

{if $category->long_description}
<div class="cat_desc">
{if strlen($category->long_description) > 500}
<p id="category_long_description_short">{$category->long_description|truncate:500}</p>
<p id="category_long_description_full" style="display:none">{$category->long_description}</p>
<a href="#" onclick="$('#category_long_description_short').hide(); $('#category_long_description_full').show(); $(this).hide(); return false;" class="lnk_more">{l s='More'}</a>
{else}
<p>{$category->long_description}</p>
{/if}
</div>
{/if}

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

Hi q-skins,

 

here we go: (N.B. Of all files we will edit, please make a backup first!!)

(Note: Sample code is from PrestaShop 1.4.11, so may differ a little from 1.4.8.2, but should be recognisable)

Edit /classes/Category.php: (Back up made?)

At the top, just under:

	/** @var mixed Description */
	public 		$description;


add:

/** @var mixed Long Description */
public $description_long;
 
 
About 45-47 lines below this, you find something like:
  protected $fieldsValidateLang = array('name' => 'isCatalogName', 'link_rewrite' => 'isLinkRewrite', 'description' => 'isCleanHtml', 'description_long' => 'isCleanHtml',
'meta_title' => 'isGenericName', 'meta_description' => 'isGenericName', 'meta_keywords' => 'isGenericName');
 
Add the red code.
 
 
in function:
public function getTranslationsFieldsChild()
{
  parent::validateFieldsLang();
  return parent::getTranslationsFields(array('name', 'description', 'description_long', 'link_rewrite', 'meta_title', 'meta_keywords',
  'meta_description'));
}
 
Add the red code.
 
 
in function:
public function getSubCategories($id_lang, $active = true)
{
  $groups = FrontController::getCurrentCustomerGroups();
  $sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
 
  $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
  SELECT c.*, cl.id_lang, cl.name, cl.description, cl.description_long, cl.link_rewrite, cl.meta_title, cl.meta_keywords,
  cl.meta_description
  FROM `'._DB_PREFIX_.'category` c
  ...
}

 

Add the red code, just after cl.description,

 

Save the file.

 

 

Edit file: /themes/<your theme folder>/category.tpl (Back up??)

 

At the end of the file, you see code like this. Add the red code:

		{if $products}
				{include file="$tpl_dir./product-compare.tpl"}
				{include file="$tpl_dir./product-sort.tpl"}
				{include file="$tpl_dir./product-list.tpl" products=$products}
				{include file="$tpl_dir./product-compare.tpl"}
				{include file="$tpl_dir./pagination.tpl"}
			{elseif !isset($subcategories)}
				<p class="warning">{l s='There are no products in this category.'}</p>
			{/if}
{if $category->description_long}
  <div class="cat_desc_long">{$category->description_long}</div>
{/if}
	{elseif $category->id}
		<p class="warning">{l s='This category is currently unavailable.'}</p>
	{/if}
{/if}

And save the file.

 

 

Edit file: /controllers/CategoryController.php  (after making a backup...)

just under:

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

add this:

 
  $this->category->description_long = nl2br2($this->category->description_long);
 

 

and save the file. (If 1.4.8.2 doesn't have this line, that's ok...)

 

 

The next file is a little hard to find: it's inside the folder with the name that you add to your domain when logging in to you back office:

So, edit the file:  /<your admin folder>/tabs/AdminCategories.php  (backup...)

 

The next code is a little difficult to find.

Inside function:
  public function displayForm($token = NULL)
 

Search for description (use Ctrl-F)

 

You will find some code similar to this:

				<label>'.$this->l('Parent category:').' </label>
				<div class="margin-form">';
				// Translations are not automatic for the moment 
				$trads = array(
					 'Home' => $this->l('Home'), 
					 'selected' => $this->l('selected'), 
					 'Collapse All' => $this->l('Collapse All'), 
					 'Expand All' => $this->l('Expand All')
				);
				echo Helper::renderAdminCategorieTree($trads, array(isset($obj->id_parent) ? $obj->id_parent : Tools::getValue('id_parent', 1)), 'id_parent', true);
				echo '</div>


				<label>'.$this->l('Description:').' </label>
				<div class="margin-form translatable">';
		foreach ($this->_languages AS $language)
			echo '
					<div class="lang_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
						<textarea name="description_'.$language['id_lang'].'" rows="10" cols="100">'.htmlentities($this->getFieldValue($obj, 'description', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'</textarea>
					</div>';
		echo '	<p class="clear"></p>
				</div>

From this, copy this part:

				<label>'.$this->l('Description:').' </label>
				<div class="margin-form translatable">';
		foreach ($this->_languages AS $language)
			echo '
					<div class="lang_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
						<textarea name="description_'.$language['id_lang'].'" rows="10" cols="100">'.htmlentities($this->getFieldValue($obj, 'description', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'</textarea>
					</div>';
		echo '	<p class="clear"></p>
				</div>

(N.B. Your code may be a little bit different, but should be recognisable)

 

And paste it directly under the copied code

 

In the pasted code, add/change the red code:

 

<label>'.$this->l('Long description:').' </label>
<div class="margin-form translatable">';
foreach ($this->_languages AS $language)
echo '
<div class="lang_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
<textarea name="description_long_'.$language['id_lang'].'" rows="10" cols="100">'.htmlentities($this->getFieldValue($obj, 'description_long', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'</textarea>
</div>';
echo ' <p class="clear"></p>
</div>
 

So, together you will have something like:

				<label>'.$this->l('Parent category:').' </label>
				<div class="margin-form">';
				// Translations are not automatic for the moment 
				$trads = array(
					 'Home' => $this->l('Home'), 
					 'selected' => $this->l('selected'), 
					 'Collapse All' => $this->l('Collapse All'), 
					 'Expand All' => $this->l('Expand All')
				);
				echo Helper::renderAdminCategorieTree($trads, array(isset($obj->id_parent) ? $obj->id_parent : Tools::getValue('id_parent', 1)), 'id_parent', true);
				echo '</div>
				<label>'.$this->l('Description:').' </label>
				<div class="margin-form translatable">';
		foreach ($this->_languages AS $language)
			echo '
					<div class="lang_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
						<textarea name="description_'.$language['id_lang'].'" rows="10" cols="100">'.htmlentities($this->getFieldValue($obj, 'description', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'</textarea>
					</div>';
		echo '	<p class="clear"></p>
				</div>

				<label>'.$this->l('Long description:').' </label>
				<div class="margin-form translatable">';
		foreach ($this->_languages AS $language)
			echo '
					<div class="lang_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
						<textarea name="description_long_'.$language['id_lang'].'" rows="10" cols="100">'.htmlentities($this->getFieldValue($obj, 'description_long', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'</textarea>
					</div>';
		echo '	<p class="clear"></p>
				</div>


and save the file.

 

 

Finally, go to your cPanel, go to phpMyAdmin, open your database, and open the table ps_category_lang

(N.B. if you have a different Prefix than "ps_", change accordingly)

go to the SQL tab and paste this line:

 

ALTER TABLE `ps_category_lang` ADD `description_long` text AFTER `description`;
and press GO.

 

Check if you see a success message. If you then browse the table, you should see a field description_long just behind the description field.

 

Time to try it! Go to your back office, and open the Catalog Tab. Then EDIT any catalog (click on the sheet + pencil icon at the right)

You should see a field Long description: just below the field Description:

Add some text and save the changes. No error should occur...

 

Then go to the front office and in the categories tree (from the category block-module), click the changed category. At the top you should see the normal description, then the products of the category. Then at the end you should see the long description.

 

In my case, The text wrapped around the "compare" button, so I needed to move it down a little:

 

Edit the file themes/<your theme folder>/css/global.css

 

and add at the end:

 

.cat_desc_long {

  margin-top:10px;

}

 

and save the file. You can add more css decoration of your long description of course, like font, font size, background image etc. that's further up to you.

 

 

N.B. You may need to (TEMPORARILY!!): 

- turn OFF your smarty cache and

- set 'Force compile' to YES

in Preferences->Performance

to see all the changes. (Don't forget to turn cache back ON and Force compile to NO afterwards!)

 

Well, that should do the trick. Let me know if it works.

 

Hope this helps,

pascal.

Link to comment
Share on other sites

  • 4 weeks later...

Finally tried to add the sec description, but it did not work, the long_description was added successfully, button the category site on BO my category-tree would not drop down, and there was a text on top of the site in BO like Long_description ... 

Do you know what went wrong?

Link to comment
Share on other sites

  • 6 months later...
  • 3 weeks later...

Hi bbclaudiu/Crash99,

 

Follow the solution in post #2 (solution for PS version 1.5.x),

 

 

The database table modification and the modification for file classes/Category.php:   (Backup first...)

are exactly as described in post #2.

 

There are a few very small changes in themes/<your theme folder/category.tpl   (backup file first):

 

the original code in 1.6(.0.5) has been changed a tiny little bit. New code looks like this (first block is a little different from 1.5 code):

		{if $products}
			<div class="content_sortPagiBar clearfix">
            	<div class="sortPagiBar clearfix">
            		{include file="./product-sort.tpl"}
                	{include file="./nbr-product-page.tpl"}
				</div>
                <div class="top-pagination-content clearfix">
                	{include file="./product-compare.tpl"}
					{include file="$tpl_dir./pagination.tpl"}
                </div>
			</div>
			{include file="./product-list.tpl" products=$products}
			<div class="content_sortPagiBar">
				<div class="bottom-pagination-content clearfix">
					{include file="./product-compare.tpl" paginationId='bottom'}
                    {include file="./pagination.tpl" paginationId='bottom'}
				</div>
			</div>
		{/if}

(The red, added code doesn't need any change, so just copy from post #2 and add here, like before)

	{elseif $category->id}
		<p class="alert alert-warning">{l s='This category is currently unavailable.'}</p>
	{/if}
{/if}

-- END OF FILE --

 

 

 

The third file to edit is also a little different:

controllers/admin/AdminCategoriesController.php:   (backup first!)

 

in function: public function __construct()

 
just below:
 
'description' => array(
'title' => $this->l('Description'),
'callback' => 'getDescriptionClean',
'orderby' => false
),
 
add the following code:
 
'long_description' => array(
'title' => $this->l('Long description'),
'callback' => 'getDescriptionClean',
'orderby' => false
),
 

 

 

And in function:   public function renderForm()

 
 just below:
 
array(
'type' => 'textarea',
'label' => $this->l('Description'),
'name' => 'description',
'autoload_rte' => true,
'lang' => true,
'hint' => $this->l('Invalid characters:').' <>;=#{}'
),
 
add the following code:
 
 
array(
'type' => 'textarea',
'label' => $this->l('Long description'),
'name' => 'long_description',
'autoload_rte' => true,
'lang' => true,
'hint' => $this->l('Invalid characters:').' <>;=#{}'
),
 

 

 

I think that should do it. Didn't try it myself, so let me know if it works :-)

 

pascal.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...
  • 3 months later...

Hi Comprolo,

 

Just to make sure, what do you mean exactly with the "content description"?

 

- The first category description

- The second (added in this post) description?   (I vote for this one ;-) )

- something else?

 

Image with some little arrows (from->to) would be great :-)

 

Please elaborate,

pascal

Link to comment
Share on other sites

Comprolo,

 

Would that be just at the end of the left column, you mean? Do you mean a hook, linked to the left column, so that you can move it up/down on the left column as desired?

Would then be best to make it as a module, and just add a function hookDisplayLeftColumn for additional display option. Haven't looked at the module that was posted above. Maybe modify this one a little. Shouldn't be too difficult then. Any experience coding php/smarty?

 

What PS version do you use?

 

pascal.

Link to comment
Share on other sites

Hello Pascal

 

 I think is not necessary make a modul for this purpose, I have an old site in prestashop version 1.4  which have this modification made by a russian developer, I will try to discover how it was coded on the corre.

 

I´m using latest prestashop

 

Regards

Link to comment
Share on other sites

  • 8 months later...
  • 3 weeks later...
  • 3 weeks later...

This gotta be a bad solution. Never edit core files!

Do overrides if you really have to, or even better make it into a module.

 

Edited core files can be lost in a upgrade of your Prestashop installation :P

Link to comment
Share on other sites

  • 2 weeks later...

For this you can maybe add a new field to the table ps_category_lang, and modify a few files:

(in example below: Code from PS1.5.5.0)

 

Go to your cPanel, go to phpMyAdmin and Run SQL  (to do this, go to any table, and click SQL tab):

ALTER TABLE `ps_category_lang` ADD `long_description` text AFTER `description`;

and press GO.

 

Edit file: classes/Category.php:   (Backup first...)

at the top, just under:

     /** @var string Description */

     public $description;

Add:

     /** @var string long_description */

     public $long_description;

 

 

 

in  public static $definition = array( , just under:

               'description' =>           array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),

add:

               'long_description' =>           array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),

 

 

 

 

edit file themes/<your theme folder>/category.tpl:   (Backup first...)

just under: (almost at end of file) (add red text)

			<div class="content_sortPagiBar">
				<div class="sortPagiBar clearfix">
					{include file="./product-sort.tpl" paginationId='bottom'}
					{include file="./product-compare.tpl" paginationId='bottom'}
					{include file="./nbr-product-page.tpl" paginationId='bottom'}
				</div>
				{include file="./pagination.tpl" paginationId='bottom'}
			</div>
		{/if}

               {if $category->long_description}

                    <div class="cat_desc">

                    {if strlen($category->long_description) > 500}

                         <p id="category_long_description_short">{$category->long_description|truncate:500}</p>

                         <p id="category_long_description_full" style="display:none">{$category->long_description}</p>

                         <a href="#" onclick="$('#category_long_description_short').hide(); $('#category_long_description_full').show(); $(this).hide(); return false;" class="lnk_more">{l s='More'}</a>

                    {else}

                         <p>{$category->long_description}</p>

                    {/if}

                    </div>

               {/if}



	{elseif $category->id}
		<p class="warning">{l s='This category is currently unavailable.'}</p>
	{/if}
{/if}

-- END OF FILE --

 

Edit file: controllers/admin/AdminCategoriesController.php  (Backup first...)

just under:

				array(
					'type' => 'textarea',
					'label' => $this->l('Description:'),
					'name' => 'description',
					'autoload_rte' => true,
					'lang' => true,
					'rows' => 10,
					'cols' => 100,
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),

add:

 

                    array(

                         'type' => 'textarea',

                         'label' => $this->l('Long description:'),

                         'name' => 'long_description',

                         'autoload_rte' => true,

                         'lang' => true,

                         'rows' => 10,

                         'cols' => 100,

                         'hint' => $this->l('Invalid characters:').' <>;=#{}'

                    ),

 

 

That should do the trick.

pascal

 

!!!!

N.B. Be careful when updating PrestaShop, as the ps_category_lang may be overwritten. So save your table field contents before updating!

 

attachicon.gifcategory long desc.jpg

attachicon.gifproduct-list long desc.jpg

HI pascal i have made the above said thing but the data is not getting inserted in the particular field in the database any help.

Link to comment
Share on other sites

  • 3 months later...

Hi Pascal,

do you think that you can adapt to the latest version of prestashop ?
I purchased Visual Composer module, but this does not apply to longdescription .
Smartdatasoft argues that this change is old and Visual Composer just fits the description.

Tnk u

 

 

 

What PS version do you use?

 

pascal.

Link to comment
Share on other sites

Hi webprog 

 

i purchase additional description module but i dont have any idea as apply visual composer. Smartdatasoft send me this link https://smartdatasoft.zendesk.com/hc/en-us/articles/206598599-My-vc-short-code-show-in-smratblog-post-page- but i dont understand what should i do.

 

Do u have any idea ?

Tnks

 

 

You can buy module with second category descriptions here:

http://addons.prestashop.com/en/16778-additional-description-category-new.html

Link to comment
Share on other sites

  • 4 months later...
  • 3 weeks later...
  • 2 months later...
  • 9 months later...

Does anyone have a way to do this in 1.6?

I looked at the module linked a few posts above but you have to jump between creating new additional categories on the module page and the normal Edit Category page. I want to edit both descriptions on the existing Edit Category page.

Link to comment
Share on other sites

  • 5 weeks later...
On 10.12.2017 at 10:28 PM, TurkeyFish said:

Does anyone have a way to do this in 1.6?

I looked at the module linked a few posts above but you have to jump between creating new additional categories on the module page and the normal Edit Category page. I want to edit both descriptions on the existing Edit Category page.

 

You can find these functions in the module:

https://addons.prestashop.com/en/page-customization/16778-additional-description-category-new.html

Edited by webprog (see edit history)
Link to comment
Share on other sites

  • 4 months later...
  • 5 months later...
  • 2 months later...
  • 7 months later...
  • 1 year later...

Hello,

I'm trying to add the second description therefore I followed your instructions, but I have an issue.

I'm working with the 1.6.1.5 version so I followed the 1.6 instructions. It's almost working perfectly. If I add the text (for the second description) using the data base I can see it on my weebsite it's all good.

However the issue is about the backoffice. The differents categories are not here anymore.
image.thumb.png.933a8d7007e2789ce15a349923c8e657.png

That's what I see when I'm in catalogue/categories.
Following the instructions I realised I do not have a "getTranslationsFieldsChild()" function in Category.php. So maybe it's because of this ?

I don't know how to fix it can any of you help me please ?

Thank you in advance.

Link to comment
Share on other sites

  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...