Improve OSCommerce also_consider.php

OSCommercePublished July 26, 2009 at 12:05 PM No Comments

After making some mods on oscommerce file also_consider.php, i-ve find out that the results are not so well displayed, i mean, products are taken from the same categoy, or having almost the same price, but this is not enaugh. So, i-ve recreate the SQL script, so the result is displayed by relevance.

it’s an easy mod:

file to change: includes/modules/also_consider.php

find:

if (mysql_num_rows($prod_query) > 0) { 

above this, change what is between {

$sql=”select p.products_id, p.products_image, p.products_price, p.products_model, pd.products_name, p.products_tax_class_id from ” . TABLE_PRODUCTS . ” p, ” . TABLE_PRODUCTS_DESCRIPTION . …

}

with:


{

$cuvant=$product_info['products_name'];
$split_stemmed=explode(" ",trim($cuvant));
$split_stemmed=array_unique($split_stemmed);
$temp=array();
foreach($split_stemmed as $cuvant){
if(strlen(trim($cuvant))>2){
$cuvant=trim(ereg_replace("[^A-Za-z0-9]", "", $cuvant ));
if(strlen($cuvant)==3){$cuvant.="*";}
$temp[]=$cuvant;
}
}
$split_stemmed=$temp;

$string="";
$f=0;
while(list($key,$val)=each($split_stemmed)){
if($f>1){
$string.=$val.',';
}else{
$string.=''.$val.',';
}
$f++;
}

$string=substr($string,0,strlen($string)-1);

$sql = "SELECT
p.products_id, p.products_image, p.products_price, p.products_model, pd.products_name, p.products_tax_class_id,
( (90 * (MATCH(pd.products_name) AGAINST ('".$string."' ))) + (10 * (MATCH(pd.products_description) AGAINST ('".$string."' ))) ) AS relevance

from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc
WHERE
( (0.9 * (MATCH(pd.products_name) AGAINST ('".$string."' IN BOOLEAN MODE))) + (0.1 * (MATCH(pd.products_description) AGAINST ('".$string."' IN BOOLEAN MODE))) )
and   p.products_status = '1' and p.products_id = pc.products_id and p.products_id = pd.products_id and p.products_id != '" . (int)$HTTP_GET_VARS['products_id'] . "'  and pd.language_id = '" . (int)$languages_id . "'
GROUP BY p.products_id ORDER BY relevance DESC LIMIT " . (MAX_ALSO_CONSIDER);
$prod_query = tep_db_query($sql);

}

Tags: ,

Leave a Reply

(required)

(required)