Sanjoy Roy

[MCM, MCP, SCJP] – Senior PHP Programmer

Creloaded 6.2 – osCommerce – Cross sell products


$categories = array();
$sql = "SELECT `categories_id` FROM `products_to_categories` WHERE `products_id` = '".$HTTP_GET_VARS['products_id']."'";
$result = tep_db_query($sql);
while ($row = mysql_fetch_assoc($result)) {
    $categories[] = $row["categories_id"];
}

$categories_str = '';
if (sizeof($categories)){
	$categories_str = implode("','", $categories);
}

$products = array();
$sql = "SELECT `products_id` FROM `products_to_categories` WHERE `categories_id` IN ('".$categories_str."')";
$result = tep_db_query($sql);
while ($row = mysql_fetch_assoc($result)) {
    $products[] = $row["products_id"];
}
$products_str = '';
if (sizeof($products)){
	$products_str = implode("','", $products);
}

//echo "'".$products_str."'
"; /*SELECT * FROM `products` w ORDER BY RAND() LIMIT 0 , 6;*/ $sql = "select distinct p.products_id, p.products_image, p.products_price, p.manufacturers_id, pd.products_name, p.products_tax_class_id, p.products_date_added, p.products_image , xp.xsell_id products_price from (" . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id), " . TABLE_PRODUCTS_XSELL . " xp, " . TABLE_PRODUCTS_DESCRIPTION . " pd where xp.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and p.products_id = xp.xsell_id and pd.products_id = xp.xsell_id and pd.language_id = '" . $languages_id . "' and p.products_status = '1' order by rand(), xp.products_id asc limit " . 6; //echo $sql.'
'; $sql = "SELECT * FROM `products` where products_id IN ('".$products_str."') AND `products_price` 0 ORDER BY RAND() LIMIT 0 , 6";

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: