Post by enache » Tue Sep 30, 2008 4:18 am

hello everybody and thanks a lot for that hard working to develop opencart, i'd like to make a very very small contribution because i search for something like this and didn't find it, maybe someone else will need it, so if anybody has the problem that doesn't know how to reduce the product name in the category page here it is
open catalog\controller\category.php you i'l have something like this

Code: Select all

        		foreach ($results as $result) {
          			$query = array(
            			'path'       => $request->get('path'),
            			'product_id' => $result['product_id']
          			);

          			$product_data[] = array(
            			'name'  => $result['name'],
				'href'  => $url->href('product', FALSE, $query),
 
you need to create a strlen function to reduce name , like this

Code: Select all

 				function reduce_str($text, $size)
				{
				$length = strlen($text);
				if($length>$size)
				{
				$length_fin = substr($text, 0, $size);
				$text = $length_fin."..."; 
				}
				return($text); 
				}
				
				
        		foreach ($results as $result) {
          			$query = array(
            			'path'       => $request->get('path'),
            			'product_id' => $result['product_id']
          			);

          			$product_data[] = array(
            			'name'  => reduce_str($result['name'],9),
            			'href'  => $url->href('product', FALSE, $query),

and put instead of "9 ", number of character you want the name to be reduce,

hope it was helpful like it was it for me
ps : sorry for my english :-[

Newbie

Posts

Joined
Tue Sep 30, 2008 3:59 am

Post by JohnnyO » Tue Sep 30, 2008 5:16 am

This could be useful .. Especially to us template people  ;D

Thanks! .. Bookmarked

If you make it idiot proof, they will just build a better idiot.


User avatar
New member

Posts

Joined
Wed Nov 14, 2007 7:31 am
Location - Denver, CO - USA

Post by bthirsk » Thu Oct 09, 2008 9:59 pm

Another thing you might like to add to your function is a method to control how many
characters you actually display.
I limit my first line of description to 30 displayable characters.

This code will display them all.
42){
  $short = substr($short,0,42);
    }
}else{
$short = trim(substr(strip_tags($short), 0, 40));
}
return $short;
}
?>

When you mix in HTML such as bold, ", &, they all are included in your count, but are not displayable.
Brent

Brent


User avatar
Active Member

Posts

Joined
Wed Sep 03, 2008 11:33 am
Location - Canada
Who is online

Users browsing this forum: No registered users and 4 guests