Post by graf1771 » Fri May 15, 2009 11:27 pm

Hi,

I'm creating a custom install for a client and am trying to pull a shortened version of the product description into the homepage and search page.

Is there a simple way to do this that doesn't requite database fiddling? I've gone through the controllers but probably missed something as I'm not very good with php...

thanks

Newbie

Posts

Joined
Mon Apr 21, 2008 8:14 pm

Post by phpuk » Fri May 15, 2009 11:38 pm

Hi,

In the display area (template) use something like this:

Code: Select all

substr(strip_tags($query->row['description']),0,25) . "..."
Replace description with the name of the field you wish to truncate and the 25 with the number of characters you want to display before the ellipse ...

Phil.

Global Moderator

Posts

Joined
Wed Mar 25, 2009 10:57 am

Post by graf1771 » Fri May 15, 2009 11:58 pm

That's the sort of thing I need, just I can't get the description to be pulled onto the pages I need, I tried this:

Code: Select all

<?php echo $products[$j]['description']; ?>
but it doesn't work - I'm guessing that I need to make a more fundamental change somewhere?

Newbie

Posts

Joined
Mon Apr 21, 2008 8:14 pm

Post by d33p » Tue Jun 16, 2009 9:39 pm

phpuk wrote:Hi,

In the display area (template) use something like this:

Code: Select all

substr(strip_tags($query->row['description']),0,25) . "..."
Replace description with the name of the field you wish to truncate and the 25 with the number of characters you want to display before the ellipse ...

Phil.
I am trying this right now, but I am not a php-coder

In catalog/controller/product/product.php around line 133 i inserted

Code: Select all

'short_description' => substr(strip_tags($result['description']),0,50). "...",
I display it in view/theme/template/default/template/product/category.tpl with

Code: Select all

<?php echo $products[$j]['short_description']; ?>
Basically it works, but the tags are not being stripped yet. At http://us3.php.net/manual/en/function.strip-tags.php it says, that squared brackets are used to exclude tags from being stripped. Does it have to do something with that?

Could any of you PHP-Guys please give me a hint?
Help's appreciated,
Thanks
Claus

Newbie

Posts

Joined
Tue May 26, 2009 12:11 am

Post by d33p » Tue Jun 23, 2009 12:28 am

Anybody?

Newbie

Posts

Joined
Tue May 26, 2009 12:11 am

Post by readyman » Wed Jun 24, 2009 5:20 am

Try this instead...

Code: Select all

'shortdescription'  => html_entity_decode(substr($result['description'],0,50))."...",
Your above edits to the files don't seem to add up though... you need the make changes to category.php and category.tpl.
The category.tpl doesn't appear in controller/product/product.php as far as I can see.

Let me know if this works for you.

http://www.alreadymade.com
Follow me on twitter.com/alreadymade


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney

Post by d33p » Thu Jun 25, 2009 6:26 pm

Sorry, that was a typo. I meant to say that I edited both, the category.php and category.tpl and it basically works. My Problem is that the tags are NOT being stripped.

It's rather a lack of basic PHP-Knowledge-Kind-Of-Problem. If anybody could just give me a hint where to look for the problem I would try to find my way through. :)

Thank you in advance,
Claus

Newbie

Posts

Joined
Tue May 26, 2009 12:11 am

Post by readyman » Fri Jun 26, 2009 2:25 pm

Did this work for you? I'll post the files you need if you are still having issues.

http://www.alreadymade.com
Follow me on twitter.com/alreadymade


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney

Post by d33p » Fri Jun 26, 2009 4:39 pm

Sorry Readyman,
i somehow totally skipped the first part of your message... err
Your solution works fine, thanks a lot... I should get more into php I guess...

Have a nice weekend,
Claus

Newbie

Posts

Joined
Tue May 26, 2009 12:11 am

Post by ThePath » Sat Jun 27, 2009 12:20 am

Hi Readyman,

Im just wondering if you have a better solution to this issue. I followed instructions and came across some issues. One issue was it displays the text as is; that is to say if your first line of text is bold it will display bold in the short description, obviously the first line may change from bold to normal for different product descriptions, so it doesnt look good. Another issue I found was the 1st product to display a short description either failed to do so or displayed something weird. Another was the short description doesnt seem to get passed a carriage return in the main description and so stops short.

What would be perfect was if I could enter a short description in admin to be displayed. How would I go about this?

Thanks in advance!

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by d33p » Sat Jun 27, 2009 12:23 am

Yes, custom fields in the product description would indeed be very, very helpful.

Newbie

Posts

Joined
Tue May 26, 2009 12:11 am

Post by readyman » Sun Jun 28, 2009 2:18 pm

@thepath - I'll look into adding a "short description" add-on.
It will require:
- adding a field in the database for the 'product summary'
- making the field in the admin pages to add content to it.
- retrieving and putting the summary in the product list in the front end.

Pretty straight forward.

@d33p - custom fields in the description? Sounds like it's something else entirely - can you elaborate on that one?

http://www.alreadymade.com
Follow me on twitter.com/alreadymade


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney

Post by ThePath » Sun Jun 28, 2009 11:02 pm

Nice one readyamn!

Simple for those familiar with the opencart structure and well versed in php. For a dumb bum like moi however not so straight forward Im afraid. Waaaa ;)

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by make-oc » Thu Jul 02, 2009 2:32 pm

Just a thought… why not use the "Meta Tag Description" -- could do the job ;-)

New member

Posts

Joined
Tue Apr 07, 2009 2:17 pm

Post by readyman » Sat Jul 04, 2009 3:42 pm

Yep that's correct, it's exactly the same as the meta tag description, but it will just display in a different part of the template to just give you more control.

http://www.alreadymade.com
Follow me on twitter.com/alreadymade


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney

Post by ThePath » Thu Jul 09, 2009 6:46 am

Hey Readyman just wondering if there was any progress on this one.

Cheers

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by gxpratama » Sat Apr 10, 2010 12:49 am

ThePath wrote:Hey Readyman just wondering if there was any progress on this one.

Cheers
Yeah, also in need of this capabilities now. Anyone knows how to do it the simple way in 1.4.6?

Regards,

User avatar
New member

Posts

Joined
Wed Mar 31, 2010 4:50 am

Post by helenmarie » Tue Jul 06, 2010 7:58 pm

I am also wondering how to get a short description to display on the homepage, has anyone had any joy with this?

Helen ;D

User avatar
New member

Posts

Joined
Sat Nov 07, 2009 1:05 am

Post by Qphoria » Tue Jul 06, 2010 10:52 pm

1a. If using 1.4.8 or later, EDIT: catalog/controller/module/latest.php
1b. If using 1.4.7 or earlier, EDIT: catalog/controller/common/home.php

2. FIND:

Code: Select all

'name'            => $result['name'], 
3. AFTER, ADD:

Code: Select all

'description'    => strip_tags(substr(html_entity_decode($result['description']),0,80))."...", 
4a. If using 1.4.8 or later, EDIT: catalog/view/theme/default/template/module/latest_home.tpl
4b. If using 1.4.7 or earlier, EDIT: catalog/view/theme/default/template/common/home.tpl

5. FIND:

Code: Select all

<?php if ($display_price) { ?>
6. BEFORE, ADD:

Code: Select all

<?php echo $products[$j]['description']; ?>

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by helenmarie » Tue Jul 06, 2010 11:52 pm

hi Q,

Thank you for your reply.

I am using 1.4.7 :(

User avatar
New member

Posts

Joined
Sat Nov 07, 2009 1:05 am
Who is online

Users browsing this forum: No registered users and 16 guests