cylon2014 Posted January 11, 2014 Posted January 11, 2014 Hi, I'm trying to add an additional quantity box to my product info page - one at the top of the page and one at the bottom. Copying the code from the existing input box does not work. It adds the box correctly and adds to cart correctly, however the original box at the top of page only adds the product once regardless of how many I choose to add. Removing the second box fixes the problem. Is it possible to have more than one quantty box on the same page and can anyone advise of why I may be experiencing the problem Iam? Many Thanks in advance!
multimixer Posted January 11, 2014 Posted January 11, 2014 So you have 2 input boxes on the same page: A on the top and B at the bottom You enter a quantity of 8 to box A and press the add to cart. Result is, that only 1 item goes to cart Then you enter quantity of 8 to box B, press add to cart. Result is that 8 items go to cat. Is this the behaviour? Your 2 input boxes have the same "name", so they are "posting" a value using that same name. The form takes the latest value available and that is he one of the second box Imagine: What quantity should go to the cart if you enter 5 into box A and 7 into box B ? What you need to do is, to add some javascript and update the value of each input box, depending on the entry of the other box, so that both have the same value My community profile | Template system for osCommerce - New: Responsive | Feedback channel
cylon2014 Posted January 12, 2014 Author Posted January 12, 2014 Brilliant answer :) Any suggestions for the JS? Thanks
burt Posted January 12, 2014 Posted January 12, 2014 I would do this by making the input box a posted array (rather than a simple posted variable), then simply take the biggest value from that array. This has been covered in this forum in the past.
♥mattjt83 Posted January 12, 2014 Posted January 12, 2014 @@cylon2014 This is untested but should get you going in the right direction: <script> //rename input[name=quantity] to match your input name $(function(){ $("input[name=quantity]").blur(function(){ var this_value = $(this).val(); $("input[name=quantity]").val(this_value); }); }); </script> Matt
♥mattjt83 Posted January 12, 2014 Posted January 12, 2014 @@cylon2014 Something along the lines of what @@burt suggested.... This assumes you have named your qty box quantity in your product_info.php page includes/application_top.php // customer adds a product from the products page case 'add_product' : if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) { $attributes = isset($HTTP_POST_VARS['id']) ? $HTTP_POST_VARS['id'] : ''; $quantity = isset($_POST['quantity']) ? max($_POST['quantity']) : 1; $cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $attributes))+$quantity, $attributes); } tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters))); break; catalog/product_info.php -- repeat input code as needed echo tep_draw_input_field('quantity[]', '1'); Matt
Recommended Posts
Archived
This topic is now archived and is closed to further replies.