The Interface
Quick Start Guide
Creating Pages
Opening and Editing Pages
Uploading and Managing Files
Menu Display System
Site Templates
Shopping Cart & eCommerce
Event Calendar
eNewsletter Module
Database Table Manager
Secure Users
Site Data Tables
Photo Album
Site Statistics
Blog Manager
Webmaster Menu
Custom Web Forms
Custom PHP Includes
Programming structure
Custom HTML and PHP within the Page Editor
Custom Shipping Include
Custom Gateway Included
Custom Invoice Include
Custom Template Include
Custom Detail Page Include
Resources for Help
Search Engine Optimization
Useful Web Resources
Default Style Sheet File
Built-In Javascript Functions
Frequently Asked Questions (FAQs)
Online Users Manual Search Manual for:  
Custom PHP Includes
Custom Invoice Include

The invoice include is designed to allow custom scripts to run at the point in which your shopping cart customer views/receives their final invoice to the screen. This takes place after any credit card information has been taken and processed. This include was made possible to allow the most flexibility in delivery products and services to your customer.

For this example, we are going to use the following scenario:
Our client wishes to have content and shopping cart items only available to “authorized members” of their “online club”. This is easily handles via the Pro Edition’s “Page/Product Security” module. However, our client does not wish to manage all of his/her fifty-thousand members by hand. In addition, our client requires a membership fee of $50.00 per year to access the membership content.

So, what does our Invoice Include need to accomplish to make this scenario a reality? First, we need to build a “Public” product SKU that represents the membership payment of $50.00. This is simply accomplished through the normal Pro Edition interface. Then, we must set up a security code or group by which our membership will be associated and assign all “member only” content to that security code (group). This is also accomplished through the normal Pro Edition interface. Since our client wants this to be automated, it is going to require a SSL certificate for security and some type of gateway to accept credit cards online in real-time. The gateway is important because we want to insure our customer has paid for his/her membership before we give them access to the membership area.

Now for the actual include. Our include needs to detect whether or not the actual SKU Number purchased is in fact the “membership fee” SKU. If so, we need to generate a unique username and password, store that information in the “sec_users” data table and deliver that information to the customer on their final invoice and email receipt. Remember, we have over 1000 other products in our shopping cart and we only wish to generate membership data with the purchase of the “membership” SKU number.

Let’s figure our what variable data we are going to need in order to accomplish this and what data is available to us. At this point in the checkout process our session data is basically gone. The order information has been data based, the shopping cart session variables are no longer registered and the invoice HTML is simply being displayed from a BLOB in a database field. If you remember from the last exercise, we have generated and passed back an invoice number that represents the Primary Key field of this order in the “cart_invoice” data table.

Therefore, the only variable that we need to be concerned with is the $ORDER_NUMBER variable (which is the invoice number). Using this number, we can access the “cart_invoice” database table and extract the data we need to determine if our membership sku has been purchased or not. If so, we can generate a random username and password at that point. It is really unimportant what format this information is created in at purchase because we should encourage the customer to change their username and password information when they login the first time anyway. And guess what? They can do this using the built-in “Secure Auth” object from the Pro Edition.

Let’s write the script:

<?PHP

##################################################
### MEMBERSHIP GENERATION SCRIPT
### AUTHORED BY: MIKE JOHNSTON
###
###
### NOTE: We have set up a sku in the shopping
### cart called "MEMBERSKU" and created a security
### code (group) called "members".
###################################################

// Let's get this order's data from our data table
// -----------------------------------------------

$inv_lookup = mysql_query("SELECT * FROM cart_invoice WHERE
ORDER_NUMBER = '$ORDER_NUMBER'");

$this_data = mysql_fetch_array($inv_lookup);

// Assign value to our current invoice data
// -----------------------------------------------

$inv_data = $this_data[INVOICE_HTML];

// Assign variable to this customers email address
// and other needed data for the sec auth system.
// In this routine we also want to use their email
// address as their username, so go ahead and
// assign that just in case
// -----------------------------------------------

$MEMBER_USERNAME = $this_data[BILLTO_EMAILADDR];

$MEMBER_FN = $this_data[BILLTO_FIRSTNAME];
$MEMBER_LN = $this_data[BILLTO_LASTNAME];

$MEMBER_OWNER = $MEMBER_FN . " " . $MEMBER_LN;

// Has our sku number been purchased?
// -----------------------------------------------

$PURCHASE_FLAG = 0; // NO (first assumption)

if (eregi("MEMBERSKU", $inv_data)) {
$PURCHASE_FLAG = 1; // YES (found sku in this order)
}

// If we found the sku, let's generate a username
// and password; database it and display it to
// our customer now
// -----------------------------------------------

if ($PURCHASE_FLAG != 0) {

// We already have a username with their email
// address, so let's create a new password
// Our password routine will combine their
// email address, order_number and today's date into an
// md5() string. We will recommend they
// change this "huge" password once logged
// in the first time.
// --------------------------------------------

$tDate = date("ymdgia"); // Todays date & this time stamp
$tmp = $MEMBERSHIP_USERNAME . $tDate . $ORDER_NUMBER;
$MEMBERSHIP_PASSWORD = md5($tmp);

// Let's setup our automated variables that we
// will need to make this customer a member
// In this example, we have no expiration date
// on the membership, but this is where you
// would set it
// --------------------------------------------

$EXPIRATION_DATE = "0000-00-00";
$REDIRECT_PAGE = "Members"; // After login send to this page
$SEC_GROUPS = "members";

// Now that we have generated the password, let's
// save it to the sec_users table so our auth
// system will recognize them.
// ---------------------------------------------

mysql_query("INSERT INTO sec_users(OWNER_NAME,OWNER_EMAIL,USERNAME,PASSWORD,
REDIRECT_PAGE,GROUPS,EXPIRATION_DATE) VALUES('$MEMBER_OWNER',
'$MEMBER_USERNAME','$MEMBER_USERNAME','$MEMBER_PASSWORD',
'$REDIRECT_PAGE','$SEC_GROUPS','$EXPIRATION_DATE')");

// Ok, Member logged, display this information
// on the invoice output now...
// ----------------------------------------------

$THIS_DISPLAY .= "<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=0
WIDTH=100% CLASS=text>\n";
$THIS_DISPLAY .= "<TR><TD ALIGN=LEFT VALIGN=TOP class=text>\n";
$THIS_DISPLAY .= "Your New Membership Login Information is:<BR><BR>\n";
$THIS_DISPLAY .= "Username: $MEMBER_USERNAME<BR>\n";
$THIS_DISPLAY .= "Password: $MEMBER_PASSWORD<BR><BR>\n";
$THIS_DISPLAY .= "We recommend that you change your password after
logging in the first time.";
$THIS_DISPLAY .= "</TD></TR></TABLE><BR>\n";

} // End Purchase Flag NOT equal to 0
?>