Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Simple List of Other Products in that Sub Category


stewishaw

Recommended Posts

Posted

Hello, I am setting up a store and have a problem. We need to simply list on the product_info page the other products that are in that sub-category. This can be simple links so does anybody know of any solutions to this, I have searched the forum for answers and tried quite a few different modules but none of them do what we need. It would also be good if it simply displayed the products in the menu?

 

I will also give you a little bit of background on why we need this. The shop uses price breaks for the products but there are also different varieties of each product that have different price breaks...... So the only solution that I could come up with was to use a price break add-on and then just create a different product for each variety so that each product can have the different price breaks. I would then like to list the different varieties on the product page so that the user can select a different size or variety if they would like. Thanks for any help.

Posted

I'll try to find time tomorrow. I guarantee that writing the post will take longer than creating the module lol

 

I guesstimate; 5 minutes for the module, 20 minutes for the blog post.

Posted

Hi

 

Here's a start in my best slash and burn style (most folks use cut and paste but I tend to break more stuff than paste can fix)

 

Using 2.3.3 but 2.2 or MS2.2 would follow a similar line.

 

1) Grab a lump of existing code that does pretty much what you want already - so we want a display of products on the product page? Right - there's a candidate right there in includes/modules/also_purchased_products.php - open that and save it as includes/modules/also_in_this_cat_products.php

2) Edit the code as shown below

3) Go to product_info.php and add in a call to the new file- line 215 in vanilla code shown

<?php
   if ((USE_CACHE == 'true') && empty($SID)) {
  echo tep_cache_also_purchased(3600);
   } else {
  include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
   }
//added BobTerveuren
include(DIR_WS_MODULES . 'also_in_this_cat_products.php');
?>

 

n.b this is quick and dirty and does not make use of the osC file naming convention

 

So this'll give you a start - there's just an image and a name in there and the box still carries the title for 'Customers who bought this product also bought:' but you can change that and if you want price/buy now button then have a look around in the other files to see what you need

 

<?php
/*
 $Id$
 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com
 Copyright (c) 2010 osCommerce
 Released under the GNU General Public License
*/
 if (isset($HTTP_GET_VARS['products_id'])) {
  //comment out original sql query
   //$orders_query = tep_db_query("select p.products_id, p.products_image from " . TABLE_ORDERS_PRODUCTS . " opa, " . TABLE_ORDERS_PRODUCTS . " opb, " . TABLE_ORDERS . " o, " . TABLE_PRODUCTS . " p where opa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and opa.orders_id = opb.orders_id and opb.products_id != '" . (int)$HTTP_GET_VARS['products_id'] . "' and opb.products_id = p.products_id and opb.orders_id = o.orders_id and p.products_status = '1' group by p.products_id order by o.date_purchased desc limit " . MAX_DISPLAY_ALSO_PURCHASED);
  //add in a new one
  //if you do not want to use MAX_DISPLAY_ALSO_PURCHASED then change that to something else

  //Right get the parent category for this product

  if(tep_not_null($cPath)){	 //check that cPath variable exists
  $cat_array = explode("_", $cPath);  //split it out into an array
  $current_cat= end($cat_array);		   //grab the cat_id for this product

  //make a little SQL query

  $orders_query = tep_db_query("
  select
  p.products_id,
  p.products_image
  from
  " . TABLE_PRODUCTS . " p,
  " .TABLE_PRODUCTS_TO_CATEGORIES. " p2c
  where
  p.products_id <> '" . (int)$HTTP_GET_VARS['products_id'] . "'
  and p.products_status = '1'
  and p.products_id=p2c.products_id
  and p2c.categories_id='".(int)$current_cat."'
  group by p.products_id ");

   $num_products_ordered = tep_db_num_rows($orders_query);
   if ($num_products_ordered >= MIN_DISPLAY_ALSO_PURCHASED) {
  $counter = 0;
  $col = 0;
  $also_pur_prods_content = '<table border="0" width="100%" cellspacing="0" cellpadding="2" class="ui-widget-content ui-corner-bottom">';
  while ($orders = tep_db_fetch_array($orders_query)) {
    $counter++;
    $orders['products_name'] = tep_get_products_name($orders['products_id']);
    if ($col === 0) {
	  $also_pur_prods_content .= '<tr>';
    }
    $also_pur_prods_content .= '<td width="33%" valign="top" align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $orders['products_image'], $orders['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br /><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . $orders['products_name'] . '</a></td>';
    $col ++;
    if (($col > 2) || ($counter == $num_products_ordered)) {
	  $also_pur_prods_content .= '</tr>';
	  $col = 0;
    }
  }
  $also_pur_prods_content .= '</table>';
?>
 <br />
 <div class="ui-widget infoBoxContainer">
   <div class="ui-widget-header ui-corner-top infoBoxHeading">
  <span><?php echo TEXT_ALSO_PURCHASED_PRODUCTS; ?></span>
   </div>
   <?php echo $also_pur_prods_content; ?>
 </div>
<?php
   }
 }
 }//end tep_not_null($cPath)
?>

Posted

Hi Bob that's fantastic so thanks so much. I have it working, displaying just a standard text link for each product, but am wondering is it also possible to add the price as well? So it would display like:

 

Product Link - £Price

 

Or even better displaying the price breaks, although I assume that would be very difficult? I am using the Simple Price Break Contribution (http://addons.oscommerce.com/info/4658). Thanks again.

Archived

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

×
×
  • Create New...