Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

DB Query help needed...


Guest

Recommended Posts

I have recently installed the Add Multiple Items contribution which puts text boxes on the product listing page so that a consumer can add multiple items to their cart at one time. Currently all quantity boxes read "0". I would like them to pull the quantity from the products table so that each product can have a different default qty. I know it may sound a bit strange, but for our application it's very important.

 

I have added "products_qty_suggest" to the products table and this is where I would like to pull the default qty from.

 

Line 126 of the products_listing_multi.php reads:

     $lc_align = 'right'; 

    $lc_text = '<input type="text" name="add_id['.$number_of_products.']" value="0" size="4">'; 

    $list_box_contents[$cur_row][] = array('align' => $lc_align, 

                                           'params' => 'class="productListing-data"', 

                                           'text'  => $lc_text);

I know that changing the value="0" is probably what I need to do here but I can't figure out the code to add to make it pull 'products_qty_suggest' from the products table. Can anyone help me here? I'm including the complete code from the products_listing_multi here in case it's needed. Any and all responses would be greatly appreciated.

 

<?php 

/* 

 $Id: product_listing.php,v 1.39 2002/10/26 22:43:14 dgw_ Exp $ 



 osCommerce, Open Source E-Commerce Solutions 

 http://www.oscommerce.com 



 Copyright (c) 2002 osCommerce 



 Released under the GNU General Public License 

*/ 

?> 

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

<?php 

 $listing_numrows_sql = $listing_sql; 

// fix counted products 

 $listing_numrows = tep_db_query($listing_numrows_sql); 

 $listing_numrows = tep_db_num_rows($listing_numrows); 



 if ($listing_numrows > 0 ) { 

?> 

 <tr> 

   <td> 

<?php 

   $listing = tep_db_query($listing_sql); 

   $list_box_contents = array(); 

   $number_of_products = '0'; 

?> 

   <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'); ?>"> 

   <?php //echo tep_draw_form('cart_multi', tep_href_link(FILENAME_SHOPPING_CART, tep_get_all_get_params(array('action')) . 'action=add_multi', 'NONSSL')); ?> 



<?php 

   $list_box_contents[] = array('params' => 'class="productListing-heading"'); 



   $cur_row = sizeof($list_box_contents) - 1; 



  

   $lc_text = TEXT_IMAGE; 

   $lc_align = 'left'; 

   $list_box_contents[$cur_row][] = array('align' => $lc_align, 

                                           'params' => 'class="productListing-data"', 

                                           'text'  => $lc_text); 

   $lc_text = TEXT_PRODUCT; 

   $lc_align = 'left'; 

    $list_box_contents[$cur_row][] = array('align' => $lc_align, 

                                           'params' => 'class="productListing-data"', 

                                           'text'  => $lc_text); 

   

   $lc_text = TEXT_PRICE; 

   $lc_align = 'right'; 

    $list_box_contents[$cur_row][] = array('align' => $lc_align, 

                                           'params' => 'class="productListing-data"', 

                                           'text'  => $lc_text); 



 $lc_text = TEXT_QUANTITY; 

   $lc_align = 'right'; 

    $list_box_contents[$cur_row][] = array('align' => $lc_align, 

                                           'params' => 'class="productListing-data"', 

                                           'text'  => $lc_text); 

  // $lc_text = TEXT_AMOUNT_BUY; 

   //$lc_align = 'right'; 

    //$list_box_contents[$cur_row][] = array('align' => $lc_align, 

      //                                     'params' => 'class="productListing-data"', 

        //                                   'text'  => $lc_text); 



   while ($listing_values = tep_db_fetch_array($listing)) { 

     $number_of_products++; 

     $lc_align=''; 

     if ( ($number_of_products/2) == floor($number_of_products/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; 

     $products_attributes = tep_db_query("select popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . $listing_values['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . $languages_id . "'"); 

     if (tep_db_num_rows($products_attributes)) { 

       $products_attributes = '1'; 

     } else { 

       $products_attributes = '0'; 

     } 

//product_image 

    $lc_align = 'center'; 

    $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing_values['products_image'], $listing_values['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a> '; 

    $list_box_contents[$cur_row][] = array('align' => $lc_align, 

                                           'params' => 'class="productListing-data"', 

                                           'text'  => $lc_text); 



// product_name 

    $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . $listing_values['products_name'] . '</a> '; 

   $lc_align = 'left'; 

    $list_box_contents[$cur_row][] = array('align' => $lc_align, 

                                           'params' => 'class="productListing-data"', 

                                           'text'  => $lc_text); 

// product_model 

    $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing_values['products_id']) . '">' . $listing_values['products_model'] . '</a> '; 

    $lc_text = ' '.$listing_values['products_model'].' '; 

    $lc_align = 'center'; 

    $list_box_contents[$cur_row][] = array('align' => $lc_align, 

                                           'params' => 'class="productListing-data"', 

                                           'text'  => $lc_text); 

// product_quantity 

    $lc_text = ' '.$listing_values['products_qty_suggest'].' '; 

    $lc_align = 'right'; 

    $list_box_contents[$cur_row][] = array('align' => $lc_align, 

                                           'params' => 'class="productListing-data"', 

                                           'text'  => $lc_text); 



     if ($products_attributes) { 







     } 

//salemaker 

           if (tep_get_products_special_price($listing_values['products_id'])) { 

//salemaker 

             $lc_text = ' <s>' .  $currencies->display_price($listing_values['products_price'], tep_get_tax_rate($listing_values['products_tax_class_id'])) . '</s>  <span class="productSpecialPrice">' . $currencies->display_price(tep_get_products_special_price($listing_values['products_id']), tep_get_tax_rate($listing_values['products_tax_class_id'])) . '</span> '; 

            } else { 

              $lc_text = ' ' . $currencies->display_price($listing_values['products_price'], tep_get_tax_rate($listing_values['products_tax_class_id'])) . ' '; 

            } 

    $lc_align = 'right'; 

    $list_box_contents[$cur_row][] = array('align' => $lc_align, 

                                           'params' => 'class="productListing-data"', 

                                           'text'  => $lc_text); 



    $lc_align = 'right'; 

    $lc_text = '<input type="text" name="add_id['.$number_of_products.']" value="0" size="4">'; 

    $list_box_contents[$cur_row][] = array('align' => $lc_align, 

                                           'params' => 'class="productListing-data"', 

                                           'text'  => $lc_text); 

?> 

<input type="hidden" name="products_id[<?php echo $number_of_products; ?>]" value="<?php echo $listing_values['products_id']; ?>"> 

<?php 

   } 

   new tableBox($list_box_contents, true); 



   echo '    </td>' . "n"; 

   echo '  </tr>' . "n"; 

?> 

     <tr> 

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

         <tr> 

           <td align="left" class="main"><a href=<?php// echo tep_href_link(FILENAME_LOGIN, '', 'SSL'); ?>><?php //echo tep_image_submit('button_checkout.gif', IMAGE_BUTTON_CHECKOUT); ?></a></td> 

           <td align="right" class="main"><?php echo tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></td> 

         </tr> 

       </table></td> 

     </tr></form> 

<?php 











 } else { 

?> 

 <tr class="productListing-odd"> 

   <td class="smallText"> <?php echo ($HTTP_GET_VARS['manufacturers_id'] ? TEXT_NO_PRODUCTS2 : TEXT_NO_PRODUCTS); ?> </td> 

 </tr> 

<?php 

 } 

?> 

</table>

Thanks again!!!

Link to comment
Share on other sites

Thanks for your reply Matti. I believe I have added the $listing_sql query in index.php correctly

 

 case 'PRODUCT_LIST_SUGGEST':

         $listing_sql .= "p.products_qty_suggest " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";

         break;

 

as well as addiing p.products_qty_suggest to each of the "select" commands. What variable would I add to my products_listing_multi.php to make the call correctly. I really appreciate the help as I've been really struggling with this. Again, I think I should add the variable here replacing the value="0":

 

     $lc_align = 'right'; 

    $lc_text = '<input type="text" name="add_id['.$number_of_products.']" value="0" size="4">'; 

    $list_box_contents[$cur_row][] = array('align' => $lc_align, 

                                           'params' => 'class="productListing-data"', 

                                           'text'  => $lc_text);

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...