Jump to content


Corporate Sponsors


Latest News: (loading..)

- - - - -

Add a quantity box to the products page in two easy steps


  • You cannot reply to this topic
6 replies to this topic

#1 npn2531

  • Community Member
  • 951 posts
  • Real Name:Jase
  • Gender:Not Telling

Posted 18 April 2010, 18:32

This allows the customer to type in the quantity of an item they wish to purchase before they click the 'add to cart' or 'purchase' button. This is a rewrite of:
http://www.oscommerce.info/kb/osCommerce/General_Information/Tips_and_Tricks/246
which is outdated, but worth studying for the more detailed html layout.

1) in application_top.php find
$cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']);

change to:

$cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+$HTTP_POST_VARS['cart_quantity'], $HTTP_POST_VARS['id']);

essentially you are changing the '+1' to '$HTTP_POST_VARS['cart_quantity']'

2) in product_info.php find:
<?php echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?>

just in front of that add:

<input type="text" name="cart_quantity" value="1" maxlength="2" size="2">

That's it.

see an example here:
http://www.niora.com/product_info.php?cPath=8&products_id=69

or on a vanilla install here:

http://adult-acne-product.com/catalog/product_info.php?products_id=21



(you may have to play with the html to line things up nicely, but the above will post the quantity to the shopping cart.

#2 npn2531

  • Community Member
  • 951 posts
  • Real Name:Jase
  • Gender:Not Telling

Posted 19 April 2010, 00:10

To also add the quantity box to the product listing:

1) modify includes/application_top.php as described above

2) in includes/modules/product_listing.php find:

case 'PRODUCT_LIST_BUY_NOW':
            $lc_align = 'center';
            $lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a>&nbsp;';
            break;

change to:

case 'PRODUCT_LIST_BUY_NOW':
            $lc_align = 'center';
            $lc_text = '<form name="cart_quantity" method="post" action="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product', 'NONSSL'). '"><input type="hidden" name="products_id" value="' . $listing['products_id'] . '"><input type="text" name="cart_quantity" value="1" maxlength="5" size="5">' . tep_image_submit('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</form>';
     //   $lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a>&nbsp;';
            break;

see an example on a vanilla install here:

http://adult-acne-product.com/catalog/index.php?cPath=3_10

again, you will have to play with the html to line it up nicely.

Edited by npn2531, 19 April 2010, 00:13.


#3 alberti

  • Community Member
  • 12 posts
  • Real Name:Albert

Posted 26 July 2010, 05:35

View Postnpn2531, on 19 April 2010, 00:10, said:

To also add the quantity box to the product listing:

1) modify includes/application_top.php as described above

2) in includes/modules/product_listing.php find:

case 'PRODUCT_LIST_BUY_NOW':
            $lc_align = 'center';
            $lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a>&nbsp;';
            break;

change to:

case 'PRODUCT_LIST_BUY_NOW':
            $lc_align = 'center';
            $lc_text = '<form name="cart_quantity" method="post" action="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product', 'NONSSL'). '"><input type="hidden" name="products_id" value="' . $listing['products_id'] . '"><input type="text" name="cart_quantity" value="1" maxlength="5" size="5">' . tep_image_submit('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</form>';
     //   $lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a>&nbsp;';
            break;

see an example on a vanilla install here:

http://adult-acne-product.com/catalog/index.php?cPath=3_10

again, you will have to play with the html to line it up nicely.

Hi, How do you get the quantity in product_listing.php to work, I've done as outlined here but just can't get it to work?

#4 alberti

  • Community Member
  • 12 posts
  • Real Name:Albert

Posted 26 July 2010, 05:36

Here my code for product_listing.php

<?php
/*
  $Id: product_listing.php 1739 2007-12-20 00:52:16Z hpdl $

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

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/
?>
<?php echo tep_draw_title_top();?>

				<?php echo $breadcrumb->trail(' &raquo; ')?>
			
<?php echo tep_draw_title_bottom();?>	

<?php echo tep_draw3_top();?>

<?php
  $listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id');

  if ( ($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {
?>

<?php echo tep_draw_result1_top(); ?>
       
		<table border="0" cellspacing="0" cellpadding="0" class="result result_top_padd">
          <tr>
            <td><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
            <td class="result_right" 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 echo tep_draw_result1_bottom();  ?> 
       
<?php
  }
								
$info_box_contents = array();
  $list_box_contents = array();
$my_row = 0;
$my_col = 0;


  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
    switch ($column_list[$col]) {
      case 'PRODUCT_LIST_MODEL':
        $lc_text = TABLE_HEADING_MODEL;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_NAME':
        $lc_text = TABLE_HEADING_PRODUCTS;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_MANUFACTURER':
        $lc_text = TABLE_HEADING_MANUFACTURER;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_PRICE':
        $lc_text = TABLE_HEADING_PRICE;
        $lc_align = 'right';
        break;
      case 'PRODUCT_LIST_QUANTITY':
        $lc_text = TABLE_HEADING_QUANTITY;
        $lc_align = 'right';
        break;
      case 'PRODUCT_LIST_WEIGHT':
        $lc_text = TABLE_HEADING_WEIGHT;
        $lc_align = 'right';
        break;
      case 'PRODUCT_LIST_IMAGE':
        $lc_text = TABLE_HEADING_IMAGE;
        $lc_align = 'center';
        break;
case 'PRODUCT_LIST_BUY_NOW':
            $lc_align = 'center';
            $lc_text = '<form name="cart_quantity" method="post" action="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product', 'NONSSL'). '"><input type="hidden" name="products_id" value="' . $listing['products_id'] . '"><input type="text" name="cart_quantity" value="1" maxlength="5" size="5">' . tep_image_submit('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</form>';
     //   $lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ';
            break;
		
// BOF Product Sort
	  case 'PRODUCT_SORT_ORDER':
		$lc_text = TABLE_HEADING_PRODUCT_SORT;
		$lc_align = 'center';
		break;
// EOF Product Sort

    }

    if ( ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW') && ($column_list[$col] != 'PRODUCT_LIST_IMAGE') ) {
      $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);
    }

    $list_box_contents[0][] = array('align' => $lc_align,
                                    'params' => 'class="productListing-heading"',
                                    'text' => '&nbsp;' . $lc_text . '&nbsp;');
  }

  if ($listing_split->number_of_rows > 0) {
    $rows = 0;
    $listing_query = tep_db_query($listing_split->sql_query);
    while ($listing = tep_db_fetch_array($listing_query)) {
      $rows++;

      if (($rows/2) == floor($rows/2)) {
        $list_box_contents[] = array('params' => 'class="productListing-even"');
      } else {
        $list_box_contents[] = array('params' => 'class="productListing-odd"');
      }

      $cur_row = sizeof($list_box_contents) - 1;

      for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
        $lc_align = '';

        switch ($column_list[$col]) {
          case 'PRODUCT_LIST_MODEL':
            $lc_align = '';
							
            $p_model = '<tr>
							<td><b><font>'.TABLE_HEADING_MODEL.'&nbsp;:</font></b></td>
							<td align="right"><font>' . $listing['products_model'] . '</font></td>
						</tr>';
            break;
          case 'PRODUCT_LIST_NAME':
            $lc_align = '';
            if (isset($HTTP_GET_VARS['manufacturers_id'])) {
            $p_name = $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
            } else {
            $p_name = $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
            }
            break;
          case 'PRODUCT_LIST_MANUFACTURER':
            $lc_align = '';
            $p_manufact = '<tr>
							<td><b><font>'.TABLE_HEADING_MANUFACTURER.'&nbsp;:</font></b></td>
							<td align="right"><font><a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' . $listing['manufacturers_name'] . '</a></font></td>
						</tr>';
            break;
          case 'PRODUCT_LIST_PRICE':
            $lc_align = 'right';
            if (tep_not_null($listing['specials_new_products_price'])) {
           $p_price = $lc_text = '<s>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s>&nbsp;&nbsp; <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span>';
            } else {
           $p_price = $lc_text = '<span class="productSpecialPrice">' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span>';
            }
            break;
          case 'PRODUCT_LIST_QUANTITY':
            $lc_align = 'right';
            $p_qty = '<tr>
							<td><b><font>'.TABLE_HEADING_QUANTITY.'&nbsp;:</font></b></td>
							<td align="right"><font>' . $listing['products_quantity'] . '</font></td>
						</tr>';
            break;
          case 'PRODUCT_LIST_WEIGHT':
            $lc_align = 'right';
            $p_weight = '<tr>
							<td><b><font>'.TABLE_HEADING_WEIGHT.'&nbsp;:</font></b></td>
							<td align="right"><font>' . $listing['products_weight'] . '</font></td>
						</tr>';
            break;
          case 'PRODUCT_LIST_IMAGE':
            $lc_align = 'center';
            if (isset($HTTP_GET_VARS['manufacturers_id'])) {
              $p_pic = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
            } else {
              $p_pic = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
            }
            break;
          
			// BOF Product Sort
		  case 'PRODUCT_SORT_ORDER';
            $lc_align = 'center';
            $lc_text = '&nbsp;' . $listing['products_sort_order'] . '&nbsp;';
            break;
// EOF Product Sort

          case 'PRODUCT_LIST_BUY_NOW':
            $lc_align = 'right';
            $lc_text = tep_draw_form('buy_now', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id='. $listing['products_id']), 'POST') . '<table cellSpacing="0" cellPadding="0" width="100%"><tr><td align="right" width="25%">' . tep_draw_input_field('buyqty', '1', 'size=2 maxlength=2') . '</td><td align="center" width="75%" valign="absmiddle">' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART, 'align=absmiddle') . '</td></tr></table></form>';
            break;
			
        }
		
$product_query = tep_db_query("select products_description, products_id from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$listing['products_id'] . "' and language_id = '" . (int)$languages_id . "'");
      $product = tep_db_fetch_array($product_query);
       	$p_desc = substr(strip_tags($product['products_description']), 0, MAX_DESCR_1).'...<br>';
		
	  if (PRODUCT_LIST_MODEL != 0 || PRODUCT_LIST_MANUFACTURER != 0 || PRODUCT_LIST_QUANTITY != 0 || PRODUCT_LIST_WEIGHT != 0) {
		$p_listing = '<table cellpadding="0" cellspacing="0" border="0" class="listing">'.$p_model.''.$p_manufact.'' . ''.$p_qty.'' . ''.$p_weight.'</table>';
		}
		
        $p_id = $product['products_id'];
		
/*		$list_box_contents[$cur_row][] = array('align' => $lc_align,
                                               'params' => '',
                                               'text'  => $lc_text); */

 }
  $p_details = '<input type="text" name="cart_quantity" value="1" maxlength="2" size="2">';
  $p_buy_now = '<a href="'.tep_href_link("products_new.php","action=buy_now&products_id=".$p_id).'">'.tep_image_button('button_add_to_cart1.gif', '', ' class="btn1"').'</a>';
		
 
 $info_box_contents[$my_row][$my_col] = array('align' => 'center',
                                           'params' => ' style="width:1px;"',
                                           'text' => ''.tep_draw_prod2_top().'
	<table cellpadding="0" cellspacing="0" border="0"><tr><td class="pic2_padd">'.tep_draw_prod_pic_top().''.$p_pic.''.tep_draw_prod_pic_bottom().'</td></tr></table>
	<table cellpadding="0" cellspacing="0" border="0" class="wrapper_box">
		<tr><td class="price2_padd"><b>'.PRICE.':</b> '.$p_price.'</td></tr>
		<tr><td class="name name2_padd">'.$p_name.'</td></tr>
		<tr><td class="desc desc2_padd">'.$p_desc.'</td></tr>	
		<tr><td class="listing2_padd">'.$p_listing.'</td></tr>				
		
		<tr><td class="button2_padd">
			<table cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td>'.$p_buy_now .'</td>
					<td>'.$p_details.'</td>
				</tr>
			</table>
		</td></tr>
	</table>									   
	'.tep_draw_prod2_bottom().'');
 
    $my_col ++;
    if ($my_col > 2) {
      $my_col = 0;
 	$my_row ++;
      }
    }
new contentBox($info_box_contents); 
//    new productListingBox($list_box_contents);
 } else {  ?>
 <?php echo tep_draw1_top(); ?>

				<table cellpadding="0" cellspacing="0" class="main">
					<tr><td style="padding:25px 20px 20px 20px;"><?php echo TEXT_NO_PRODUCTS ?></td></tr>
				</table>

<?php echo tep_draw1_bottom();?>                
                
<?php			
}
?>

<?php
  if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {
?>

<?php echo tep_draw_result2_top(); ?> 
       
		<table border="0" cellspacing="0" cellpadding="0" class="result result_bottom_padd">
          <tr>
            <td><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
            <td class="result_right" 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 echo tep_draw_result2_bottom(); ?> 

<?php
  }
?>
<?php echo tep_draw3_bottom();?>


#5 broadstreetbully

  • Community Member
  • 69 posts
  • Real Name:jason

Posted 05 December 2010, 03:02

I used this edit and it works fine, but it's slightly off...maybe 1 or 2px lower than the "add to cart" button. I saw you said to edit the html to line it up correctly but I can't seem to get it. could you help me please?

#6 mgump

  • Community Member
  • 5 posts
  • Real Name:Gump

Posted 06 November 2011, 19:56

This doesn't work for 2.3.1 -- it displays the quantity box on the product listing page but whenever you try and add it to your cart, nothing is added.

Any advice?

Edited by mgump, 06 November 2011, 19:57.


#7 peteravu

  • Community Member
  • 312 posts
  • Real Name:peter avu
  • Gender:Male

Posted 07 November 2011, 11:54

View Postmgump, on 06 November 2011, 19:56, said:

This doesn't work for 2.3.1 -- it displays the quantity box on the product listing page but whenever you try and add it to your cart, nothing is added.

Any advice?
Hi Grmp

I have the same problem, that nothing is add, hope somebody can help us.
also atributes are not there so I like products with atributes to have a "go to product" button
how ever i have add plus and minus buttons.
you can see what I have now, (I have separate_price_per_customers_4.2.2_for_2.3.1 installed so if you dont have I think you has to remove the [$x] if any)
this is my file
<form name="cart_multi" method="post" action="<?php echo tep_href_link(FILENAME_SHOPPING_CART, tep_get_all_get_params(array('action')) . 'action=add_multi', 'NONSSL'); ?>">
<script language=javascript> function changeValue(textObject,delta){  var myVal = parseInt(textObject.value);  if (myVal == NaN) {   myVal = 0;   } else {  myVal = myVal + delta;  }  /* check that it is not negetive */  if (myVal < 0) {  myVal = 0;  }  textObject.value = myVal;  return; } </script>
<?php
/*
  $Id$
  adapted for Separate Pricing Per Customer v4.2 2007/08/23
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
  Copyright (c) 2010 osCommerce
  Released under the GNU General Public License
*/
  $listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id');
?>
 
  <div class="contentText">
<?php
  if ( ($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {
?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
	<td align="right" class="main"><?php echo tep_draw_button(IMAGE_BUTTON_IN_CART, 'cart', null, 'primary'); ?></td>
  </tr>
</table>
<br>
	<div>
	  <span style="float: right;"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span>
	  <span><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></span>
	</div>
	<br />
<?php
  }
  $prod_list_contents = '<div class="ui-widget infoBoxContainer">' .
						'  <div class="ui-widget-header ui-corner-top infoBoxHeading">' .
						'	<table border="0" width="100%" cellspacing="0" cellpadding="2" class="productListingHeader">' .
						'	  <tr>';
  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
	$lc_align = '';
	switch ($column_list[$col]) {
	  case 'PRODUCT_LIST_MODEL':
		$lc_text = TABLE_HEADING_MODEL;
		$lc_align = '';
		break;
	  case 'PRODUCT_LIST_NAME':
		$lc_text = TABLE_HEADING_PRODUCTS;
		$lc_align = '';
		break;
	  case 'PRODUCT_LIST_MANUFACTURER':
		$lc_text = TABLE_HEADING_MANUFACTURER;
		$lc_align = '';
		break;
	  case 'PRODUCT_LIST_PRICE':
		$lc_text = TABLE_HEADING_PRICE;
		$lc_align = 'right';
		break;
	  case 'PRODUCT_LIST_QUANTITY':
		$lc_text = TABLE_HEADING_QUANTITY;
		$lc_align = 'right';
		break;	  
	  case 'PRODUCT_LIST_MIN_ORDER_QTY':
		$lc_align = 'center';
		$lc_text = ' ' . TABLE_HEADING_MIN_ORDER_QTY . ' ';
		break;
	  case 'PRODUCT_LIST_WEIGHT':
		$lc_text = TABLE_HEADING_WEIGHT;
		$lc_align = 'right';
		break;
	  case 'PRODUCT_LIST_IMAGE':
		$lc_text = TABLE_HEADING_IMAGE;
		$lc_align = 'center';
		break;
	  case 'PRODUCT_LIST_BUY_NOW':
		$lc_text = TABLE_HEADING_BUY_NOW;
		$lc_align = 'center';
		break;
	}
	if ( ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW') && ($column_list[$col] != 'PRODUCT_LIST_IMAGE') ) {
	  $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);
	}
	$prod_list_contents .= '		<td' . (tep_not_null($lc_align) ? ' align="' . $lc_align . '"' : '') . '>' . $lc_text . '</td>';
  }
  $prod_list_contents .= '	  </tr>' .
						 '	</table>' .
						 '  </div>';
  if ($listing_split->number_of_rows > 0) {
	$rows = 0;
	$listing_query = tep_db_query($listing_split->sql_query);
// BOF Separate Pricing per Customer
	$no_of_listings = tep_db_num_rows($listing_query);
// global variable (session) $sppc_customer_group_id -> local variable customer_group_id
  if(isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '0') {
  $customer_group_id = $_SESSION['sppc_customer_group_id'];
  } else {
   $customer_group_id = '0';
  }
while ($_listing = tep_db_fetch_array($listing_query)) {
$listing[] = $_listing;
$list_of_prdct_ids[] = $_listing['products_id'];
}
// next part is a debug feature, when uncommented it will print the info that this module receives
/*
   echo '<pre>';
   print_r($listing);
   echo '</pre>';
*/
// get all product prices for products with the particular customer_group_id
// however not necessary for customer_group_id = 0
if ($customer_group_id != '0') {
  $pg_query = tep_db_query("select pg.products_id, customers_group_price as price from " . TABLE_PRODUCTS_GROUPS . " pg where products_id in (" . implode(',', $list_of_prdct_ids) . ") and pg.customers_group_id = '" . $customer_group_id . "'");
//   $no_of_pg_products = tep_db_num_rows($pg_query) ;
while ($pg_array = tep_db_fetch_array($pg_query)) {
$new_prices[] = array ('products_id' => $pg_array['products_id'], 'products_price' => $pg_array['price'], 'specials_new_products_price' => '', 'final_price' => $pg_array['price']);
}
	for ($x = 0; $x < $no_of_listings; $x++) {
// replace products prices with those from customers_group table
	  if(!empty($new_prices)) {
		for ($i = 0; $i < count($new_prices); $i++) {
		 if( $listing[$x]['products_id'] == $new_prices[$i]['products_id'] ) {
		  $listing[$x]['products_price'] = $new_prices[$i]['products_price'];
		  $listing[$x]['final_price'] = $new_prices[$i]['final_price'];
		}
	   }
	 } // end if(!empty($new_prices)
$listing[$x]['specials_new_products_price'] = ''; // makes sure that a retail specials price doesn't carry over to another customer group
$listing[$x]['final_price'] = $listing[$x]['products_price']; // final price should not be the retail special price
   } // end for ($x = 0; $x < $no_of_listings; $x++)
} // end if ($customer_group_id != '0')
// an extra query is needed for all the specials
$specials_query = tep_db_query("select products_id, specials_new_products_price from " . TABLE_SPECIALS . " where products_id in (" . implode(',', $list_of_prdct_ids) . ") and status = '1' and customers_group_id = '" . $customer_group_id . "'");
while ($specials_array = tep_db_fetch_array($specials_query)) {
$new_s_prices[] = array ('products_id' => $specials_array['products_id'], 'products_price' => '', 'specials_new_products_price' => $specials_array['specials_new_products_price'] , 'final_price' => $specials_array['specials_new_products_price']);
}
// add the correct specials_new_products_price and replace final_price
for ($x = 0; $x < $no_of_listings; $x++) {
	if(!empty($new_s_prices)) {
	 for ($i = 0; $i < count($new_s_prices); $i++) {
	  if( $listing[$x]['products_id'] == $new_s_prices[$i]['products_id'] ) {
	  $listing[$x]['specials_new_products_price'] = $new_s_prices[$i]['specials_new_products_price'];
	  $listing[$x]['final_price'] = $new_s_prices[$i]['final_price'];
	  }
	 }
   } // end if(!empty($new_s_prices)
} // end for ($x = 0; $x < $no_of_listings; $x++)
	$prod_list_contents .= '  <div class="ui-widget-content ui-corner-bottom productListTable">' .
						   '	<table border="0" width="100%" cellspacing="0" cellpadding="2" class="productListingData">';
//	while ($listing = tep_db_fetch_array($listing_query)) { (was original code)
for ($x = 0; $x < $no_of_listings; $x++) {
	  $rows++;
	  $prod_list_contents .= '	  <tr>';
	  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
		switch ($column_list[$col]) {
		  case 'PRODUCT_LIST_MODEL':
			$prod_list_contents .= '		<td>' . $listing[$x]['products_model'] . '</td>';
			break;
		  case 'PRODUCT_LIST_NAME':
			if (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
			  $prod_list_contents .= '		<td><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing[$x]['products_id']) . '">' . $listing[$x]['products_name'] . '</a></td>';
			} else {
			  $prod_list_contents .= '		<td><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing[$x]['products_id']) . '">' . $listing[$x]['products_name'] . '</a></td>';
			}
			break;
		  case 'PRODUCT_LIST_MANUFACTURER':
			$prod_list_contents .= '		<td><a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing[$x]['manufacturers_id']) . '">' . $listing[$x]['manufacturers_name'] . '</a></td>';
			break;
		  case 'PRODUCT_LIST_PRICE':
			if (tep_not_null($listing[$x]['specials_new_products_price'])) {
			  $prod_list_contents .= '		<td align="right"><del>' .  $currencies->display_price($listing[$x]['products_price'], tep_get_tax_rate($listing[$x]['products_tax_class_id'])) . '</del>  <span class="productSpecialPrice">' . $currencies->display_price($listing[$x]['specials_new_products_price'], tep_get_tax_rate($listing[$x]['products_tax_class_id'])) . '</span></td>';
			} else {
			  $prod_list_contents .= '		<td align="right">' . $currencies->display_price($listing[$x]['products_price'], tep_get_tax_rate($listing[$x]['products_tax_class_id'])) . '</td>';
			}
			break;
		  case 'PRODUCT_LIST_QUANTITY':
			$prod_list_contents .= '		<td align="right">' . $listing[$x]['products_quantity'] . '</td>';
			break;		  
		  case 'PRODUCT_LIST_MIN_ORDER_QTY':
			$prod_list_contents .= '		<td align="right">' . $lc_text = ' ' . $listing[$x]['products_min_order_qty'] . ' ';
			break;
		  case 'PRODUCT_LIST_WEIGHT':
			$prod_list_contents .= '		<td align="right">' . $listing[$x]['products_weight'] . '</td>';
			break;
		  case 'PRODUCT_LIST_IMAGE':
			if (isset($HTTP_GET_VARS['manufacturers_id'])  && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
			  $prod_list_contents .= '		<td align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing[$x]['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing[$x]['products_image'], $listing[$x]['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>';
			} else {
			  $prod_list_contents .= '		<td align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing[$x]['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing[$x]['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>';
			}
			break;
		  case 'PRODUCT_LIST_BUY_NOW':
			$prod_list_contents .= '		<td align="center">' . $lc_text = '<input type=button value="  -1" onclick="javascript:changeValue(document.getElementById(\'add_id_'.$listing[$x]['products_id'].'\'),-1);return  false;"><input type="text" name="add_id['.$number_of_products.']"  id="add_id_'.$listing[$x]['products_id'].'" value="0" size="3"><input  type=button value="+1" onclick="javascript:changeValue(document.getElementById(\'add_id_'.$listing[$x]['products_id'].'\'),1);return  false;">';
		  $lc_text .= '<input type="hidden"  name="products_id['.$number_of_products.']"  value="'.$listing[$x]['products_id'].'">';
		 break;		  
		}
	  }
	  $prod_list_contents .= '	  </tr>';
	}
	$prod_list_contents .= '	</table>' .
						   '  </div>' .
						   '</div>';
	echo $prod_list_contents;
  } else {
?>
	<p><?php echo TEXT_NO_PRODUCTS; ?></p>
<?php
  }
  if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {
?>
	<br />
	<div>
	  <span style="float: right;"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span>
	  <span><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></span>
	</div>
<br>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
	<td align="right" class="main"><?php echo tep_draw_button(IMAGE_BUTTON_IN_CART, 'cart', null, 'primary'); ?></td>
  </tr>
</table>
</form>
<?php
  }
?>
  </div>