Totally Zenned
- Join Date:
- Jan 2007
- Posts:
- 1,514
- Plugin Contributions:
- 1
need coding help, please! Very small non-Zencart project for a friend, almost there!
I need a little help on a non-zencart coding project for a friend. He's installing this on his church's website so they can sell downloads of some of their choir's music. My love of zencart has led me to get bitten by the Coder Bug and now I'm learning PHP and MySQL, among other things, on a daily basis with various books. So I thought that this little project of my friend's would be a great exercise for my fledgling coding skills. But I am still at a level too low to completely figure it out and need a little instruction. I have spent hours reading through the paypal docs and trying various ways to get this to work, all to no avail.
Could I ask for some PHP coding help?
I have attached a zip with the files in. The folder labelled "current" is the original files and the one labelled "new" has the ones I have started working on.
Basically, this little app is to allow for automatic downloading of digital files once payment has gone through Paypal IPN. There is a simple admin interface to allow you to enter names and prices of a product and then browse through your computer for the file to upload. You upload it to a directory called "myfiles". It sends an email to the customer once notification is returned from Paypal that the checkout has gone through, and the email contains a link to the purchased downloads that are retrieved from the "myfiles" directory. Originally, the app was set up for the Paypal "x-click" type of button, which is for a single item purchase, and it works as it should.
What I am trying to do is to use the "_cart" button, to allow the customer to add multiple items to a Paypal cart before checkout. So I need to change the ipn.php file to recognise the "num_cart_items" variable returned from Paypal, which I have done.
$num_cart_items = $_POST['num_cart_items'];
Then as it does the check of the item name and price to the values in the database to confirm that the variables returned match the database values, I have inserted a for loop to loop through all of the cart items being returned.
for ($i = 0; $i <= $num_cart_items; $i++) {
$x=$i+1;
$item_name = "item_name".$x;
}
But from there, I am not quite sure what to do next. I have tried some things but nothing has worked. This is the validation part:
$checkquery = "SELECT * FROM files WHERE paypalname = '$item_name'";
$checkresult = mysql_query($checkquery);
$checkrow=mysql_fetch_assoc($checkresult);
$price = $checkrow["price"];
$filename = $checkrow["filename"];
What has to happen next is all of the cart items are added to the email sent to the customer, and then the send_url.php file verifies that the link is valid and allows the customer to download the file. So, the code needs to take all of the items that are created from the for loop, run it through the validation, generate an md5 link and then add it to the email.
if ($price == $amount)
{
//send email to buyer
$random = rand();
$string = md5($random);
$query = "INSERT INTO links (getfilename, link, dltimes) VALUES ('$filename', '$string', '3')";
mysql_query($query);
mysql_close($connect);
$to = $payer_email;
$subject = $storename . " Order";
$body = "Your download [URL="http://www.zen-cart.com/forum/\n"]url:\n[/URL]" . $scriptpath . "send_url.php?q=" . $string . "\n\nIf you cannot download, please contact us at " . $email . ".";
Please, can you help me to figure it out? I am sure that for someone versed in PHP and MySql this would take like 5 minutes. It would really help me to understand how to figure out the logic of the actions that need to be done and then to code that logic accordingly.
I'm unclear as to what happens in the for loop. Are the variables created in it stored there in the script? Do I need to specifiy a new variable to contain all of the cart items? Or an array? Or do I do something else? And then how do I get all of the cart items to go through the validation and then have a link created? And what, if anything, do I need to do in send_url.php to allow it to run through all links in the email as they are clicked? I'm not quite sure how that all works.
Thanks!
Matt