Only pass products to cart if quantity is greater than zero

Mitch19851
Contributor
Contributor

Hi Guys,

 

I have a simple Paypal _cart with around 5 products each with a quantity, I want my users to be able to enter the quantity next to each product they would like.

 

It's all working fine, however when I choose checkout/buy now it adds the products with an empty quantity and puts a quantity of 1.

 

Please please help guys I am so close with this...

 

An example product coding below:

 

<form name="_self" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">

<input type="hidden" name="item_name_2" value="Building User Guide">
<input size="2" type="text" name="quantity_2"><font size="2"><strong>Quantity</font>
<input type="hidden" name="amount_2" value="18.00">

 

Thanks.

 

 

Login to Me Too
5 REPLIES 5

MTS_Andre
Moderator
Moderator

Hi Mitch19851, you need to add few variables like the return URL and business (which I don't see on your example) but you could run something like this and it will add the quantity specified in your textbox (just replace the business variable with your account email):

 

<form name="_self" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="YourPayPalAccount@yourDomain.com">
<input type="hidden" name="add" value="1">

<input size="2" type="text" name="quantity"><font size="2"><strong>Quantity</font>
<input type="hidden" name="amount" value="0.10">
<input type="hidden" name="item_name" value="Building User Guide">
<input type="hidden" name="item_number" value="18">

<input type="hidden" name="return" value="https://developer.paypal.com">
<input type="hidden" name="cancel_return" value="https://www.mystore.com/cancel">

<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted">
<input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

Login to Me Too

Mitch19851
Contributor
Contributor

Hi thanks so much for the reply.

 

I do have all this setup, apologies I only posted part of the code.

 

My question is when quantity_1 is 0 and quantity_2 is 1

 

Once the buy now is clicked it adds a quantity of 1 for both items, I only want it to add to the cart if it has a quantity greater than 0

 

Hope this makes sense.

Login to Me Too

MTS_Andre
Moderator
Moderator

Ok, usually if the quantity is 0 it will not be considered but if you can share the full code of your button (just cover the business variable) I can run a test.

Login to Me Too

Mitch19851
Contributor
Contributor

Ok, here it is...I do have many more products but this will make sense hopefully.

 

If I choose "pay now/view cart" and leave the quantities blank it will add 1 of each as standard to the cart.

 

<form name="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="cpp_header_image" value="image address">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="email address">
<input type="hidden" name="currency_code" value="GBP">

 

<input type="hidden" name="item_name_1" value="Small touch point labels x 100">
<input size="2" type="text" name="quantity_1"><font size="2"><strong>Quantity</font>
<input type="hidden" name="amount_1" value="9.60">

<br>
<input type="hidden" name="item_name_2" value="Large touch point labels x 100">
<input size="2" type="text" name="quantity_2"><font size="2"><strong>Quantity</font>
<input type="hidden" name="amount_2" value="24.00">

 

<input type='hidden' name='cancel_return' value='site address/paymentcancel.php'>
<input type='hidden' name='return' value='site address/paymentthanks.php'>
<input type="hidden" name="bn" value="PP-ShopCartBF">
<input type="image" src="site address/paybutton.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">

 

Thanks so much in advance for your time here.

Login to Me Too

MTS_Andre
Moderator
Moderator

Hi Mitch, I did some testing but the workaround you can eventually use is to create 2 Add to Cart - ADD buttons, one for each item and once the user click one of them will see the PayPal cart summary page where can increase / decrease the quantities as needed. Below is an example of what I mean. Using the button you were testing (Add to cart - UPLOAD) I can't see the possibility to send a specific quantity to the cart.

 

<form name="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="hidden" name="business" value="BUSINESS_ACCT"
<input type="hidden" name="currency_code" value="GBP">

<input type="hidden" name="item_name" value="Small touch point labels x 100">Small x 100
<!-- <input size="2" type="text" name="quantity"><font size="2"><strong>Quantity</font> -->
<input type="hidden" name="amount" value="9.60">

<input type="hidden" name="return" value="https://developer.paypal.com">
<input type="hidden" name="cancel_return" value="https://www.mystore.com/cancel">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted">
<input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

<br><br>

<form name="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="hidden" name="business" value="BUSINESS_ACCT">
<input type="hidden" name="currency_code" value="GBP">

<input type="hidden" name="item_name" value="Large touch point labels x 100">Large x 100
<!-- <input size="2" type="text" name="quantity"><font size="2"><strong>Quantity</font> -->
<input type="hidden" name="amount" value="24.00">

<input type="hidden" name="return" value="https://developer.paypal.com">
<input type="hidden" name="cancel_return" value="https://www.mystore.com/cancel">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted">
<input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.