mugitty Posted December 11, 2004 Posted December 11, 2004 I'm using the Star Product contribution which has a provision to limit the number of charcters that are returned when presenting the product description: $star_products_query = tep_db_query("select substring(pd.products_description, 1, 200) as products_description, p.products_id, ...etc. This works fine, except it cuts off many times in the middle of a word. The Description in Product Listing contribution uses a function to limit the listing and trims it so that words are not chopped off: function tep_flatten_product_description($description, $link) { $description = ereg_replace('<[^>]*>', '', $description); if (strlen($description) > PRODUCT_LIST_DESCRIPTION_MAX_LENGTH){ $sub_description = wordwrap($description, PRODUCT_LIST_DESCRIPTION_MAX_LENGTH,'$@$'); $sub_des = explode('$@$',$sub_description); $description = $sub_des[0]; $description .= "...".$link; } return $description; } Is there a way to limit the Star Product return so it doesn't chop words without having to resort to re-writing the mod with a new function? ... if you want to REALLY see something that doesn't set up right out of the box without some tweaking, try being a Foster Parent!
thetraveller Posted December 11, 2004 Posted December 11, 2004 I'm using the Star Product contribution which has a provision to limit the number of charcters that are returned when presenting the product description: $star_products_query = tep_db_query("select substring(pd.products_description, 1, 200) as products_description, p.products_id, ...etc. This works fine, except it cuts off many times in the middle of a word. The Description in Product Listing contribution uses a function to limit the listing and trims it so that words are not chopped off: function tep_flatten_product_description($description, $link) { $description = ereg_replace('<[^>]*>', '', $description); if (strlen($description) > PRODUCT_LIST_DESCRIPTION_MAX_LENGTH){ $sub_description = wordwrap($description, PRODUCT_LIST_DESCRIPTION_MAX_LENGTH,'$@$'); $sub_des = explode('$@$',$sub_description); $description = $sub_des[0]; $description .= "...".$link; } return $description; } Is there a way to limit the Star Product return so it doesn't chop words without having to resort to re-writing the mod with a new function? <{POST_SNAPBACK}> Hi: You will get a better response if you post this into the support forum for the contribution located here: http://www.oscommerce.com/forums/index.php?showtopic=106740 John
mugitty Posted December 12, 2004 Author Posted December 12, 2004 Thanks, John, but the question is really about a universal method to limit characters and not chop a word halfway through without adding a whole new function... It just happens to be needed in the Star Product module ... if you want to REALLY see something that doesn't set up right out of the box without some tweaking, try being a Foster Parent!
mugitty Posted December 14, 2004 Author Posted December 14, 2004 Thanks to Ivan Prieto who added a code snippet (surprisingly enough to the Star Product contribution) which will prevent the words from being chopped off at exactly the character count specified earlier in the code. This is what I was looking for as a general way to limit text returned without chopping up words and without having to install a whole new function. For those of you reading along, here is his modification (from about line 18 of the Star Product mod, but it could be easily adapted to other uses) $star_products_query = tep_db_query("select substring(pd.products_description, 1, 200) as products_description, p.products_id, p.products_image, p.manufacturers_id, p.products_price, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price, p.products_tax_class_id, sp.product_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_STAR_PRODUCT . " sp left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_id = pd.products_id and p.products_status = '1' and pd.products_description != '' and p.products_id=sp.product_id and pd.language_id = '" . $languages_id . "'"); $star_products = tep_db_fetch_array($star_products_query); $star_products['products_name'] = tep_get_products_name($star_products['products_id']); // BOF Ivan's fix: evita cortar palabras - literally means "it avoids to cut words" - you can of course call the variable whatever you like as long as you use the same name in all 3 spots below $evita_cortar_palabras = explode( ' ', $star_products["products_description"] ); array_pop( $evita_cortar_palabras ); $star_products["products_description"] = implode( ' ', $evita_cortar_palabras ); // EOF Ivan's fix ... if you want to REALLY see something that doesn't set up right out of the box without some tweaking, try being a Foster Parent!
Recommended Posts
Archived
This topic is now archived and is closed to further replies.