Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Optional related product


stevennickelby

Recommended Posts

Posted

Hello,

 

I am using the contribution "optional related products",

and have altered it alittle so instead of showing the product in rows,

it shows them side by side...

 

...the problem is that if you have say for instance 10 realted products specified,

then it will show 10 side by side which causes the page to be stetched,

 

how can i make it <br> or go to another row after say 4 products?

 

Below is the script...

 

// DANIEL: begin - show related products

$attributes = "select pop_products_id_slave, products_name, products_price, products_tax_class_id, products_image from " . TABLE_PRODUCTS_OPTIONS_PRODUCTS . ", " . TABLE_PRODUCTS_DESCRIPTION . " pa, ". TABLE_PRODUCTS . " pb WHERE pop_products_id_slave = pa.products_id and pa.products_id=pb.products_id and language_id = '" . (int)$languages_id . "' and pop_products_id_master = '".$HTTP_GET_VARS['products_id']."' and products_status=1 order by pop_order_id, pop_id";

$attribute_query = tep_db_query($attributes);

 

echo '<tr><td><table border="0" cellspacing="2" cellpadding="0" width="100%">';

echo '<tr><td align="left" class= "products_name" ><span class="products_name2"> '.TEXT_RELATED_PRODUCTS.' </span></td></tr><tr><td align="center">';

echo '<table border="0" cellspacing="0" cellpadding="2" width="100%" align="center"><Tr>';

if (mysql_num_rows($attribute_query)>0) {

while ($attributes_values = tep_db_fetch_array($attribute_query)) {

$products_name_slave = ($attributes_values['products_name']);

$products_id_slave = ($attributes_values['pop_products_id_slave']);

if ($new_price = tep_get_products_special_price($products_id_slave)) {

$products_price_slave = $currencies->display_price($new_price, tep_get_tax_rate($attributes_values['products_tax_class_id']));

} else {

$products_price_slave = $currencies->display_price($attributes_values['products_price'], tep_get_tax_rate($attributes_values['products_tax_class_id']));

}

 

// show thumb image if Enabled

echo '<td class="productListing-data" align="center">';

if (MODULE_RELATED_PRODUCTS_SHOW_THUMBS!='False') {

echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id_slave) . '">' . tep_image(DIR_WS_IMAGES . $attributes_values['products_image'], $attributes_values['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"').'</a>';

}

echo '<Br> <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id_slave) . '">'.$products_name_slave.'<Br>@ '.$products_price_slave.'</a>';

}

echo '</td>';

}

echo '</tr></table></td></tr></table></td></tr>';

//DANIEL: end

 

--------------------------------------------------

i tried seeing if I could use the method of the contribution

"thumbar.php" which alows you to specify how rows and columns,

but it's too difficult....come on guys!

 

below is that script

 

<?php

/*=======================================================================*\

|| #################### //-- SCRIPT INFO --// ########################## ||

|| # Script name: thumb_bar.php

|| # Contribution: Thumbnail Category Browse on Product Page

|| # Version: 1.0

|| # Date: 24 Janauary 2005

|| # ------------------------------------------------------------------ # ||

|| #################### //-- COPYRIGHT INFO --// ######################## ||

|| # Copyright © 2005 Bobby Easland # ||

|| # Internet moniker: Chemo # ||

|| # Contact: [email protected] # ||

|| # Commercial Site: http://gigabyte-hosting.com/ # ||

|| # GPL Dev Server: http://mesoimpact.com/ # ||

|| # # ||

|| # This script is free software; you can redistribute it and/or # ||

|| # modify it under the terms of the GNU General Public License # ||

|| # as published by the Free Software Foundation; either version 2 # ||

|| # of the License, or (at your option) any later version. # ||

|| # # ||

|| # This script is distributed in the hope that it will be useful, # ||

|| # but WITHOUT ANY WARRANTY; without even the implied warranty of # ||

|| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # ||

|| # GNU General Public License for more details. # ||

|| # # ||

|| # Script is intended to be used with: # ||

|| # osCommerce, Open Source E-Commerce Solutions # ||

|| # http://www.oscommerce.com # ||

|| # Copyright © 2003 osCommerce # ||

|| ###################################################################### ||

\*========================================================================*/

 

/*===============================================================================

*/

define('MAX_THUMB_ROW', 5); # Number of maximum thumbs per row

define('MIN_THUMB_ROW', 1); # Minimum number of thumbs

define('TEXT_THUMB_BAR', 'Quick Browser - Products In This Category'); # text

/*===============================================================================

=*/

 

#####################################

# DO NOT EDIT BELOW THIS POINT #

#####################################

 

# get the products in the current category

# $prod_query = "SELECT products_id FROM ".TABLE_PRODUCTS_TO_CATEGORIES." WHERE categories_id='".$current_category_id."'";

// MOD TO EXCLUDE CURRENT PRODUCT LISTING FROM QUERY

$prod_query = "SELECT products_id FROM ".TABLE_PRODUCTS_TO_CATEGORIES." WHERE categories_id='".$current_category_id."' AND products_id != '".$products_id."'";

# execute the query

$products_id_query = tep_db_query($prod_query);

# loop the array and populate the $prod_array with product ID's

$prod_array = array();

while($prods = tep_db_fetch_array($products_id_query)){

$prod_array[] = $prods['products_id'];

}

# free the result...clean as we go

tep_db_free_result($products_id_query);

# define the column list

$column_list = 'products_id, products_image, products_ordered';

# loop the $prod_array and start compiling the UNION query

$union = array();

foreach($prod_array as $index => $pID){

#$column_list = ( $index=0 ? 'SQL_CALC_FOUND_ROWS '.$column_list : $column_list);

$union[] = "SELECT ".$column_list." FROM ".TABLE_PRODUCTS." WHERE products_id='".$pID."' AND products_status='1'";

}

# implode the UNION query and get the final string

$union_str = implode(" UNION ", $union) . " ORDER BY products_ordered desc";

# unset some stuff...clean as we go

unset($prod_array, $union);

# include the class

include(DIR_WS_CLASSES . 'union_split_page_results.php');

# initiate the unionSplit class

# unionSplit( union query [string], max per row [int], current page [int], page parameter [string], explain the query [bool] )

$listing_split = new unionSplit($union_str, MAX_THUMB_ROW, (int)$_GET['page'], 'page', false);

# sanity check - if the number of returned products is greater than or equal to the minimum

if ( $listing_split->num_rows >= MIN_THUMB_ROW ){

?>

<!-- quick category thumb browser - by Chemo //-->

<?php

# set the column width dynamically

$width = (int)( ($listing_split->num_rows > MAX_THUMB_ROW) ? (1/MAX_THUMB_ROW*100) : (1/$listing_split->num_rows*100 ) );

#initialize the array - heading

$info_box_contents = array();

# set the array content - heading

$info_box_contents[] = array('text' => TEXT_THUMB_BAR);

# initialize the contentBoxHeading

new contentBoxHeading($info_box_contents);

#initialize the array - content

$info_box_contents = array();

# loop the query results from the split

while ( $tmp = tep_db_fetch_array($listing_split->query) ){

# get the name of the product

# you may choose to get this from a JOIN ... modify the above code and comment this out

$tmp['products_name'] = tep_get_products_name($tmp['products_id']);

# assign the data

$info_box_contents[0][] = array('align' => 'center',

'params' => 'class="smallText" valign="top" width="'.$width.'%"',

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $tmp['products_id'] . ( isset($_GET['page']) && tep_not_null($_GET['page']) && is_numeric($_GET['page']) ? '&page=' . (int)$_GET['page'] : '') ) . '">' . tep_image(DIR_WS_IMAGES . $tmp['products_image'], $tmp['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $tmp['products_id']) . '">' . $tmp['products_name'] . '</a>');

}

# initialize the contentBox

new contentBox($info_box_contents);

# if the number of returned rows is greater than the max per row then output the nav links

if ( $listing_split->num_rows > MAX_THUMB_ROW ){

?>

<table border="0" width="100%" cellspacing="0" cellpadding="2">

<tr>

<td class="smallText"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>

<td class="smallText" align="right"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>

</tr>

</table>

<?php

} # end bracket for nav links block

?>

<!-- eof quick category thumb browser - by Chemo //-->

<?php

} # end bracket for if number returned products is greater than or equal to minimum

 

# If you would like to see how long it is taking to run the final UNION query for debugging

# uncomment the following line which will output the execution time

# echo $listing_split->execution_time;

?>

 

Archived

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

×
×
  • Create New...