Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How to put "Other Suggested Items" on the product info page


negri21

Recommended Posts

Do you mean something like at this page: http://www.gamesdepot.com.au/arma-armed-as...-dvd-p-211.html, where under the main picture are suggestions about other things the customer might like? If so, it sounds like you're looking for a cross-sell contribution. Have a look here: http://addons.oscommerce.com/category?search=cross+sell

 

I use the "X-Sell v2-MS2 - Cross Sell for MS2" contribution, available at http://addons.oscommerce.com/info/1415, which I've modified a little to produce random results instead of having to manually enter in cross-sells for every item. I hope this helps!

 

Max

Link to comment
Share on other sites

Can do, with a couple caveats: the first is that this contains modifications relating to the graphical borders mod. The second is that this is still a work in progress. Right now, if a manually-entered cross-sell exists, it does not "fill in the blanks" with random x-sells, it just shows the manually-entered x-sell. So you're best off not entering a manual x-sell at all, let the random bit do its thing. Ideally, I want to change this so that I can manually set a particular item as an x-sell, and have the module populate the rest of the row, so there's always 3 x-sells no matter if they are all random, all manually set, or a bit of both.

 

Here's catalog/includes/modules/xsell_products.php. All work belongs to the original authors, and TBH I can't quite remember which code is mine!

<?php
/*
$Id: xsell_products.php, v1  2002/09/11
// adapted for Separate Pricing Per Customer v4 2005/02/24

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

Copyright (c) 2002 osCommerce

Released under the GNU General Public License
*/
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_XSELL_PRODUCTS);

// BOF Separate Pricing Per Customer
if(!tep_session_is_registered('sppc_customer_group_id')) {
$customer_group_id = '0';
} else {
 $customer_group_id = $sppc_customer_group_id;
}

if ($HTTP_GET_VARS['products_id']) {

//Cache

$dircache = DIR_FS_CACHE_XSELL . $HTTP_GET_VARS['products_id'] . '/';
$filename = $dircache  . $languages_id . '-' . $customer_group_id . '.php';
$cache = '<?php 
	 $info_box_contents = array();
	 $info_box_contents[] = array(\'text\' => TEXT_XSELL_PRODUCTS);
	 new contentBoxHeading($info_box_contents);
	 $info_box_contents = array();';
if (file_exists($filename)) {
		require $filename;
} else {

	//Fin cache

	if ($customer_group_id != '0') {
		$xsell_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name, p.products_tax_class_id, IF(pg.customers_group_price IS NOT NULL, pg.customers_group_price, p.products_price) as products_price from " . TABLE_PRODUCTS_XSELL . " xp, " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_GROUPS . " pg using(products_id), " . 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' and pg.customers_group_id = '".$customer_group_id."' order by sort_order asc limit " . MAX_DISPLAY_ALSO_PURCHASED);
	} else {
		$xsell_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name, p.products_tax_class_id, products_price 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 sort_order asc limit " . MAX_DISPLAY_ALSO_PURCHASED);
	}
	// EOF Separate Pricing Per Customer

	// echo "x_sell query is " . $xsell_query . "<br>";


	$num_products_xsell = tep_db_num_rows($xsell_query);

	// echo "num_products_xsell is " . $num_products_xsell . "<br>";
	if ($num_products_xsell > 0) {
		?>

		<table border="0" width="100%" cellspacing="0" cellpadding="0">
		  <tr>
			<?php echo mws_header(TEXT_XSELL_PRODUCTS); ?>
			  <td>

		<!-- xsell_products //-->
		<?php
			 $info_box_contents = array();
			 $info_box_contents[] = array('text' => TEXT_XSELL_PRODUCTS);
			 new infoBoxHeading ($info_box_contents);

			 $row = 0;
			 $col = 0;
			 $info_box_contents = array();
			 while ($xsell = tep_db_fetch_array($xsell_query)) {
			   $xsell['specials_new_products_price'] = tep_get_products_special_price($xsell['products_id']);

		if ($xsell['specials_new_products_price']) {
			 $xsell_price =  '<s>' . $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</s><br>';
			 $xsell_price .= '<span class="productSpecialPrice">' . $currencies->display_price($xsell['specials_new_products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</span>';
		   } else {
			 $xsell_price =  $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id']));
		   }
			   //Cache
				$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'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . $xsell['products_name'] .'</a><br>' . $xsell_price. '<br>';


			   //Fin cache
			   $info_box_contents[$row][$col] = array('align' => 'center',
													  'params' => 'class="smallText" width="33%" valign="top"',
													  'text' => $text);
			   //Cache
			   $cache .= '$info_box_contents[' .$row . '][' . $col . '] = array(\'align\' => \'center\',
													  \'params\' => \'class="smallText" width="33%" valign="top"\',
													  \'text\' => \'' . str_replace("'", "\'", $text) .'\');';

			   //Fin cache	   
			   $col ++;
			   if ($col > 2) {
				 $col = 0;
				 $row ++;
			   }
			 }
		new noborderBox($info_box_contents);
		//Cache
		/*
			 $cache .= 'new contentBox($info_box_contents); ?>';
			 if(!is_dir($dircache)) { mkdir($dircache,0777); }
			 $fp = fopen($filename , 'w');
			 $fout = fwrite($fp , $cache);
			 fclose($fp);
		*/

		//Fin Cache		
		?>
		</td>
		<?php echo mws_footer(''); ?>
		</tr>
		</table>
		<!-- xsell_products_eof //-->
		<?php
	} else {

		  /* there are no xsell products registered at all for this product */
		$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);

		//var_dump($xsell_cat_array);

		$xsell_category = $xsell_cat_array['categories_id'];

		//echo "xsell_category " . $xsell_category . "<br>";
		$new_limit = 3 - $num_products_xsell;

		// $new_limit = 3;

		//echo "new_limit " . $new_limit . "<br>";

		$xsell_prod_query = tep_db_query("select distinct p.products_id, 
														  p.products_image, 
														  pd.products_name,
														  p.products_tax_class_id, 
														  products_price
										  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 " . $new_limit);

		$num_prod_query_xsell = tep_db_num_rows($xsell_prod_query);
		// echo "num_products_xsell is " . $num_prod_query_xsell . "<br>";
		if ($num_prod_query_xsell > 0) {
			?>
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
				<?php echo mws_header(TEXT_XSELL_PRODUCTS); ?>
				<td>
				<?php
				$info_box_contents = array();
				$info_box_contents[] = array('text' => TEXT_XSELL_PRODUCTS);
				new infoBoxHeading ($info_box_contents);

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

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

				while ($xsell = tep_db_fetch_array($xsell_prod_query)) {
					$xsell['products_name'] = tep_get_products_name($xsell['products_id']);


					$xsell['specials_new_products_price'] = tep_get_products_special_price($xsell['products_id']);

					if ($xsell['specials_new_products_price']) {
						 $xsell_price =  '<s>' . $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</s><br>';
						 $xsell_price .= '<span class="productSpecialPrice">' . $currencies->display_price($xsell['specials_new_products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</span>';
					   } else {
						 $xsell_price =  $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id']));
					   }

					// $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'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . $xsell['products_name'] .'</a><br>' . $xsell_price. '<br>'; 









					 /*
					 $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'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . $xsell['products_name'] . '</a>');

					*/

					 $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'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . $xsell['products_name'] .'</a><br>' . $xsell_price. '<br>';


					//Fin cache
					$info_box_contents[$row][$col] = array('align' => 'center',
														  'params' => 'class="smallText" width="33%" valign="top"',
														  'text' => $text);



					$col ++;
					 if ($col > 2) {
					   $col = 0;
					   $row ++;
					 }
				}
				new noborderBox($info_box_contents);
				?>



				</td>
				<?php echo mws_footer(''); ?>
				  </tr>
			</table>
			<?php	 
		}   
	}	  
}
}
?>

 

The idea behind this code is that it finds out the product's parent category, then yanks other products from that same category and populates the x-sell box with it. I hope this helps. :)

 

Cheers,

Max

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...