Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Truncated best_sellers.php


strictlypc

Recommended Posts

Hi There,

 

I was wondering if anyone modified or could help me with a truncated best_sellers.php?

 

For example:

 

32" Sony XBR Stereo HDTV Ready Television

 

TO BE DISPLAYED AS:

 

32" Sony XBR Stereo...

 

If anyone has the code and can email me at david@strictlypc.com, that would be great.

 

Thanks,

David

Link to comment
Share on other sites

Here is a function to truncate it at whatever length you wish without breaking a word:

 

function osc_trunc_string($str="",$len=150,$more=1)

{

 if ($str=="") return $str;

 if (is_array($str)) return $str;

 $str = trim($str);

 // if it's les than the size given, then return it

 if (strlen($str) <= $len) return $str;

 // else get that size of text

 $str = substr($str,0,$len);

 // backtrack to the end of a word

 if ($str != "") {

	 // check to see if there are any spaces left

	 if (!substr_count($str," ")) {

   if ($more) $str .= "...";

   return $str;

	 }

	 // backtrack

	 while(strlen($str) && ($str[strlen($str)-1] != " ")) {

   $str = substr($str,0,-1);

	 }

	 $str = substr($str,0,-1);

	 if ($more) $str .= "...";

 }

 return $str;

}

"It's a damn poor mind that can only think of one way to spell a word."

-- Andrew Jackson

Link to comment
Share on other sites

Hi Paul,

 

Thanks for your reply. I've tried implementing your code onto my best_sellers.php and could not get it to work. The following is my best_sellers.php:

 

<?php

/*

 $Id: best_sellers.php,v 1.19 2002/06/05 20:59:08 dgw_ Exp $



 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com



 Copyright (c) 2001 osCommerce



 Released under the GNU General Public License

*/

?>

<!-- best_sellers //-->

<?php

 if ($cPath) {

   $best_sellers_query = tep_db_query("select distinct p.products_id, pd.products_name, p.products_ordered from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and (c.categories_id = '" . $current_category_id . "' OR c.parent_id = '" . $current_category_id . "') order by p.products_ordered DESC, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);

 } else {

   $best_sellers_query = tep_db_query("select p.products_id, pd.products_name, p.products_ordered from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' order by p.products_ordered DESC, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);

 }



 if (tep_db_num_rows($best_sellers_query) >= MIN_DISPLAY_BESTSELLERS) {

?>

         

  	 <tr>

           <td>

<?php

   $info_box_contents = array();

   $info_box_contents[] = array('align' => 'left',

                                'text'  => BOX_HEADING_BESTSELLERS

                               );

   new infoBoxHeading($info_box_contents, false, false);



   $rows = 0;

   $info_box_contents = array();

   while ($best_sellers = tep_db_fetch_array($best_sellers_query)) {

     $rows++;

     $info_box_contents[] = array('align' => 'left',

                                  'text'  => tep_row_number_format($rows) . '. <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id'], 'NONSSL') . '">' . $best_sellers['products_name'] . '</a>');

   }



   new infoBox($info_box_contents);

?>

           </td>

         </tr>

<?php

 }

?>

<!-- best_sellers_eof //-->

 

what would i need to do to make this work? Thanks for your help.

 

David

Link to comment
Share on other sites

I haven't tested this, so please backup your files before trying it.

 

Add the function I posted above to the bottom of your catalog/includes/functions/general.php (it's a handy function that you may find yourself wanting to use again elsewhere) and replace your best_sellers.php with the following:

<?php 

/* 

$Id: best_sellers.php,v 1.19 2002/06/05 20:59:08 dgw_ Exp $ 



osCommerce, Open Source E-Commerce Solutions 

http://www.oscommerce.com 



Copyright (c) 2001 osCommerce 



Released under the GNU General Public License 

*/ 

?> 

<!-- best_sellers //--> 

<?php 

if ($cPath) { 

 $best_sellers_query = tep_db_query("select distinct p.products_id, pd.products_name, p.products_ordered from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and (c.categories_id = '" . $current_category_id . "' OR c.parent_id = '" . $current_category_id . "') order by p.products_ordered DESC, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS); 

} else { 

 $best_sellers_query = tep_db_query("select p.products_id, pd.products_name, p.products_ordered from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' order by p.products_ordered DESC, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS); 

} 



if (tep_db_num_rows($best_sellers_query) >= MIN_DISPLAY_BESTSELLERS) { 

?> 

    

         <tr> 

     <td> 

<?php 

 $info_box_contents = array(); 

 $info_box_contents[] = array('align' => 'left', 

                'text' => BOX_HEADING_BESTSELLERS 

               ); 

 new infoBoxHeading($info_box_contents, false, false); 



 $rows = 0; 

 $info_box_contents = array(); 

 while ($best_sellers = tep_db_fetch_array($best_sellers_query)) { 

  $rows++; 

  $info_box_contents[] = array('align' => 'left', 

                 'text' => tep_row_number_format($rows) . '. <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id'], 'NONSSL') . '">' . osc_trunc_string($best_sellers['products_name'], 19) . '</a>'); 

 } 



 new infoBox($info_box_contents); 

?> 

     </td> 

    </tr> 

<?php 

} 

?> 

<!-- best_sellers_eof //-->

 

Change the "19" (couple lines above "new infoBox($info_box_contents);")

To whatever you would like the maximum number of characters displayed to be.

 

I think that should do it, but again I haven't tested this.

"It's a damn poor mind that can only think of one way to spell a word."

-- Andrew Jackson

Link to comment
Share on other sites

  • 7 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...