Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

automatically cross-sell products, noyt individually


allvogue

Recommended Posts

Posted

I have the cross-sell module installed, but I want to find a way to automatically cross-sell products on the website, rather than going through each product individually and choosing 3 products to cross-sell it with. Is there anyway that this can be achieved

 

Cheers,

Chris

Posted

Try this in includes/modules/xsell.php (I thought this was how it came, but I must have modified it at some point....?:

<?php
/* 
$Id: xsell_products.php, v1  2002/09/11

osCommerce, Open Source E-Commerce Solutions 
<http://www.oscommerce.com> 

Copyright (c) 2002 osCommerce 

Released under the GNU General Public License 
*/ 

/* if product given */

if ($HTTP_GET_VARS['products_id']) { 

/* obtain the xsell product */

$xsell_query = tep_db_query("select distinct p.products_id, 
										 p.products_image, 
										 pd.products_name 
						 from " . TABLE_PRODUCTS_XSELL . " xp,
							  " . TABLE_PRODUCTS . " p,
							  " . TABLE_PRODUCTS_DESCRIPTION . " pd 
						 where xp.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and 
							   xp.xsell_id = p.products_id and 
							   p.products_id = pd.products_id and 
							   pd.language_id = '" . $languages_id . "' and 
							   p.products_status = '1' 
						 order by xp.products_id asc 
						 limit " . MAX_DISPLAY_ALSO_PURCHASED); 

$num_products_xsell = tep_db_num_rows($xsell_query); 

/* if we equal or exceed the minimal amount of products */

if ($num_products_xsell >= MIN_DISPLAY_ALSO_PURCHASED) { 

  /* put them in the box */

  $info_box_contents = array();
  $info_box_contents[] = array('align' => 'left', 'text' => TEXT_XSELL_PRODUCTS);
  new contentBoxHeading($info_box_contents);

  $row = 0;
  $col = 0;
  $info_box_contents = array();
  while ($xsell = tep_db_fetch_array($xsell_query)) {
	$xsell['products_name'] = tep_get_products_name($xsell['products_id']);
	$info_box_contents[$row][$col] = array('align' => 'center',
										   'params' => 'class="smallText" width="33%" valign="top"',
										   'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $xsell['products_image'], $xsell['products_name']) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . $xsell['products_name'] . '</a>');
	$col ++;
	if ($col > 2) {
	  $col = 0;
	  $row ++;
	}
  }

  /* if we have not enough products to fill the box */

  if ($num_products_xsell < MAX_DISPLAY_ALSO_PURCHASED) {

	/* add some random products from the same category to fill the box */

	$mtm= rand();

	$xsell_cat_query = tep_db_query("select categories_id
							   from " . TABLE_PRODUCTS_TO_CATEGORIES . "
							   where products_id = '" . $HTTP_GET_VARS['products_id'] . "'");
	$xsell_cat_array = tep_db_fetch_array($xsell_cat_query);
	$xsell_category = $xsell_cat_array['categories_id'];
	$new_limit = MAX_DISPLAY_ALSO_PURCHASED - $num_products_xsell;
	$xsell_prod_query = tep_db_query("select distinct p.products_id, 
										 p.products_image, 
										 pd.products_name 
						 from " . TABLE_PRODUCTS . " p,
							  " . TABLE_PRODUCTS_TO_CATEGORIES . " pc,
							  " . TABLE_PRODUCTS_DESCRIPTION . " pd 
						 where pc.categories_id = '" . $xsell_category . "' and
							   p.products_id != '" . $HTTP_GET_VARS['products_id'] . "' and 
							   pc.products_id = p.products_id and 
							   p.products_id = pd.products_id and 
							   pd.language_id = '" . $languages_id . "' and 
							   p.products_status = '1' 
						 order by rand($mtm) desc 
						 limit " . $new_limit);

   while ($xsell = tep_db_fetch_array($xsell_prod_query)) {
	 $xsell['products_name'] = tep_get_products_name($xsell['products_id']);
	 $info_box_contents[$row][$col] = array('align' => 'center',
											'params' => 'class="smallText" width="33%" valign="top"',
											'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $xsell['products_image'], $xsell['products_name']) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . $xsell['products_name'] . '</a>');
	 $col ++;
	 if ($col > 2) {
	   $col = 0;
	   $row ++;
	 }
   }
  }
  new contentBox($info_box_contents);
}
else {

  /* there are no xsell products registered at all for this product */

  $info_box_contents = array();
  $info_box_contents[] = array('align' => 'left', 'text' => TEXT_XSELL_PRODUCTS);
  new contentBoxHeading($info_box_contents);

  $row = 0;
  $col = 0;
  $info_box_contents = array();


  /* fill the box with all random products from the same category */

	$mtm= rand();
	$xsell_cat_query = tep_db_query("select categories_id
									 from " . TABLE_PRODUCTS_TO_CATEGORIES . "
									 where products_id = '" . $HTTP_GET_VARS['products_id'] . "'");

	$xsell_cat_array = tep_db_fetch_array($xsell_cat_query);
	$xsell_category = $xsell_cat_array['categories_id'];
	$new_limit = MAX_DISPLAY_ALSO_PURCHASED - $num_products_xsell;
	$xsell_prod_query = tep_db_query("select distinct p.products_id, 
													  p.products_image, 
													  pd.products_name 
									  from " . TABLE_PRODUCTS . " p,
										   " . TABLE_PRODUCTS_TO_CATEGORIES . " pc,
										   " . TABLE_PRODUCTS_DESCRIPTION . " pd 
									  where pc.categories_id = '" . $xsell_category . "' and 
											pc.products_id = p.products_id and 
											p.products_id != '" . $HTTP_GET_VARS['products_id'] . "' and 
											p.products_id = pd.products_id and 
											pd.language_id = '" . $languages_id . "' and 
											p.products_status = '1' 
									  order by rand($mtm) desc 
									  limit " . MAX_DISPLAY_ALSO_PURCHASED);

   while ($xsell = tep_db_fetch_array($xsell_prod_query)) {
	 $xsell['products_name'] = tep_get_products_name($xsell['products_id']);
	 $info_box_contents[$row][$col] = array('align' => 'center',
											'params' => 'class="smallText" width="33%" valign="top"',
											'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $xsell['products_image'], $xsell['products_name']) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . $xsell['products_name'] . '</a>');
	 $col ++;
	 if ($col > 2) {
	   $col = 0;
	   $row ++;
	 }
   }
  new contentBox($info_box_contents);
}
}
?>

That will automatically populate your x-sell box with products from the same category if you havent got items already defined.

  • 3 weeks later...
Posted

hi,

 

i did it to one of my sites, but i have another site, which includes the buy-it-now button and the price of the product in the cross-sell box of the screen. Do you know what type of code i will need to keep those there?

 

Cheers,

Chris

Archived

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

×
×
  • Create New...