Please help us to make AbanteCart Ideal Open Source Ecommerce Solution for everyone.

Support AbanteCart eCommerce

Author Topic: Short product description ?!?  (Read 15004 times)

Offline cookie

  • Jr. Member
  • **
  • Posts: 65
  • Karma: +10/-0
    • View Profile
Short product description ?!?
« on: January 20, 2014, 06:26:11 PM »
How can we have something like a short description to be displayed for a product on the category listing page (the grid view), just under the image and before the "add to cart" button?

I have noticed you use the full product description in the "row" listing, which I don't think it's a great idea either. No user wants to see in a product listing the products with their full (!) descriptions. So this too should be somehow truncated.

All shopping carts have such an option and it's very useful to give the visitor an idea about what the product is about ... (but not let him read the whole story there)

An "in extremis" solution could be to use the first 200 characters (or first N words) from the usual description as a short description, anyone knows how can we achieve that (the code ?!) ?

I tried to adds smth. like this in product_listing.tpl but it did not work ...

Code: [Select]
<?php
 $text1 
$product['description'];
private function 
truncate($text1$length) {
   
$length abs((int)$length);
   if(
strlen($text1) > $length) {
      
$text preg_replace("/^(.{1,$length})(\s.*|$)/s"'\\1...'$text1);
   }
   return(
$text1);
}

  
?>

Could anyone please react to this and offer some help?

Thx a lot!
« Last Edit: January 21, 2014, 08:02:44 PM by cookie »

Offline cookie

  • Jr. Member
  • **
  • Posts: 65
  • Karma: +10/-0
    • View Profile
Re: Short product description ?!?
« Reply #1 on: January 25, 2014, 07:31:04 PM »
ANYONE?

gordontaylor

  • Guest
Re: Short product description ?!?
« Reply #2 on: January 25, 2014, 08:13:05 PM »
How can we have something like a short description to be displayed for a product on the category listing page (the grid view), just under the image and before the "add to cart" button?

I have noticed you use the full product description in the "row" listing, which I don't think it's a great idea either. No user wants to see in a product listing the products with their full (!) descriptions. So this too should be somehow truncated.

All shopping carts have such an option and it's very useful to give the visitor an idea about what the product is about ... (but not let him read the whole story there)

An "in extremis" solution could be to use the first 200 characters (or first N words) from the usual description as a short description, anyone knows how can we achieve that (the code ?!) ?

I tried to adds smth. like this in product_listing.tpl but it did not work ...

Code: [Select]
<?php
 $text1 
$product['description'];
private function 
truncate($text1$length) {
   
$length abs((int)$length);
   if(
strlen($text1) > $length) {
      
$text preg_replace("/^(.{1,$length})(\s.*|$)/s"'\\1...'$text1);
   }
   return(
$text1);
}

  
?>

Could anyone please react to this and offer some help?

Thx a lot!

An easy work around would be to add the text to the image in your image editor....

Offline cookie

  • Jr. Member
  • **
  • Posts: 65
  • Karma: +10/-0
    • View Profile
Re: Short product description ?!?
« Reply #3 on: January 25, 2014, 08:26:34 PM »
and than the same text will appear in the main product page as well  :(
I also doubt I'll want to modify image files anytime I have a small text change (leave alone the fact that it's quite difficult to find an image in the image library)

So I still need the php part I am afraid ...

(hey, but thx!)

gordontaylor

  • Guest
Re: Short product description ?!?
« Reply #4 on: January 26, 2014, 08:57:42 AM »

I tried to adds smth. like this in product_listing.tpl but it did not work ...

Code: [Select]
<?php
 $text1 
$product['description'];
private function 
truncate($text1$length) {
   
$length abs((int)$length);
   if(
strlen($text1) > $length) {
      
$text preg_replace("/^(.{1,$length})(\s.*|$)/s"'\\1...'$text1);
   }
   return(
$text1);
}

  
?>
OK, with that php you're calling a table labeled 'description'. Does such a table exist? If so, where in the Admin panel is the input for it?

Those fields you fill out in the admin panel are inputs to the php tables. You ad the info to that table via the input fields in the admin template. I'm not sure why you're calling that table, I don't see a place for the input in the admin template.

If there is NOT a table for that short description, you'd need to create the table and either fill it manually or alter the admin template to create an input field for it. In other words, you'd nearly need to create an extension for that purpose.



Offline cookie

  • Jr. Member
  • **
  • Posts: 65
  • Karma: +10/-0
    • View Profile
Re: Short product description ?!?
« Reply #5 on: January 26, 2014, 09:16:58 AM »
Gordon, look in product.tpl file !
The
Code: [Select]
product['description'] is actually THE code outputing the FULL product description (the one and only you can enter in admin).

All I am trying at this stage is to truncate that description somehow to be able to get the first X characters or Y words.

I just need the damn ( :o) php code for this as my version is for whatever reason not working  >:(

You know php?
« Last Edit: January 26, 2014, 09:19:58 AM by cookie »

gordontaylor

  • Guest
Re: Short product description ?!?
« Reply #6 on: January 26, 2014, 10:04:31 AM »
OK, now I understand what you're trying to do. You won't be able to truncate that description, you'll need to create a new table and call that table.

Offline cookie

  • Jr. Member
  • **
  • Posts: 65
  • Karma: +10/-0
    • View Profile
Re: Short product description ?!?
« Reply #7 on: January 26, 2014, 01:23:04 PM »
I don't understand ... why can't I truncate the description !?!? It's quite a common function, no?
My problem is that I am not a programmer, I know a few things here and there, but not that much ..
That's why I hope to find some php guru around here to help with these little things  ::)

gordontaylor

  • Guest
Re: Short product description ?!?
« Reply #8 on: January 26, 2014, 02:17:46 PM »
I can hear your frustration Cookie and I empathize with you, I really do.

Let me see what I can come up with and I'll let you know if it works.

Gordon

Offline llegrand

  • Hero Member
  • *****
  • Posts: 1811
  • Karma: +526/-7
    • View Profile
Re: Short product description ?!?
« Reply #9 on: January 26, 2014, 02:30:27 PM »
Here's a link to some scripts that have options for truncating strings,  or by words or length, etc.  Might be a good place to start.


http://www.the-art-of-web.com/php/truncate/


If you figure out how to do this,  and add it to the image on the product pages - that would be cool.  I think Junkyard was looking for something like that awhile back.

Lee

gordontaylor

  • Guest
Re: Short product description ?!?
« Reply #10 on: January 26, 2014, 03:03:02 PM »
Thanks for the link, I'll look at it. I'm pretty good with coding.

gordontaylor

  • Guest
Re: Short product description ?!?
« Reply #11 on: January 26, 2014, 03:44:32 PM »
Woot woot....I'll have a working example shortly!

@cookie, you resolution is at hand!!

The question is now "How many characters do you want in the truncated text?

It can be any number, best if broken at the end of a word on the space"
« Last Edit: January 26, 2014, 04:17:50 PM by gordontaylor »

Offline cookie

  • Jr. Member
  • **
  • Posts: 65
  • Karma: +10/-0
    • View Profile
Re: Short product description ?!?
« Reply #12 on: January 26, 2014, 05:37:02 PM »
Hey guys, you are cool  ::)

I got this one working eventually  ;D

Here's the damn  :o code :

add this on top of product_listing.tpl

Code: [Select]
<?php
function myTruncate($string$limit$break="."$pad="...") {

if(
strlen($string) <= $limit) return $string

if(
false !== ($breakpoint strpos($string$break$limit))) {

if(
$breakpoint strlen($string) - 1) { 
$string substr($string0$breakpoint) . $pad
}
 }
 return 
$string;
 }
 
?>

than add this bit of code where you want your short description to show (I used it just bellow the image):

Code: [Select]
<div class="productdiscrption">
            <?php
$shortdesc 
myTruncate($product['description'], 150" "); 
echo 
"$shortdesc"?>
<a class="details" href="<?php echo $item['info_url']?>">[read more]</a></div>

Replace 150 chars with the nr. of characters you want.
The above code keeps the last word (not truncating it :))

hey, we are fixing abantecart  8)
« Last Edit: January 26, 2014, 05:39:13 PM by cookie »

gordontaylor

  • Guest
Re: Short product description ?!?
« Reply #13 on: January 26, 2014, 07:08:48 PM »
Good deal Cookie, nice work. I did the same, using # of words option.

I think I'll write an extension for this, then all that will be required is to add one little string where you want the text to appear.

Gordon

Offline flyn

  • Full Member
  • ***
  • Posts: 142
  • Karma: +8/-0
    • View Profile
Re: Short product description ?!?
« Reply #14 on: August 19, 2014, 11:59:04 AM »
I know this thread is old but I want to chime in here. Cookie good job by you on this.

I tried it but not on the category/product listing page but on the actual product detail page. It worked but it gave me the whole description. How can I get it to only show 150 characters?

Here is a product detail page of ours: http://www.hygienics.com/mens-underwear/mature-basics-fluid-resistant-underwear

I would like a short description above the 3 circle graphics. It would sit between that and the name of the product

 

Powered by SMFPacks Social Login Mod