Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Adding a Quantity Box to Product Listings


themutantchair

Recommended Posts

Posted

In includes/application_top.php

replace this code (look around line 375)

                                  $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+1);

with

                                  $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+$_POST[list_quantity]);

 

In includes/modules/product_listing.php

replace this code (around line 135)

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

with

    case 'PRODUCT_LIST_BUY_NOW':
          $lc_align = 'center';
          $lc_text = tep_draw_form('buy_now' . $listing['products_id'], tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']), 'POST') . tep_draw_input_field('list_quantity', '1', 'size=2') . tep_image_submit('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</form> ';

 

That should be it!

 

Good luck!

Posted

No joke, I was looking for the same feature for hours. People have asked for it forever, but nobody's really had a working contribution.

 

Oh, and thanks to matt for the preliminary code he offered in another thread. It didn't work, but I modified it a bit, and it worked fine.

Posted

Ahh, coool,

 

Thanks for that, worked perfectly,. just one thing, how would i use this on product info.php,

 

 

Great work though

 

Thanks

 

kristofor

Don't die with the music in you!!!

 

Failure is just another boundary to sucess!!! But that doesn't mean your getting somewhere...

Posted

I need your help, in my old version, the following message...

 

Fatal error: Call to undefined function: tep_draw_form() in /.../catalogo/includes/modules/product_listing.php on line 190

 

How can I do, to fix that? Thanks

Posted
I need your help, in my old version, the following message...

 

Fatal error: Call to undefined function: tep_draw_form() in /.../catalogo/includes/modules/product_listing.php on line 190

 

How can I do, to fix that? Thanks

I?m using snapshot: Oct-23-2002 4:08

 

How can I add this function to my old version?

What is the files dependencies?

THANKS

Posted

tep_draw_form is from includes/functions/html_output.php if you want to download MS2 and copy it.

 

Hth,

Matt

Posted

Thanks Matt

 

I copied the following code accordint to my version ...

// Output a form hidden field
 function tep_draw_hidden_field($name, $value = '') {
   $field = '<input type="hidden" name="' . $name . '" value="';
   if ($value != '') {
     $field .= trim($value);
   } else {
     $field .= trim($GLOBALS[$name]);
   }
   $field .= '">';

   return $field;
 }

////

 

But, in my shoppint cart doesnt show anything? Could you help me? thanks

Posted

sorry, the code copied was...

// Output a form
 function tep_draw_form($name, $action, $method = 'post', $parameters = '') {
   $form = '<form name="' . $name . '" action="' . $action . '" method="' . $method . '"';
   if ($parameters) $form .= ' ' . $parameters;
   $form .= '>';

   return $form;
 }

////

 

But, I doesnt work the shopping cart.

Posted

I don't know how to help with your problem. I'm barely 10 chapters in to my php book.

 

I suppose if my code's causing the problem, you could drop the whole tep_draw_form function, and just do a simple <form> tag. Unfortunately, I don't feel skilled enough to say exactly how to do it.

  • 4 weeks later...
Posted

I thought this was just what I was looking for, and it worked great, except I guess I need it for the product_info page instead, since there are attributes on all products in the store. How would I adapt this code for that page? Warning: I'm an newbie...

 

-jc

Posted
I thought this was just what I was looking for, and it worked great, except I guess I need it for the product_info page instead, since there are attributes on all products in the store. How would I adapt this code for that page? Warning: I'm an newbie...

 

-jc

Very easy contrib here. Just a matter of adding a couple bits of code.

 

In products_info.php. find:

 

<tr>
           <td class="main"><a href="<?php echo tep_href_link(FILENAME_PRODUCT_REVIEWS, substr(tep_get_all_get_params(), 0, -1)); ?>"><?php echo tep_image_button('button_reviews.gif', IMAGE_BUTTON_REVIEWS); ?></a></td>
           <td align="right" class="main"><?php echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></td>
         </tr>

 

and before it add:

 

<tr><td></td><td align="right" class="main">Quantity: <input type="text" name="quantity" value="1" maxlength="3" size="2"> </td></tr>

 

Then, in include/application_top.php, find:

 

$HTTP_POST_VARS['id']))+1

 

and replace it with

 

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

 

Back up first in case you make a mess but it really is easy.

 

BTW if anyone's interested, I have a thread going in contribs about the possibility of making a single order page, with all the products (and attributes) listed on one page, a little quantity box beside each one and a single "Place Order" button at the bottom of the page. So customers could place their entire oirder in one go - brilliant for stores with perhaps not so many products.

 

I have got it looking OK but it doesn't work so now I need people who know what they are talking about to come and help. I have ahd quite a few pms from peolpe who are interested in adding it when it's done.

 

http://www.oscommerce.com/forums/index.php?showtopic=73446

  • 3 months later...
Posted

This is exactly what I need but it doesn't work with MS2.2

 

Anyone know how to configure it to work with MS2.2?

 

Me too! I am sure it wouldn't take alot to adapt the code, my PHP skills are very limited

 

Thanks in advance if anybody takes the time to post it.

 

:D

Posted

braclark,

 

Thanks for your response, but we are looking for the ability to add a quantity box to the product_listing.php file, not the product_info.php page. We already have that established. If you have any suggestions I would love to hear them.

 

Thanks,

 

-Aaron

Posted

This Contribution will add a quantity box above your "Add to Cart" button in the Product Listing (product_listing.php) page. This module works for Version MS2.2 and may have bugs but it works perfectly on my end. If you have any enhancements or changes please feel free to make them at the Contribution site.

 

 

========================================

 

All you need to do is make the following simple changes:

 

1) in catalog/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>';

break;

}

 

 

 

replace with:

 

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="5" size="5"><br>' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</form>';

break;

}

 

 

 

 

2) in catalog/includes/application_top.php

 

find:

 

$HTTP_POST_VARS['id']))+1

 

 

replace with:

 

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

 

 

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

That's it. You're done!

Posted

Good try Royalfunk!

 

The quantity would probably make more sense at the left hand side enabling to put a header of quantity.

 

There is a bug in that if you have a look a the large description in product info then click ad to cart from there it does not put product in the cart.

 

Don't give up though.

Posted

Not sure of your setup but what it sounds like is that you just have your site set up a little differently as far as arrangement. Could you explain more about the "bug". I have this mod set up as well as numerous other Contributions and it works perfectly.

  • 1 month later...
Posted

Hi Royal Funk

 

Sorry for the delay in replying. Been away.

 

I am now going to test my memory as I have deleted the mod.

 

In the product list the quantity works fine and adds the qantity to the cart when you click

the button "Buy Now"

 

If you click on the product name then you get to the product info which has more info on the product this has a button called "ad to cart" if you put in the quantity here it does not transfer the quantity to the cart.

 

Hopes this makes sense.

 

This would be a very good mod to have.

Posted

Hay Acheron

 

Thanks alot! got the mod in and working.

 

A couple of comments if you want to ad more than 99 for the quantity it won't let you. This is particularly important to the site I slowley getting there with.

 

Also if you click on the product name which then takes you to the larger description is it possible to be able to enter the quantity in there as well.

 

I will try to do this myself.

 

Thanks again.

Posted

Found how change Acherons mod incase a you have a product that people will purchase in the hundreds, just change the

 

size=2 maxlength=2

 

to the amount of digits you require.

 

 

$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_buy_now.gif', IMAGE_BUTTON_IN_CART, 'align=absmiddle') . '</td></tr></table></form>';

Archived

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

×
×
  • Create New...