Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

I've seen on some OSC sites product pages a quantity box


Guest

Recommended Posts

to put a # in before clicking the purchase button. I have searched for quantity box, but i got 247 pages of listings, and couldn't find anything through the first 8. Could someone point me in the right direction? Thanks in advance...

Link to comment
Share on other sites

that's it, but it looks like the answer was never given. I need it to be on the index.php page, so there isn't another click to go to the product_info page. I want people to just be able to put a number in the column for what they want and be able to click "put in cart". Any other ideas?

Link to comment
Share on other sites

is this what you are looking for:

 

http://www.yantzitimbr.com/catalog/default...p?cPath=216_217

 

I have it so that the add product button can be used to just add one of that item, of if quantities are entered and the button at the bottom is hit, then all of those items are added to the cart. I did a couple of small modifications to this contribution:

 

http://www.oscommerce.com/downloads.php/co...ions,466/type,3

Unexpect the Expected

Link to comment
Share on other sites

That's exactly what i'm looking for. Any way you could share that code for it to work on the default or index page? It doesn't look like it's too much modification, but i'm stumped...

Link to comment
Share on other sites

I'll have to do a bit of digging in my code to find where I made changes from the original contribution, but I'll get to it this weekend. (There were only a couple, to allow the buy now button to work, I think. It was a few weeks ago). When you say you need it on the default page, do you mean the new products listing that shows up when you first visit the site? I have new products turned off for this particular site.

Unexpect the Expected

Link to comment
Share on other sites

No, i just meant so people could pick the # of items they want when they go to the categories part of the default page, without going to the products pae itself. Make sense? Thanks for the time to find this, it's really important.

Link to comment
Share on other sites

I'm having a hard time sorting out the changes I did for the quantity change versus the other mods I have made. Try making the changes as per the contribution, and if you need more than what it gives, let me know, and I'm sure I can point you in the right direction.

Unexpect the Expected

Link to comment
Share on other sites

The contrib was just reeal confusing. It only added a few lines to the application_top.php file, so i'm not sure what that is supposed to do. Am I supposed to write the code for that in the pages I want to use it on? I'm beyond confused...

Link to comment
Share on other sites

Jeff,

I tried looking at your code as much as I could to get the direction of where to go. You have the form posting to...

 

<form action="addtocart.php" method="post" id="form1" name="form1">

 

I don't have an addtocart.php page that I know of. Did you create this? If so, maybe that is all i'll need. Just add the line to the form for the quantity field, then the addtocart.php file? I've added the line of code to the application_top.php file, but where to start next i'm clueless. I want to have my website up by Friday, so i'm working hard on this. I hope to hear a little more input if you have a chance, since this is the last main change I need. And if you just happen to burn candles, i'll send you one of mine on the site...

Link to comment
Share on other sites

Wow,

 

great mod!

 

Regards Seb

 

is this what you are looking for:

 

http://www.yantzitimbr.com/catalog/default...p?cPath=216_217

 

I have it so that the add product button can be used to just add one of that item, of if quantities are entered and the button at the bottom is hit, then all of those items are added to the cart. I did a couple of small modifications to this contribution:

 

http://www.oscommerce.com/downloads.php/co...ions,466/type,3

Link to comment
Share on other sites

Eureka - here's the link for the base code.:

 

http://www.oscommerce.com/forums/viewtopic.php?t=22973

 

sorry, folks - it was a while ago, and I'm working on five very different implementation of oscommerce right now, and my brain is a bit spinny. I'm trying to remember everything that I did, but it's a start. I did sort out John's issue with the next button - let me try and squeeze my brain and find my changes.

Unexpect the Expected

Link to comment
Share on other sites

Great!

 

this is an excellent mod I will see if I can't play with this a bit myself

 

regards Seb

 

Eureka - here's the link for the base code.:

 

http://www.oscommerce.com/forums/viewtopic.php?t=22973

 

sorry, folks - it was a while ago, and I'm working on five very different implementation of oscommerce right now, and my brain is a bit spinny. I'm trying to remember everything that I did, but it's a start. I did sort out John's issue with the next button - let me try and squeeze my brain and find my changes.

Link to comment
Share on other sites

sorry for putting the code here in the forum - but here is my listing for product_listing.php and John's addtocart.php

 

You will probably have to remove my references to the UNITS field, but other than that it should work.

product_listing.php:

 

<?php

/*

 $Id: product_listing.php,v 1.38 2002/08/01 10:55:27 hpdl Exp $



 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com



 Copyright (c) 2002 osCommerce



 Released under the GNU General Public License

*/

?>

<form action="addtocart.php" method="post" id="form1" name="form1">

<table border="0" width="100%" cellspacing="0" cellpadding="2" background="/catalog/images/mainBackground.gif">

<script language="javascript" src="includes/general.js"></script>

<script language="javascript"><!--

function popupWindow(url) {

 window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resiza
ble=yes,copyhistory=no,width=450,height=280,screenX=150,screenY=150,top=150,left=
150')

}

//--></script>



<?php



 $colspan = sizeof($column_list);



 $listing_numrows_sql = $listing_sql;

 $listing_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $listing_sql, $listing_numrows);

// fix counted products

 $listing_numrows = tep_db_query($listing_numrows_sql);

 $listing_numrows = tep_db_num_rows($listing_numrows);



 if ($listing_numrows > 0 && (PREV_NEXT_BAR_LOCATION == '1' || PREV_NEXT_BAR_LOCATION == '3')) {

?>

 <tr>

   <td colspan="<?php echo $colspan; ?>"><table border="0" width="100%" cellspacing="0" cellpadding="2">

     <tr>

       <td class="smallText"> <?php echo $listing_split->display_count($listing_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?> </td>

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

     </tr>

   </table></td>

 </tr>

 <tr>

   <td colspan="<?php echo $colspan; ?>"><?php echo tep_draw_separator(); ?></td>

 </tr>

<?php

 }

?>

 <tr>

   <td>

<?php

 $list_box_contents = array();

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

 $cur_row = sizeof($list_box_contents) - 1;



 for ($col=0; $col<sizeof($column_list); $col++) {

   switch ($column_list[$col]) {

     case 'PRODUCT_LIST_MODEL':

       $lc_text = TABLE_HEADING_MODEL;

       $lc_align = 'left';

       break;

     case 'PRODUCT_LIST_NAME':

       $lc_text = TABLE_HEADING_PRODUCTS;

       $lc_align = 'left';

       break;

     case 'PRODUCT_LIST_MANUFACTURER':

       $lc_text = TABLE_HEADING_MANUFACTURER;

       $lc_align = 'left';

       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_UNIT':

       $lc_text = TABLE_HEADING_UNIT;

       $lc_align = 'left';

       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);



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

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

                                            'text'  => " " . $lc_text . " ");

 }



 if ($listing_numrows > 0) {

   $number_of_products = '0';

   $listing = tep_db_query($listing_sql);

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

$customer_group_query = tep_db_query("select customers_group_id from " . TABLE_CUSTOMERS . " where customers_id =  '" . $customer_id . "'");

$customer_group = tep_db_fetch_array($customer_group_query);

$customer_group_price_query = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . $listing_values['products_id'] . "' and customers_group_id =  '" . $customer_group['customers_group_id'] . "'");

if ( $customer_group['customers_group_id'] != 0) {

 if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) {

   $listing_values['products_price'] = $customer_group_price['customers_group_price'];

 }

}

    $number_of_products++;



     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;

     

     for ($col=0; $col<sizeof($column_list); $col++) {

       $lc_align = '';



       switch ($column_list[$col]) {

         case 'PRODUCT_LIST_MODEL':

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

           break;

         case 'PRODUCT_LIST_NAME':

           if ($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_values['products_id'], 'NONSSL') . '">' . $listing_values['products_name'] . '</a>';

           } else {

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

           }

           break;

         case 'PRODUCT_LIST_MANUFACTURER':

           $lc_text = ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing_values['manufacturers_id'], 'NONSSL') . '">' . $listing_values['manufacturers_name'] . '</a> ';

           break;

         case 'PRODUCT_LIST_PRICE':

           $lc_align = 'right';

           if ($listing_values['specials_new_products_price']) {

             $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($listing_values['specials_new_products_price'], 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'])) . ' ';

           }

           break;

         case 'PRODUCT_LIST_QUANTITY':

           $lc_align = 'right';

           $lc_text = '<input type="text" name="Qty_ProdId_' . $listing_values['products_id'] . '" value="0" maxlength="6" size="4">';

//            $lc_text = ' ' . $listing_values['products_quantity'] . ' ';

           break;

         case 'PRODUCT_LIST_WEIGHT':

           $lc_align = 'right';

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

           break;

         case 'PRODUCT_LIST_UNIT':

           $lc_align = 'left';

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

           break;

         case 'PRODUCT_LIST_IMAGE':

           $lc_align = 'center';

           if ($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_values['products_id'], 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . $listing_values['products_image'], $listing_values['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_values['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing_values['products_image'], $listing_values['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a> ';

           }

           break;

         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_values['products_id'], 'NONSSL') . '">' . tep_image_button('button_buy_now.gif', TEXT_BUY . $listing_values['products_name'] . TEXT_NOW) . '</a> ';

           break;

       }



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

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

                                              'text'  => $lc_text);



     }

   }

   new tableBox($list_box_contents, true);



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

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

 } else {

?>

 <tr class="productListing-odd">

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

 </tr>

<?php

 }

?>

 <tr>

   <td  align="right" colspan="<?php echo $colspan; ?>"><input type="submit" align="absmiddle" value="Add To Cart" id="submit1" name="submit1" Class="SubmitBtn"></form></td>

 </tr>

 <tr>

   <td colspan="<?php echo $colspan; ?>"><?php echo tep_draw_separator(); ?></td>

 </tr>

<?php

 if ($listing_numrows > 0 && (PREV_NEXT_BAR_LOCATION == '2' || PREV_NEXT_BAR_LOCATION == '3')) {

?>

 <tr>

   <td colspan="<?php echo $colspan; ?>"><table border="0" width="100%" cellspacing="0" cellpadding="2">

     <tr>

       <td class="smallText"> <?php echo $listing_split->display_count($listing_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?> </td>

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

     </tr>

   </table></td>

 </tr>

<?php

 }

?>

</table>

 

addtocart.php (put this in the catalog root directory)

 

<?php

require('includes/application_top.php');





if (0) session_start();



// a couple flags used during debugging

$putdbg = 0; // put out dbg msgs

$docart = 1; // actually add products to cart



// Enter Items into cart



if ($putdbg) echo "<BR>POST VARS<BR>";

while ( list( $key, $val ) = each( $HTTP_POST_VARS ) )

{

if ($putdbg) echo "$key=$val<BR>n";

if (substr($key,0,11) == "Qty_ProdId_" || substr($key,0,11) == "Qty_NPrdId_")

{

$prodId = substr($key, 11);

$qty = $val;

if ($qty <= 0 ) continue;

if ($putdbg) echo "Got a hit, $key=$val, P=$prodId, Q=$qty<BR>n";

if ($docart)

{

$cart->add_cart($prodId, $qty, '', true);

}

}

}



if ($putdbg) echo "<BR><BR>SESSION VARS<BR>";

while ( list( $key, $val ) = each( $HTTP_SESSION_VARS ) )

{

if ($putdbg) echo "$key=$val<BR>n";

}



if ($docart)

{



tep_session_register('cart');



tep_redirect("shopping_cart.php"); 



}



?>

Unexpect the Expected

Link to comment
Share on other sites

Hi all,

 

just installed this with some minor mods (very little - changed the tep_redirect to the page it was refered from and deleted some code to suit my snapshot)

 

if you install this (and it works great BTW so much so that I have added it to my site) be advised that if has some problems with download items, it dos'nt pass the url option at lest on my snapshot.

 

The download does work though from the products page, but not from the product_listing page.

 

A nice piece of work. Thanks guys!!

Regards Seb

Link to comment
Share on other sites

Woohoo!

I got it to work myself! Thanks for the help Jeff. The only thing I can't figure out now is how to remove the link for the Quantity header to "Sort products ascendingly by category"? I see you still have the link on your site. Thanks again for all the help!

Link to comment
Share on other sites

Yep you are right!

 

Add this line:

 

$column_list[$col] != 'PRODUCT_LIST_QUANTITY'

to:

 

if ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW' &&

$column_list[$col] != 'PRODUCT_LIST_IMAGE' &&

$column_list[$col] != 'PRODUCT_LIST_QUANTITY' // don't sort quantity

 

I should have picked that up myself.

 

regards Seb

 

Woohoo!

I got it to work myself! Thanks for the help Jeff. The only thing I can't figure out now is how to remove the link for the Quantity header to "Sort products ascendingly by category"? I see you still have the link on your site. Thanks again for all the help!

Link to comment
Share on other sites

is this what you are looking for:

 

http://www.yantzitimbr.com/catalog/default...p?cPath=216_217

 

I have it so that the add product button can be used to just add one of that item, of if quantities are entered and the button at the bottom is hit, then all of those items are added to the cart. I did a couple of small modifications to this contribution:

 

http://www.oscommerce.com/downloads.php/co...ions,466/type,3

 

Hello Mouflon!

 

I've seen your page and, in my opinion, there are two weak points:

 

1. It's not very easy to get the idea

 

- If anybody put a number in the box and click the "add to cart" button, then the number doesn't do anything. You must know that it's necessary click on the bottom button.

 

2. Continue shopping button bug

 

- When you do it right (clicking the botton button), you go to the "Cart Contents" view but the buttom "Continue shopping" doesn't run

 

- I think the best way would be adding products directly to the cart without view it. Is it possible?

 

Regards,

 

Joan

[email protected]

www.delaterra.net

organic food in Catalonia

Link to comment
Share on other sites

Actually there are several bugs within OSC, and there are are few in this code but if you look at the code you will see that it is a base to build on.

 

The add to cart button adds multiples at once, if you have the cart box in one of the side includes you will see that the items are added to the cart, as for taking you to the cart it' self after you hit the add to cart simply edit the redirect link to point back to the page.

 

Regards Seb

Link to comment
Share on other sites

Hi arbocenc

 

Your points are quite valid - in the case of the posted site - the "buy now" buttons are going away - they are strictly there for testing purposes, the site isn't live yet. In order to have both the buy now button and quantity box some descriptive text will be needed, probaly the text on the buttons changed to make it clearer, and also I haven't written the help file yet - accessible from the help link in the top right.

 

Also, there is still some extraneous code in there specific to this site - reference to the UNITS field, and code for the seperate price per cosumer contribution. That code should be stripped out. As Seb says, this is a base to work from, not a finished piece of work.

Unexpect the Expected

Link to comment
Share on other sites

  • 2 months later...

<?php

require('includes/application_top.php');

 

 

if (0) session_start();

 

// a couple flags used during debugging

$putdbg = 0; // put out dbg msgs

$docart = 1; // actually add products to cart

 

// Enter Items into cart

 

if ($putdbg) echo "<BR>POST VARS<BR>";

while ( list( $key, $val ) = each( $HTTP_POST_VARS ) )

{

if ($putdbg) echo "$key=$val<BR>n";

if (substr($key,0,11) == "Qty_ProdId_" || substr($key,0,11) == "Qty_NPrdId_")

{

$prodId = substr($key, 11);

$qty = $val;

if ($qty <= 0 ) continue;

if ($putdbg) echo "Got a hit, $key=$val, P=$prodId, Q=$qty<BR>n";

if ($docart)

{

$cart->add_cart($prodId, $qty, '', true);

}

}

}

 

if ($putdbg) echo "<BR><BR>SESSION VARS<BR>";

while ( list( $key, $val ) = each( $HTTP_SESSION_VARS ) )

{

if ($putdbg) echo "$key=$val<BR>n";

}

 

if ($docart)

{

 

tep_session_register('cart');

 

tep_redirect($HTTP_REFERER);

 

 

}

 

?>

Link to comment
Share on other sites

I wish we cpuld edit our posts after submitting them, any way I left out the reason for the post, I had a few mails asking how to redirect back to the same page after hitting add to cart, so I thought I would simply post the whole code for others to see.

Regards Seb

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...