Jump to content

Archived

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

miserlou

Pull down quantity box.

Recommended Posts

I hope some one can help with this.

 

What I want to do is have a pull down box in the products listing and products info pages for the quantity of the item based on the actual quantity in the database.

 

I have seen a contrib. that would add a pull down box for the quantity but it was not based on the quantity in the database it just set with 1-5 on all items. With the items that I sell, all the items have different quantities from 1 to 100 and anywhere between. It would be better for the customers to just have a pull down box to pick how many they want of a particular item. Right now I have it set up were a customer can type in the quantity they want, but they can accidentally add more then I have in stock. With a pull down box I hope to not have this problem anymore and look much more professional.

 

Thanks in advance.

Share this post


Link to post
Share on other sites
I hope some one can help with this.

 

What I want to do is have a pull down box in the products listing and products info pages for the quantity of the item based on the actual quantity in the database.

 

I have seen a contrib. that would add a pull down box for the quantity but it was not based on the quantity in the database it just set with 1-5 on all items. With the items that I sell, all the items have different quantities from 1 to 100 and anywhere between. It would be better for the customers to just have a pull down box to pick how many they want of a particular item. Right now I have it set up were a customer can type in the quantity they want, but they can accidentally add more then I have in stock. With a pull down box I hope to not have this problem anymore and look much more professional.

 

Thanks in advance.

 

This is exactly what I?m looking for aswell. I have searched but not been able to find anything.

 

Can anybody help with this?

 

kind regards

 

Per

Share this post


Link to post
Share on other sites
This is exactly what I?m looking for aswell. I have searched but not been able to find anything.

 

Can anybody help with this?

 

kind regards

 

Per

I use a contribution that allows a customer to see a green colored bar as a stock indicater and as the products reduces in quantity so does the bar in size .

When the stock reaches zero the indicater turns Red with the message that this item is unavailable and out of stock

My Webpage

Take a look if this is the type of thing your after?


( WARNING )

I think I know what Im talking about.

BACK UP BACK UP BACK UP BACK UP

Share this post


Link to post
Share on other sites
I use a contribution that allows a customer to see a green colored bar as a stock indicater and as the products reduces in quantity so does the bar in size .

When the stock reaches zero the indicater turns Red with the message that this item is unavailable and out of stock

My Webpage

Take a look if this is the type of thing your after?

 

 

Thanks for your quick answear :) but the ideal solution for my shop would be the pull down box in both the products listing and the products info pages as described in the first post in this thread.

 

Hope that someone has a solution for this.

 

/Per

Share this post


Link to post
Share on other sites
I hope some one can help with this.

 

What I want to do is have a pull down box in the products listing and products info pages for the quantity of the item based on the actual quantity in the database.

 

I have seen a contrib. that would add a pull down box for the quantity but it was not based on the quantity in the database it just set with 1-5 on all items. With the items that I sell, all the items have different quantities from 1 to 100 and anywhere between. It would be better for the customers to just have a pull down box to pick how many they want of a particular item. Right now I have it set up were a customer can type in the quantity they want, but they can accidentally add more then I have in stock. With a pull down box I hope to not have this problem anymore and look much more professional.

 

Thanks in advance.

 

 

I only use it in the shopping cart but you could also use it for the product info and product listing pages.

 

// determine qty in stock

$max_to_order = tep_get_products_stock($products['id']);

$options = '';

// create array of qty up to the stock

for ($s=0 ; $s<$max_to_order; $s++) {

$z = $s+1;

$options[] = array('id' => $z,'text' => $z);

}

 

// create pulldown menu for the qty

tep_draw_pull_down_menu('cart_quantity[]', $options, $products['quantity']);


Treasurer MFC

Share this post


Link to post
Share on other sites
I only use it in the shopping cart but you could also use it for the product info and product listing pages.

 

// determine qty in stock

$max_to_order = tep_get_products_stock($products['id']);

$options = '';

// create array of qty up to the stock

for ($s=0 ; $s<$max_to_order; $s++) {

  $z =  $s+1;

  $options[] = array('id' => $z,'text' => $z);

}

 

// create pulldown menu for the qty

tep_draw_pull_down_menu('cart_quantity[]', $options, $products['quantity']);

 

Thanks! I?m not sure where to put the code though. Your help would be appreciated.

 

Thanks in advance.

 

/Per

Share this post


Link to post
Share on other sites
Thanks! I?m not sure where to put the code though. Your help would be appreciated.

 

Thanks in advance.

 

/Per

 

well, I would simply implement that contribution which gives a dropdown box from 1 to 5 and change that maximum number with the qty retrieved from the function tep_get_products_stock($products['id']);


Treasurer MFC

Share this post


Link to post
Share on other sites
well, I would simply implement that contribution which gives a dropdown box from 1 to 5 and change that maximum number with the qty retrieved from the function tep_get_products_stock($products['id']);

 

I have tried to figure out how to do this but can?t get it to work.

The contribution I?m trying to implement your code into is the following:

 

If you would rather have a pull down quantity menu than a quantity box
in the product information area, this code will do the trick. 


1. The best spot for this code is likely after the options and before the in cart button but you
can add it anywhere in the file you want. This code limits the quantity to a max of 5 but you
can change it to anything.

-------------------------------------------------------------------------------------------------------------------------
          <tr>

           <?php
             for ($i=0; $i<5; $i++) {
               $qty_array[] = array('id' => $i+1, 'text' => $i+1);
             }
           ?>
             <td class="main"><?php echo 'Quantity: ' . tep_draw_pull_down_menu('quantity', $qty_array, 1); ?></td>

           </tr>

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

2. Like Sean's contribution, search application_top.php for the following code:

--------------------------------------------- 
$HTTP_POST_VARS['id']))+1 
--------------------------------------------

and replace with this:

$HTTP_POST_VARS['id']))+ (int)$HTTP_POST_VARS['quantity']

And that's all folks!

 

Your help is appreciated.

 

/Per

Share this post


Link to post
Share on other sites
I have tried to figure out how to do this but can?t get it to work.

The contribution I?m trying to implement your code into is the following:

 

If you would rather have a pull down quantity menu than a quantity box
in the product information area, this code will do the trick. 
1. The best spot for this code is likely after the options and before the in cart button but you
can add it anywhere in the file you want. This code limits the quantity to a max of 5 but you
can change it to anything.

-------------------------------------------------------------------------------------------------------------------------
? ? ? ? ? <tr>

? ? ? ? ? ?<?php
? ? ? ? ? ? ?for ($i=0; $i<5; $i++) {
? ? ? ? ? ? ? ?$qty_array[] = array('id' => $i+1, 'text' => $i+1);
? ? ? ? ? ? ?}
? ? ? ? ? ??>
? ? ? ? ? ? ?<td class="main"><?php echo 'Quantity: ' . tep_draw_pull_down_menu('quantity', $qty_array, 1); ?></td>

? ? ? ? ? ?</tr>

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

2. Like Sean's contribution, search application_top.php for the following code:

--------------------------------------------- 
$HTTP_POST_VARS['id']))+1 
--------------------------------------------

and replace with this:

$HTTP_POST_VARS['id']))+ (int)$HTTP_POST_VARS['quantity']

And that's all folks!

 

Your help is appreciated.

 

/Per

 

like:

 

<tr>

 

<?php

$max_to_order = tep_get_products_stock($product_info['products_id']);

for ($i=0; $i<$max_to_order; $i++) {

$qty_array[] = array('id' => $i+1, 'text' => $i+1);

}

?>

<td class="main"><?php echo 'Quantity: ' . tep_draw_pull_down_menu('quantity', $qty_array, 1); ?></td>

 

</tr>


Treasurer MFC

Share this post


Link to post
Share on other sites
like:

 

<tr>

 

          <?php

$max_to_order = tep_get_products_stock($product_info['products_id']);

            for ($i=0; $i<$max_to_order; $i++) {

              $qty_array[] = array('id' => $i+1, 'text' => $i+1);

            }

          ?>

            <td class="main"><?php echo 'Quantity: ' . tep_draw_pull_down_menu('quantity', $qty_array, 1); ?></td>

 

          </tr>

 

 

Thanks soooo much! :D It works perfectly.

 

kind regards

Per

Share this post


Link to post
Share on other sites
Thanks soooo much! :D It works perfectly.

 

kind regards

Per

 

Well I get it to work perfectly in my product description page but now I have tried to implement your code into product_listing.php I can?t get it to work.

 

I would like for it to look like the picture but with the pull down box and with the same features as the pull down box in my product description.

 

screenshot.jpg

Picture taken from this contribution

http://www.oscommerce.com/community/contributions,2147/

 

 

Hoping for help with this.

 

Thanks in advance

Per

Share this post


Link to post
Share on other sites

 

okay you cant get it to work, but what have you tried


"All animals are equal, but some animals are more equal than others" - George Orwell

Share this post


Link to post
Share on other sites
okay you cant get it to work, but what have you tried

 

I have tried to modify the contribution listed a couple of posts over this one with the code provided by boxtel.

I?m pretty much a cut and paste guy but trying to learn through trial and error.

I?m lost with this though.

 

What I?m trying to do is explained in the very first post in this thread.

 

Maybe you have a solution? I would love to hear it. :)

 

kind regards

 

Per

Share this post


Link to post
Share on other sites
I have tried to modify the contribution listed a couple of posts over this one with the code provided by boxtel.

I?m pretty much a cut and paste guy but trying to learn through trial and error.

I?m lost with this though.

 

What I?m trying to do is explained in the very first post in this thread.

 

Maybe you have a solution? I would love to hear it.  :)

 

kind regards

 

Per

 

I dont have a product_listing.php, it just requeries index.php passing some variables. Where does product_listing come from?


"All animals are equal, but some animals are more equal than others" - George Orwell

Share this post


Link to post
Share on other sites

anyway,

 

in your products_listing.php it should be doing a query to get the products

 

add the following field into that query products_quantity

 

create a variable to hold it and then do your for statement thing to construct your drop down


"All animals are equal, but some animals are more equal than others" - George Orwell

Share this post


Link to post
Share on other sites
anyway,

 

in your products_listing.php it should be doing a query to get the products

 

add the following field into that query products_quantity

 

create a variable to hold it and then do your for statement thing to construct your drop down

 

Thanks for your reply mikeq!

I have played around a little with the code but I have no clue how to do this.

like I said I know very very little about coding.

 

This is what my product_listing.php looks like now. I have a quantity box which is working but now I need to get a pull down box which gets the actual quantity in stock from the databas. I have this working in the product_info.php. Can I implement the code provided by boxtel somehow in the product listing. For her code see the end of this post.

 

<?php
/*
 $Id: product_listing.php,v 1.44 2003/06/09 22:49:59 hpdl Exp $

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

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 $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') ) ) {
?>
<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
 }

 $list_box_contents = array();

 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_text = '<table cellSpacing="0" cellPadding="0" width="100%"><tr><td class="productListing-heading" align="right" width="25%">' . ' ' . TABLE_HEADING_QUANTITY  . ' ' . '</td><td class="productListing-heading" align="center" width="75%" valign="absmiddle">' . ' ' . TABLE_HEADING_BUY_NOW . ' ' . '</td></tr></table>';
       $lc_align = 'right';
       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);
   }

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

 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 = '';
           $lc_text = ' ' . $listing['products_model'] . ' ';
           break;
         case 'PRODUCT_LIST_NAME':
           $lc_align = '';
           if (isset($HTTP_GET_VARS['manufacturers_id'])) {
             $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 {
             $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 = '';
           $lc_text = ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' . $listing['manufacturers_name'] . '</a> ';
           break;
         case 'PRODUCT_LIST_PRICE':
           $lc_align = 'right';
           if (tep_not_null($listing['specials_new_products_price'])) {
             $lc_text = ' <s>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s>  <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span> ';
           } else {
             $lc_text = ' ' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' ';
           }
           break;
         case 'PRODUCT_LIST_QUANTITY':
           $lc_align = 'right';
           $lc_text = ' ' . $listing['products_quantity'] . ' ';
           break;
         case 'PRODUCT_LIST_WEIGHT':
           $lc_align = 'right';
           $lc_text = ' ' . $listing['products_weight'] . ' ';
           break;
         case 'PRODUCT_LIST_IMAGE':
           $lc_align = 'center';
           if (isset($HTTP_GET_VARS['manufacturers_id'])) {
             $lc_text = '<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 {
             $lc_text = ' <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, 'class=shadow1') . '</a> ';
           }
           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="quantity" value="1" maxlength="3" size="3"><br>' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</form>';
           break;
       }

       $list_box_contents[$cur_row][] = array('align' => $lc_align,
                                              'params' => 'class="productListing-data"',
                                              'text'  => $lc_text);
     }
   }

   new productListingBox($list_box_contents);
 } else {
   $list_box_contents = array();

   $list_box_contents[0] = array('params' => 'class="productListing-odd"');
   $list_box_contents[0][] = array('params' => 'class="productListing-data"',
                                  'text' => TEXT_NO_PRODUCTS);

   new productListingBox($list_box_contents);
 }

 if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {
?>
<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
 }
?>

 

 

 

 

I really hope that someone can help me with the code.

 

Below is the code provided by boxtel which I?m hoping to be able to use somehow in the file product_listing.php?

 

<tr>

         <?php
$max_to_order = tep_get_products_stock($product_info['products_id']);
           for ($i=0; $i<$max_to_order; $i++) {
             $qty_array[] = array('id' => $i+1, 'text' => $i+1);
           }
         ?>
           <td class="main"><?php echo 'Quantity: ' . tep_draw_pull_down_menu('quantity', $qty_array, 1); ?></td>

         </tr>

 

I would be really happy if someone could help me out with this.

 

Thanks again.

 

Per

Share this post


Link to post
Share on other sites

well where you have this piece of code

 

          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="quantity" value="1" maxlength="3" size="3"><br>' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</form>';
          break;

 

that has the code for the quantity input box, right?

 

put in your for statment

 

$max_to_order = $listing['products_quantity']);

for ($i=0; $i<$max_to_order; $i++) {

$qty_array[] = array('id' => $i+1, 'text' => $i+1);

}

?>

<td class="main"><?php echo 'Quantity: ' . tep_draw_pull_down_menu('quantity', $qty_array, 1); ?>

 

so it would be something like

 

 

  case 'PRODUCT_LIST_BUY_NOW':
 $max_to_order = tep_get_products_stock($product_info['products_id']);
 for ($i=0; $i<$max_to_order; $i++) {
	 $qty_array[] = array('id' => $i+1, 'text' => $i+1);
 }

 $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="quantity" value="1" maxlength="3" size="3"><br>' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</form>';
 break;

 

but rather than

 

<input type="text" name="quantity" value="1" maxlength="3" size="3">

 

you would replace that with the function call

 

'.tep_draw_pull_down_menu('quantity', $qty_array, 1).'


"All animals are equal, but some animals are more equal than others" - George Orwell

Share this post


Link to post
Share on other sites
well where you have this piece of code

 

 ? ? ? ? ?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="quantity" value="1" maxlength="3" size="3"><br>' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</form>';
? ? ? ? ? break;

 

that has the code for the quantity input box, right?

 

put in your for statment

 

$max_to_order = $listing['products_quantity']);

          for ($i=0; $i<$max_to_order; $i++) {

            $qty_array[] = array('id' => $i+1, 'text' => $i+1);

          }

        ?>

          <td class="main"><?php echo 'Quantity: ' . tep_draw_pull_down_menu('quantity', $qty_array, 1); ?>

 

so it would be something like

 ?case 'PRODUCT_LIST_BUY_NOW':
?$max_to_order = tep_get_products_stock($product_info['products_id']);
?for ($i=0; $i<$max_to_order; $i++) {
?	$qty_array[] = array('id' => $i+1, 'text' => $i+1);
?}

?$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="quantity" value="1" maxlength="3" size="3"><br>' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</form>';
?break;

 

but rather than

 

<input type="text" name="quantity" value="1" maxlength="3" size="3">

 

you would replace that with the function call

 

'.tep_draw_pull_down_menu('quantity', $qty_array, 1).'

 

Thanks mikeq!

I have tried to do what you suggested. I have tried something like that earlier but not been able to get it to work.

 

Here?s what the code look like when I have made your changes. I get a pull down box but nothing in it. Just an empty pull down box.

 

<?php
/*
 $Id: product_listing.php,v 1.44 2003/06/09 22:49:59 hpdl Exp $

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

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 $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') ) ) {
?>
<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
 }

 $list_box_contents = array();

 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_text = '<table cellSpacing="0" cellPadding="0" width="100%"><tr><td class="productListing-heading" align="right" width="25%">' . ' ' . TABLE_HEADING_QUANTITY  . ' ' . '</td><td class="productListing-heading" align="center" width="75%" valign="absmiddle">' . ' ' . TABLE_HEADING_BUY_NOW . ' ' . '</td></tr></table>';
       $lc_align = 'right';
       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);
   }

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

 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 = '';
           $lc_text = ' ' . $listing['products_model'] . ' ';
           break;
         case 'PRODUCT_LIST_NAME':
           $lc_align = '';
           if (isset($HTTP_GET_VARS['manufacturers_id'])) {
             $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 {
             $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 = '';
           $lc_text = ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' . $listing['manufacturers_name'] . '</a> ';
           break;
         case 'PRODUCT_LIST_PRICE':
           $lc_align = 'right';
           if (tep_not_null($listing['specials_new_products_price'])) {
             $lc_text = ' <s>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s>  <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span> ';
           } else {
             $lc_text = ' ' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' ';
           }
           break;
         case 'PRODUCT_LIST_QUANTITY':
           $lc_align = 'right';
           $lc_text = ' ' . $listing['products_quantity'] . ' ';
           break;
         case 'PRODUCT_LIST_WEIGHT':
           $lc_align = 'right';
           $lc_text = ' ' . $listing['products_weight'] . ' ';
           break;
         case 'PRODUCT_LIST_IMAGE':
           $lc_align = 'center';
           if (isset($HTTP_GET_VARS['manufacturers_id'])) {
             $lc_text = '<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 {
             $lc_text = ' <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, 'class=shadow1') . '</a> ';
           }
           break;
         case 'PRODUCT_LIST_BUY_NOW':
         $max_to_order = tep_get_products_stock($product_info['products_id']);
         for ($i=0; $i<$max_to_order; $i++) {
         $qty_array[] = array('id' => $i+1, 'text' => $i+1);
         }

         $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'] . '">'.tep_draw_pull_down_menu('quantity', $qty_array, 1).'<br>' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</form>';
         break;
         }

       $list_box_contents[$cur_row][] = array('align' => $lc_align,
                                              'params' => 'class="productListing-data"',
                                              'text'  => $lc_text);
     }
   }

   new productListingBox($list_box_contents);
 } else {
   $list_box_contents = array();

   $list_box_contents[0] = array('params' => 'class="productListing-odd"');
   $list_box_contents[0][] = array('params' => 'class="productListing-data"',
                                  'text' => TEXT_NO_PRODUCTS);

   new productListingBox($list_box_contents);
 }

 if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {
?>
<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
 }
?>

 

What am I doing wrong?

 

/Per

Share this post


Link to post
Share on other sites
Thanks mikeq!

I have tried to do what you suggested. I have tried something like that earlier but not been able to get it to work.

 

Here?s what the code look like when I have made your changes. I get a pull down box but nothing in it. Just an empty pull down box.

 

<?php
/*
?$Id: product_listing.php,v 1.44 2003/06/09 22:49:59 hpdl Exp $

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

?Copyright (c) 2003 osCommerce

?Released under the GNU General Public License
*/

?$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') ) ) {
?>
<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
?}

?$list_box_contents = array();

?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_text = '<table cellSpacing="0" cellPadding="0" width="100%"><tr><td class="productListing-heading" align="right" width="25%">' . ' ' . TABLE_HEADING_QUANTITY ?. ' ' . '</td><td class="productListing-heading" align="center" width="75%" valign="absmiddle">' . ' ' . TABLE_HEADING_BUY_NOW . ' ' . '</td></tr></table>';
? ? ? ?$lc_align = 'right';
? ? ? ?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);
? ?}

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

?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 = '';
? ? ? ? ? ?$lc_text = ' ' . $listing['products_model'] . ' ';
? ? ? ? ? ?break;
? ? ? ? ?case 'PRODUCT_LIST_NAME':
? ? ? ? ? ?$lc_align = '';
? ? ? ? ? ?if (isset($HTTP_GET_VARS['manufacturers_id'])) {
? ? ? ? ? ? ?$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 {
? ? ? ? ? ? ?$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 = '';
? ? ? ? ? ?$lc_text = ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' . $listing['manufacturers_name'] . '</a> ';
? ? ? ? ? ?break;
? ? ? ? ?case 'PRODUCT_LIST_PRICE':
? ? ? ? ? ?$lc_align = 'right';
? ? ? ? ? ?if (tep_not_null($listing['specials_new_products_price'])) {
? ? ? ? ? ? ?$lc_text = ' <s>' . ?$currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s>  <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span> ';
? ? ? ? ? ?} else {
? ? ? ? ? ? ?$lc_text = ' ' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' ';
? ? ? ? ? ?}
? ? ? ? ? ?break;
? ? ? ? ?case 'PRODUCT_LIST_QUANTITY':
? ? ? ? ? ?$lc_align = 'right';
? ? ? ? ? ?$lc_text = ' ' . $listing['products_quantity'] . ' ';
? ? ? ? ? ?break;
? ? ? ? ?case 'PRODUCT_LIST_WEIGHT':
? ? ? ? ? ?$lc_align = 'right';
? ? ? ? ? ?$lc_text = ' ' . $listing['products_weight'] . ' ';
? ? ? ? ? ?break;
? ? ? ? ?case 'PRODUCT_LIST_IMAGE':
? ? ? ? ? ?$lc_align = 'center';
? ? ? ? ? ?if (isset($HTTP_GET_VARS['manufacturers_id'])) {
? ? ? ? ? ? ?$lc_text = '<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 {
? ? ? ? ? ? ?$lc_text = ' <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, 'class=shadow1') . '</a> ';
? ? ? ? ? ?}
? ? ? ? ? ?break;
? ? ? ? ?case 'PRODUCT_LIST_BUY_NOW':
? ? ? ? ?$max_to_order = tep_get_products_stock($product_info['products_id']);
? ? ? ? ?for ($i=0; $i<$max_to_order; $i++) {
? ? ? ? ?$qty_array[] = array('id' => $i+1, 'text' => $i+1);
? ? ? ? ?}

? ? ? ? ?$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'] . '">'.tep_draw_pull_down_menu('quantity', $qty_array, 1).'<br>' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</form>';
? ? ? ? ?break;
? ? ? ? ?}

? ? ? ?$list_box_contents[$cur_row][] = array('align' => $lc_align,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'params' => 'class="productListing-data"',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'text' ?=> $lc_text);
? ? ?}
? ?}

? ?new productListingBox($list_box_contents);
?} else {
? ?$list_box_contents = array();

? ?$list_box_contents[0] = array('params' => 'class="productListing-odd"');
? ?$list_box_contents[0][] = array('params' => 'class="productListing-data"',
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'text' => TEXT_NO_PRODUCTS);

? ?new productListingBox($list_box_contents);
?}

?if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {
?>
<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
?}
?>

 

What am I doing wrong?

 

/Per

 

 

this :

 

$max_to_order = tep_get_products_stock($product_info['products_id']);

 

should be :

 

$max_to_order = tep_get_products_stock($listing['products_id']);

 

and be aware that in application top the action "add_product" adds 1 by default so you need to pull the quantity value there as well.


Treasurer MFC

Share this post


Link to post
Share on other sites
this :

 

        $max_to_order = tep_get_products_stock($product_info['products_id']);

 

should be :

 

        $max_to_order = tep_get_products_stock($listing['products_id']);

 

and be aware that in application top the action "add_product" adds 1 by default so you need to pull the quantity value there as well.

 

Well what can I say...you are the best. It is now working. Thanks to both of you guys! I will try to make a conclution and write it in this post. Maybe it can be useful for somebody else.

 

Thanks again Boxtel and mikeq!

 

kind regards

Per

Share this post


Link to post
Share on other sites
Well what can I say...you are the best. It is now working. Thanks to both of you guys! I will try to make a conclution and write it in this post. Maybe it can be useful for somebody else.

 

Thanks again Boxtel and mikeq!

 

kind regards

Per

 

And in the interests of performance you could try it with

 

$max_to_order = $listing['products_quantity'];

 

which is the field I asked you to add to the query earlier.

 

tep_get_products_stock is perfomring another query on the database, but we have already retrieved that information in the original query so there isnt really any need to query again.


"All animals are equal, but some animals are more equal than others" - George Orwell

Share this post


Link to post
Share on other sites
And in the interests of performance you could try it with

 

$max_to_order = $listing['products_quantity'];

 

which is the field I asked you to add to the query earlier.

 

tep_get_products_stock is perfomring another query on the database, but we have already retrieved that information in the original query so there isnt really any need to query again.

 

I tried to add that but it didn?t work then.

 

I tested the changes I made earlier and I?m getting something strange happening with my pull down boxes with the products where I have only one of each in stock.

 

On the first product in the list I will get a perfect pull down box with the number one. In the second product in the list I will get a pull down box with two ones. And in the third product in the list I will get a pull down box with three ones and so on..

 

This isn?t really a big problem since I can only choose one anyway but it looks a little bit stupid.

A Link, so you can see what I?m talking about. Don?t worry about anything else on the page since I?m trying to get this funktion to work now and will take care of the other things later.

 

 

In the products where I have more than one in stock it works perfect.

 

Why is this happening?

Suggestions?

 

/Per

Share this post


Link to post
Share on other sites
I tried to add that but it didn?t work then.

 

I tested the changes I made earlier and I?m getting something strange happening with my pull down boxes with the products where I have only one of each in stock.

 

On the first product in the list I will get a perfect pull down box with the number one. In the second product in the list I will get a pull down box with two ones. And in the third product in the list I will get a pull down box with three ones and so on..

 

This isn?t really a big problem since I can only choose one anyway but it looks a little bit stupid.

A Link, so you can see what I?m talking about. Don?t worry about anything else on the page since I?m trying to get this funktion to work now and will take care of the other things later.

In the products where I have more than one in stock it works perfect.

 

Why is this happening?

Suggestions?

 

/Per

 

this is because the array is not reset and as such the values are added and added.

 

try putting this :

 

$qty_array = array;

 

before the $max_to_order = .....


Treasurer MFC

Share this post


Link to post
Share on other sites
this is because the array is not reset and as such the values are added and added.

 

try putting this :

 

$qty_array = array;

 

before the $max_to_order = .....

 

I tried it and it gave me an error:

Parse error: parse error, unexpected ';', expecting '('

 

/Per

Share this post


Link to post
Share on other sites

×