Post by monostudio » Sat Oct 15, 2011 4:27 am

New to this board and working on a couple of sites at the moment. I am trying to extend the truncated text in the product listings - where you can view by list or grid so we can get a full sentence in there and it doesn't get cut off (in list view).
Trying to avoid this sort of thing: Vivaspin centrifugal concentrators are disposable ultrafiltration devices for the concentration o..
Hope you can help - am working in 1.5.1
Cheers
Tim

Newbie

Posts

Joined
Sat Oct 15, 2011 4:05 am

Post by JAY6390 » Sat Oct 15, 2011 7:12 am

Hi Tim. Here's a little function you can use (put it at the top of the template file

Code: Select all

<?php

if(!function_exists('get_snippet')) {
    function get_snippet($sentence, $count = 5, $separator = ' ') {
        $count = (int) $count;
        if(!$count) return '';
        
        $words = array_chunk(explode($separator, $sentence), $count);
        return implode($separator, $words[0]);
        
    }
}
?>
Then for the text, you just wrap it in parentheses and put get_words before it, optionally specifying the word count
For example, you could change

Code: Select all

<?php echo $product['description']; ?>
to

Code: Select all

<?php echo get_snippet($product['description'], 15); ?>

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by monostudio » Tue Oct 18, 2011 5:14 am

Thanks for the rapid reply Jay - sorry don't want to break it, so which file do you change? Sorry to ask but am new to this.
Thanks Tim

Newbie

Posts

Joined
Sat Oct 15, 2011 4:05 am

Post by JAY6390 » Tue Oct 18, 2011 5:17 am

It depends which page. The main ones I'm guessing will be

Code: Select all

/catalog/view/theme/your-theme-name/template/product/product.tpl
/catalog/view/theme/your-theme-name/template/product/category.tpl
/catalog/view/theme/your-theme-name/template/product/manufacturer_info.tpl
/catalog/view/theme/your-theme-name/template/product/search.tpl

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by monostudio » Fri Oct 21, 2011 6:51 am

Thanks for the input - have been working on the category.tpl. The code seems to work to shorten the number of words - ie less than 15 - if I increase this number nothing seems to happen.
ie <?php echo get_snippet($product['description'], 30); ?>
Perhaps there is something else preventing any more words to be added. Test site is
generonshop.co.uk/generon - still work in progress.

Newbie

Posts

Joined
Sat Oct 15, 2011 4:05 am

Post by JAY6390 » Fri Oct 21, 2011 5:18 pm

Are you sure there are more than 15 words?

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by monostudio » Fri Oct 21, 2011 5:44 pm

Hi Jay - thanks for all your help on this. Go to:
http://generonshop.co.uk/generon/index. ... path=71_72
You will see the description at the top that is being used for all this range of products at the moment.

The full description:
The BJP concentrates urine through the absorption of water by absorbent pads located on the underside of an ultrafiltration membrane. Bence Jones protein will be retained on the membrane surface in the front compartment of the BJP unit because it has a 7.5 kDa MWCO membrane, a molecular weight cut-off far from the molecular weight of Bence Jones protein itself.

The truncated text cuts as:
The BJP concentrates urine through the absorption of water by absorbent pads located on the under..

It's 15 + a bit words - perhaps I am referring to the wrong text or something?

Cheers
Tim

Newbie

Posts

Joined
Sat Oct 15, 2011 4:05 am

Post by JAY6390 » Fri Oct 21, 2011 5:48 pm

Ah, the problem will be that it contains HTML actually. it won't work with HTML content

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by monostudio » Fri Oct 21, 2011 5:53 pm

So you reckon this text snippet cannot be expanded to show a bit more?

Newbie

Posts

Joined
Sat Oct 15, 2011 4:05 am

Post by JAY6390 » Fri Oct 21, 2011 5:56 pm

Hi Tim. The problem is that the snippet cuts off the end tags of the HTML, so it could totally mess up your page. I would therefore advise against this

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by monostudio » Fri Oct 21, 2011 6:05 pm

Last question before I abandon this ;-) - am playing with CSS in firebug - could this tweaked to show more or even have no description snippet at all to clean the listings up? Thanks T

Newbie

Posts

Joined
Sat Oct 15, 2011 4:05 am

Post by JAY6390 » Fri Oct 21, 2011 6:21 pm

You can certainly get rid of the description snippets sure. As for the css option, I don't think there's any way of doing this with that

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by travoltron » Thu Dec 01, 2011 1:12 am

The file in question you'd like to update is: /catalog/controller/product/category.php

Line 186:

Code: Select all

'description' => substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
Change to:

Code: Select all

'description' => substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 900) . '',
Increasing the number of parsed characters from 100 to 900 (or whatever you need it to, and if you add ending punctuation in your descriptions, remove the

Code: Select all

'..'
and change it to

Code: Select all

''
, to remove the trailing ellipses.

Hope it helps!

Newbie

Posts

Joined
Fri Nov 04, 2011 4:07 am

Post by albsim81 » Tue Feb 21, 2012 3:10 pm

Thank you.
But, in your opinion ther is a problem of duplicate content now, between product and category page?

Sigaretta elettronica Opencart 1.5.4.1 italian translation


New member

Posts

Joined
Wed Jan 26, 2011 5:14 am
Location - Italy

Post by monostudio » Thu Feb 23, 2012 12:10 am

Thanks for the input - will have a look at some point again. Been diverted onto other areas of Opencart to modify now!
Cheers

Newbie

Posts

Joined
Sat Oct 15, 2011 4:05 am

Post by billshakes » Mon Jul 02, 2012 4:55 pm

I have been looking for a similar solution and followed travoltron php change to allow full description text (no truncation) in list view which is great but I would also like to show the audio player in list view that I have in full product view>source>html.

e.g.

<p>
<object data="dewplayer.swf" height="20" id="dewplayer" name="dewplayer" type="application/x-shockwave-flash" width="200"><param name="movie" value="dewplayer.swf" /><param name="flashvars" value="mp3=../sampleguitar/mp3/test1.mp3" /><param name="wmode" value="transparent" /></object></p>

Is it possible to show the individual product audio flash player in the List view?

Any help greatly appreciated!

Toby

Newbie

Posts

Joined
Wed Jun 27, 2012 4:46 pm

Post by arthurmild » Sun Oct 13, 2013 4:46 pm

To stop/edit trunctation of product description in OpenCart 1.5.6

In catalog/controller/product/category.php

search for the line

Code: Select all

$this->data['products'][] = array(
then

change :

Code: Select all

'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
to:

Code: Select all

'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 999),
the 999 is the number of characters that will display before being truncated, so alter this to suit yourself




The . '..' at the end of the original line is what displays after truncation,

so if you wanted truncation, but not the default dots you could to amend this to e.g.

Code: Select all

. '... more...' 
this would be the place to do it.

Newbie

Posts

Joined
Sun Sep 22, 2013 5:36 pm

Post by maxxpaul » Wed Aug 31, 2016 6:07 pm

Finally I managed to find a solution to this and it's working beautifully.
I know this is an old thread but there might be people who still use OpenCart 1.5.6.4.
Also I wanted to make a contribution to the community.

So .... in order to truncate the description text in product lists to only to full words, and only if the initial string's length is larger than the wanted one, here is the new code.

Find in:
in catalog/controller/product/ folder, in these 4 files:
category.php
manufacturer.php
search.php
special.php

the following line:

Code: Select all

'description' => substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
(assuming 100 is the default value, if not, search only for the first part of the line)

And replace with:

Code: Select all

'description' => (strlen(utf8_decode(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))))> 400 ? mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, mb_strrpos(mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 400, 'UTF-8'), ' ', 0, 'UTF-8'), 'UTF-8') : strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))) . '...',
Adjust the 400 value to your needs. Keep in mind that, using the default layout / template, the product listing in category has a lower width (because on one side there is the categories column), and in product, search and special has the full with of the content column.
Depending on the font used, you might get 2 1/2 rows of text in special.php, search.php and manufacturer.php using a value of 400 and a little more than that using 350 in category.php

Newbie

Posts

Joined
Wed Aug 31, 2016 5:53 pm

Post by IP_CAM » Sat Sep 03, 2016 8:04 am

I just tried it with the files, and it seems to work well in my latest v.1.5.6.5_rc Test Shop. And looks much better too !

It only does not work on the product Page, for related items, where I added a $desc Variable - calling the $description Value, to add the Description to the related items also. So, I modified your 'content' accordingly, to match the above variable, but there, it presents an error, and the entire page does not longer display. But since I don't need to have it in the related Products, because of lots of free space, I just don't use it there anyway! ::)

Code: Select all

'desc' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 240) . '.',
Sample Page:
http://www.gratis-anzeiger.com/shop/ind ... ry&path=33
Don't look at the Words, or try to understand the meaning, they are auto-generated! :laugh:
Still, Google, Amazon, & Co. seemengly indexes them, on a steady pace!
Thank you ! ;)
Ernie

PS: OC v.1.5.6.x is not old, it's just grown-up!
http://www.merriam-webster.com/dictiona ... E2%80%93up

My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by jyeann » Tue Sep 20, 2016 11:54 am

Hi,

Is there a way to truncated the product name? currently on version '2.0.3.1' .

thanks.

Newbie

Posts

Joined
Tue Sep 20, 2016 11:35 am
Who is online

Users browsing this forum: No registered users and 207 guests