Guest Posted June 29, 2004 Posted June 29, 2004 Hi, This is my first attempt at creating a contribution for Oscommerce, techincally it's my first independent PHP program , so bear with me.. This contribution is intended to send customers an email containing log in infomation that can be used with software they download automatically upon checkout. I believe i am done writting the code for the core of the program (Quoted below) , but i have a few questions: 1- How would i link this file to the checkout process ? (I.e How would i have oscommerce excute this php script upon checkout_sucess.php is validated) 2-I need the checkout_sucess script to pass the orderID$ to this php script, how would i go about that ? Below is the code for this contirbution, if any one spots any syntax errors (i'm sure there's plenty), i'd also be grateful for input Thank you very much for your input and time. <?php // To do // Fix validate order function -- DONE // Fix get log -- DONE // Fix email log -- DONE global $orderID ; // Set debug vairable to false $completed=FALSE; if (validateorder($orderID)){ // Make sure order is valid before we proceed chooseproduct($productID); readcodes($DB_Table); sendcodes($userID,$password,$emailFile,$customerEmail,$productName); $completed = TRUE; // Debug variable set to true once we finish everything successfully. } // if order is invalid reject request or file is accessed manually else{ print <<<HERE <h1> Invalid order info</h1> <p> Please submit valid order info or order to recieve login information </p> HERE; die; } function validateorder($orderid) { global $customerEmail, $productID, $productName; // Connect to OSC DB $conn=mysql_connect("localhost","xxxxx","xxxxx"); if (!mysql_select_db("xxxxx", $conn)){ print "Unable to connect to DB please try again later"; end; } // Validate order and get productID $sql = "SELECT * FROM orders_products WHERE orderid = '$orderid'"; $result= mysql_query($sql,$conn); if (!result == FALSE){ return FALSE; } else{ $orderdetails= mysql_fetch_assoc($result); $productID = $orderdetails["products_id"]; $productName =$orderdetails["products_name"]; } // Now connect to Orders table to get customer email $sql = "SELECT * FROM orders WHERE orderid = '$orderid'"; $result= mysql_query($sql,$conn); $details= mysql_fetch_assoc($result); $customerEmail=$details["customers_email_address"]; return TRUE; // Order does exist } function readcodes($DB_Table) { global $userID, $password; //Connect to DB $conn=mysql_connect("localhost","xxxxx","xxxxx"); if (!mysql_select_db("xxxxxxx", $conn)){ print "Unable to connect to DB please try again later"; end; } $sql = "SELECT * FROM ". $DB_Table. " WHERE used = 0"; $result = mysql_query($sql,$conn); // Get one log row $row = mysql_fetch_assoc($result); list($lognumber,$userID,$password,$used,$order,$completed)= $row; // Update DB log used $sql=<<<HERE UPDATE unlocklogs SET used='1' order='$orderid' completed='1' WHERE id='$lognumber' <<<HERE; mysql_query($sql,$conn); // Do update } function chooseproduct($productID) { global $emailFile,$DB_Table; switch($productID){ case 32: $emailFile="xxxxx"; $DB_Table="xxxx"; break; case 34: $emailFile="xxxxx"; $DB_Table="xxxx"; break; case 35: $emailFile="xxxxx" $DB_Table="xxxxx"; break; default: print "Invalid Product Id passed"; die; } } function sendcodes($userID,$password,$emailFile,$customerEmail,$productName) { // Get product email and Replace fields with data chdir("xxxx"); $dirPtr=openDir("xxxx"); $fp = fopen($emailFile,"r"); $email = file($fp); foreach ($email ad $currentline){ $currentline = str_replace("***||customerName||***",$customerName,$currentline); $currentline = str_replace("***||userID||***",$usedID,$currentline); $currentline = str_replace("***||password||***",$usedID,$currentline); $productEmail .= rtrim($currentline) . "<br>\n"; } // Finally email the customer his instructions mail($customerEmail,$productTitle,$productEmail); fclose($fp); } ?> Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.