wizardsandwars Posted January 2, 2003 Share Posted January 2, 2003 I'd like for soneone in the know to take a quick gander at it. It is a script that will email all customers that sign up, but do not order, and that are not online presently, with a quick little 'feedback request'. It has the capibility, with a little additional code to restrict emails further to just customer that meet that above criteria, and who placed an item in their cart. It will need to be scheduled in cron, or winat. It uses a static file to keep track of what customers have been emailed already. I place the static file in the document root. It will need 2 defines somewhere, I put them in create_account_process.php. Like I said, this script is not quite ready for production. I just need someone to give it a quick once over, to make sure all of the logic is correct, although I tested it pretty throughly. If everything looks good, I'll package it up wit hfull installation instructions, and add it to the contributions section tomorrow. Here's the script. PLEASE let me know what you think. <?php require("includes/application_top.php"); require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CREATE_ACCOUNT_PROCESS); $datafile="/home/wizardsa/data.txt"; // Get the static customer ID where we left off the last time this script ran $fd = fopen ("$datafile", "r"); while (!feof ($fd)) { $buffer = fgets($fd, 4096); if($buffer){$num=$buffer;} } fclose ($fd); // If this is the first time running, we want to set the static variable to the highest customer_id if(!$num){ $max_id_query_raw = "SELECT max(customers_id) as customers_id FROM customers"; $max_id_query = tep_db_query($max_id_query_raw); while ($max_id_array = tep_db_fetch_array($max_id_query)) {$max_id = $max_id_array['customers_id'];} } else { // Get NEW customers info that are not currently online, [OPTIONAL: We could add "and that have left items in cart" by adding to the where clause here] $customers_query_raw = "SELECT customers.customers_id, customers.customers_firstname, customers.customers_email_address FROM customers LEFT JOIN whos_online ON customers.customers_id = whos_online.customer_id WHERE whos_online.customer_id IS NULL and customers_id > $num ORDER BY customers.customers_id"; $customers_query = tep_db_query($customers_query_raw); while ($customers = tep_db_fetch_array($customers_query)) { $max_id=$customers['customers_id']; tep_mail('', $customers['customers_email_address'], EMAIL_FOLLOWUP_SUBJECT, "Hello ".$customers['customers_firstname'] ."," . FOLLOWUP_EMAIL_TEXT, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, ''); } } // If we found customers to email, or this is the first time running this script, we need to update our static file if ($max_id){ if (is_writable("$datafile")) { if (!$fp = fopen($datafile, 'w')) { print "Cannot open file ($datafile)"; exit; } // Write $static to our opened file. if (!fputs($fp, "$max_id")) { print "Cannot write to file ($datafile)"; exit; } fclose($fp); } else { print "The file $datafile is not writable"; } } ?> Quote ------------------------------------------------------------------------------------------------------------------------- NOTE: As of Oct 2006, I'm not as active in this forum as I used to be, but I still work with osC quite a bit. If you have a question about any of my posts here, your best bet is to contact me though either Email or PM in my profile, and I'll be happy to help. Link to comment Share on other sites More sharing options...
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.