burt, on 14 June 2013 - 10:20 AM, said:
HOw does this grab you, can you optimise?
Awesome, I like how coalesce does all the work without the need to create a mile long function.
I set this up on a test site, and got it to work as needed, but had to add NULLIF or it would not retrieve further than the first requested column. I double checked to make sure my columns were NULL as default, as from what I found on coalesce shows it is made to work on columns set to null, not empty. They were, but anyhow, check this out:
function osc_split_mini_description($products_precis) {
$content= strip_tags($products_precis);
if (strlen($content) > 156 ) {
$content = substr($content, 0, strpos($content, ' ', 156));
}
return $content;
}
function osc_get_mini_description($products_id) {
global $languages_id;
$product_query = tep_db_query(" select coalesce(NULLIF(products_mini_description,'') , NULLIF(products_seo_text,'') , NULLIF(LEFT(products_description, 300),'') ,'". TAG_LINE ."') as products_precis from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$products_id . "' and language_id = '" . (int)$languages_id . "'");
$product = tep_db_fetch_array($product_query);
$products_precis = $product['products_precis'];
return osc_split_mini_description($products_precis);
}
I added TAG_LINE to be the default throw back. If it is set in the stores configurations options then it can be used in the rare case that none of the 3 exist.
I noticed earlier in this thread you had microformats in mind. I have been studying these a while now, and I feel that this exact function should also be used for microformating the description itemscope. It would keep the description consistant anywhere that the product id presented, IE: a product infoBox or the product listing or product info page. The character length is just fine and there would be no chance for one product display presenting different content than the same product being presented elsewhere.
Another good thing, this function could be duplicated, osc_get_meta_description and just switch the first 2 column lookups around for a failsafe meta description output.