Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

how can I truncate the product description to be a kind of 'product precview'


dahui

Recommended Posts

Posted

Hi @ll

 

I have a custom made top-10-products page, where I use the description and truncate it by characters so far I read about some solutions to truncate by word and tried but without success

 

is there a contrib or howto out there todo that?

 

dahui

 

 

 

so far I do it like this to be ssen here >> http://elflein-kosmetik.de/most_sold_prod.php

 

<?php
 if ($products_new_split->number_of_rows > 0) {
$products_new_query = tep_db_query($products_new_split->sql_query);
while ($products_new = tep_db_fetch_array($products_new_query)) {
  if ($new_price = tep_get_products_special_price($products_new['products_id'])) {
	$products_price = '<s>' . $currencies->display_price($products_new['products_price'], tep_get_tax_rate($products_new['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($products_new['products_tax_class_id'])) . '</span>';
  } else {
	$products_price = $currencies->display_price($products_new['products_price'], tep_get_tax_rate($products_new['products_tax_class_id']));
  }
?>
	  <tr>
		<td width="<?php echo SMALL_IMAGE_WIDTH + 10; ?>" valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $products_new['products_image'], $products_new['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>'; ?></td>
		<td valign="top" class="main">N?<?php echo $rank++ . ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_new['products_id']) . '"><b><u>' . $products_new['products_name'] . '</u></b></a><br>' . $truncated = substr($products_new['products_description'], 0, 110) . '...<br><div align="right" style="font-size:10; font-weight: bold;">' . $products_price;?>	</div></td>
		<td align="right" valign="middle" class="main">  <?php echo '<a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $products_new['products_id']) . '">' . tep_image_button('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</a>'; ?></td>
	  </tr>
	  <tr>
		<td colsp?an="3"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	  </tr>
<?php
}
 } else {
?>
	  <tr>
		<td class="main"><?php echo TEXT_NO_BESTSELLER; ?></td>
	  </tr>

Posted

hi mike, see this contribution, it builds a separate description for each product. (separate in terms you add a separate brief description. You can check out my site see how it looks).

 

http://www.oscommerce.com/community/contributions,3123

 

For the standard short description you can change the tep_flatten_product_description function to return the string on the last space it encounters before the end of the max length of characters. That contrib grabs a predefined number of chars from a string.

 

Contrib here: http://www.oscommerce.com/community/contributions,1743

 

So the function could become like this:

 

function tep_flatten_product_description($description, $link)
{
$description = ereg_replace('<[^>]*>', '', $description);
if (strlen($description) > PRODUCT_LIST_DESCRIPTION_MAX_LENGTH){

$description = substr($description, 0, PRODUCT_LIST_DESCRIPTION_MAX_LENGTH);
$description = substr(strrchr($descritpion, ' '));
$description .= $link;
}else {
$description .= $link;
}
return $description;
}

Archived

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

×
×
  • Create New...