Quantity Box in Product Listing v1.0
by Aaron Hiatt
aaron@scaredrabbit.com
========================================
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 here 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!
Legend: 
Download

Report
With the newest version of OSC, it's really easy to add a quantity box and change the "buy now" button to an add to cart button. This allows your customer to add 1,2,3... of the same item to their cart with one click of the "add to cart" button. I don't know exactly how old version 1 is but here is all you have to do.
in catalogincludesmodulesproduct_listing
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_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</a> ';
break;
}
Replace with
case 'PRODUCT_LIST_BUY_NOW':
$lc_align = 'center';
$lc_text = '<form name="cart_quantity" method="post" action="' . tep_href_link(basename($PHP_SELF), 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;
}
That's it. You're done. Enjoy.
This code worked for me... This one does not use the dropdown menú.
product_listing.php
Replace this:
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;
}
with:
case 'PRODUCT_LIST_BUY_NOW':
$lc_align = 'center';
$lc_text = '<form name="cart_quantity" method="post" action="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $listing['products_id']) . '"><input type="hidden" name="products_id" value="' . $listing[$x]['products_id'] . '"><input type="text" name="quantity" value="1" maxlength="5" size="5"> ' . tep_image_submit('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</form>';
break;
In application_top.php
Replace this:
$HTTP_POST_VARS['id']))+1
with:
$HTTP_POST_VARS['id'])) + $HTTP_POST_VARS['quantity']
I used a button different than the one used by the contribution creator as it was better for my own use.
Hope it helps anyone.
The archive does not contain nothing.
Thanks for this contribution it helps a lot but when I try to add additional quantity on the product it will not add in the quantity in shopping cart.
First, I add in the cart and choose the quantity 10 in the drop down quantity box and the quantity is added in the shopping cart.
Second I back to product listing or in product info and try to add additional quantity 20 for the product and the results is that the quantity change to the new quantity I choose, instead the quantity must add the new quantity e.g. 10+20=30 the quantity must be 30 not 20. Is there any way to solve the problem and thanks a lot.
*** Modified by DuFF1 to include dropdown box to select quantity in product_info***
If you want send form with quantity to product_listing.php as it's used in original file product_listing.php, use you
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(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $listing['products_id']) . '"><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
(as used Aaron)
find:
$HTTP_POST_VARS['id']))+1
replace with:
$HTTP_POST_VARS['id']))+$quantity
3) in /catalog/product_info.php
(or the root dir of wherever you installed osc)
find:
<td class="main" align="right"><?php echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></td>
replace with:
<td class="main" align="right"><?php echo '<b> Qty :</b> <select name="quantity" size="1"><option value="1" selected>1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option></select> ' . tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></td>
If you want send form with quantity to product_listing.php as it's used in original file product_listing.php, use you
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(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $listing['products_id']) . '"><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
(as used Aaron)
find:
$HTTP_POST_VARS['id']))+1
replace with:
$HTTP_POST_VARS['id']))+$quantity
this solution writing again product_listing.php and no product info.
Please excuse me, as this is my -very- first bit of PHP tweaking, but I discovered a way to use this same code to put a quantity box on the Product Info page as well.
Just open:
/catalog/product_info.php
(or the root dir of wherever you installed osc)
and where it says:
<td class="main" align="right"><?php echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></td>
simply insert a snippet of code from this contribution so it looks like:
<td class="main" align="right"><?php echo '<b>Qty:</b> <input type="text" name="quantity" value="1" maxlength="5" size="5">' . tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></td>
Important: You must have this contribution already installed for this to work! The attached zip does NOT include the original contribution, only my bit.
Please test this after backing up your system, and forgive me for bugs. I have tested it thoroughly on my installation and it works well, but again... PHP is very new to me.
Thank you and take care.
~Kyr
Quantity Box in Product Listing v1.0
by Aaron Hiatt
aaron@scaredrabbit.com
========================================
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 here 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!