Paypal IPN Script - Multiple Products from One Form

Starting with version 4.2 my Paypal IPN script now allows you to set up one purchase form to allow for the purchase of multiple products at once. There are a number of things you have to do to set this up.

To make it easier to explain how this all works we'll imagine that there are three products A, B, and C.

  1. If you are emailing the purchased product then the first step is to create zip files that contain each combination. So as well as A.zip, B.zip, and C.zip (or whatever those files are called since the files don't have to be named the same as the product codes) we also need AB.zip, AC.zip, BC.zip, and ABC.zip (again using whatever names you like but containing those product combinations).
  2. Next you need to create the combination product entries in the product table ($pa[] if you are using the basic script or in the database if you have the database extensions as well). These combination product codes will attach the corresponding combination zip files if you are going to be emailing the products.
  3. The final step is to update the form to include checkboxes instead of a hidden field or radio buttons.

So for this last step we delete the line that reads:

<input type="hidden" name="prod" value="A">

That now gets replaced with checkboxes so that the appropriate combination of products can be seleted.

<input type="checkbox" name="prods[]" value="A">

You would of course have a checkbox with the value for each product that can be purchased in combination so for our example we'd have two further checkboxes for products B and C.

Now the form will pass a prods[] array instead of the single prod field when it is submitted. The prods array will contain all of the checked values from the form. The code for the paypal.php and paypal1.php scripts were updated in version 4.2 so that if a prods[] array is received then the prod field is generated by imploding the array. What this means is that if the A and C checkboxes are checked and the B checkbox isn't then the product code ends up being AC. Since you created that product and added it to the product table in steps one and two the same processing for the rest of the product purchase can take place as if a single product were selected (since as far as the rest of the script is concerned this is a single product).

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate