Full-service Internet Marketing & Web Development
Recent Posts

Sponsors
![]() |
How to access SPI Shopping Cart variablesMike Peters, 10-31-2008 |
Unlike other solutions, the SoftwareProjects shopping cart front-end runs on your server (so that you can customize everything) while the back-end processing runs in SPI's robust data centers.
Understanding this architecture is key to learning how to access shopping cart run time variables, such as Order ID, customer shipping information, Order total etc.
Since the front-end runs on your server, you can access all run time variables by simply examining the return values of the cart's do_checkout, do_backgroundcheckout, do_getcustomerorders and do_getcustomerinformation methods.
As part of this post, I will provide you with step-by-step instructions for a couple of popular scenarios.
How to display Order ID and Order Total on thank you page
The Order ID is returned when calling do_checkout and do_backgroundcheckout. Every order in the system is going to get a unique ID assigned to it.
Step 1: Find the call to do_checkout (typically done on your main screen or checkout page).
You should find a block of code that looks like this:
// If submitted order for processing
if (Strcasecmp($HTTP_POST_VARS['action'],'checkout')==0)
{
$input = array();
$input['store_id'] = 2;
$input['product_codename'] = $product_codename;
// Checkout
if (do_checkout($input, &$output, &$ResultStr))
{
// If successful, redirect
Header("Location: thankyou.php?order_id=".$output['order_id']);
return;
}
}
Notice in the example above, the order_id returned by do_checkout is immediately passed to the thankyou.php page as an HTTP_GET parameter.
If you have multiple pages to your sales cycle and you're looking to make the main Order ID available to the thankyou page (which is a few pages later in the process), you're going to have to store the Order ID.
The easiest way to do this is by using a cookie.
Add a call to setcookie() to store Order ID as a cookie, prior to redirecting the user to the next step of the process.
Example:
// If submitted order for processing
if (Strcasecmp($HTTP_POST_VARS['action'],'checkout')==0)
{
$input = array();
$input['store_id'] = 2;
$input['product_codename'] = $product_codename;
// Checkout
if (do_checkout($input, &$output, &$ResultStr))
{
// Save Order ID as a cookie so that we can access it later
$order_id = $output['order_id'];
setcookie("order_id", $order_id, time()+3600*24*7,"/");
// If successful, redirect
Header("Location: step2.php);
return;
}
}
Once the Order ID is saved as a cookie, you can easily access it on the thank you page.
Here's an example of how you would populate a PepperJam network tracking script with the order ID:
<img src="http://www.pepperjamnetwork.com/tracking/trackmerchant.php?PID=1977&AMOUNT=0&TYPE=2&OID=<?=$_COOKIE['order_id']?>&CURRENCY=USD"
height="1" width="1" border="0" />
You can use the same approach for storing the order amount.
How to display customer name and emailaddress on the thank you page
The customer name, shipping address and shipping method are also returned by do_checkout.
You can use a similar method as the one described above, storing the pieces of information you need (such as: customer name) in a cookie, so that they are accessible by other pages in your sales process.
Another approach you can use is a function called do_getcustomerinformation.
Once you have the Order ID, you can pass the Order ID to this function and receive all customer information related to this order.
For example on your thank you page, you can use the code below to display Hi FirstName:
// Use "Customer" as the default first name in case we don't have a valid Order ID
$firstname = "Customer";
// Fetch customer information from the database
$input = array();
$input['order_id'] = $order_id;
// Checkout
if (do_getcustomer($input, &$output, &$ResultStr))
{
// Set first name
$firstname = $output['firstname'];
}
// Display greeting
echo "Hello $firstname,";
Understanding this architecture is key to learning how to access shopping cart run time variables, such as Order ID, customer shipping information, Order total etc.
Since the front-end runs on your server, you can access all run time variables by simply examining the return values of the cart's do_checkout, do_backgroundcheckout, do_getcustomerorders and do_getcustomerinformation methods.
As part of this post, I will provide you with step-by-step instructions for a couple of popular scenarios.
How to display Order ID and Order Total on thank you page
The Order ID is returned when calling do_checkout and do_backgroundcheckout. Every order in the system is going to get a unique ID assigned to it.
Step 1: Find the call to do_checkout (typically done on your main screen or checkout page).
You should find a block of code that looks like this:
// If submitted order for processing
if (Strcasecmp($HTTP_POST_VARS['action'],'checkout')==0)
{
$input = array();
$input['store_id'] = 2;
$input['product_codename'] = $product_codename;
// Checkout
if (do_checkout($input, &$output, &$ResultStr))
{
// If successful, redirect
Header("Location: thankyou.php?order_id=".$output['order_id']);
return;
}
}
Notice in the example above, the order_id returned by do_checkout is immediately passed to the thankyou.php page as an HTTP_GET parameter.
If you have multiple pages to your sales cycle and you're looking to make the main Order ID available to the thankyou page (which is a few pages later in the process), you're going to have to store the Order ID.
The easiest way to do this is by using a cookie.
Add a call to setcookie() to store Order ID as a cookie, prior to redirecting the user to the next step of the process.
Example:
// If submitted order for processing
if (Strcasecmp($HTTP_POST_VARS['action'],'checkout')==0)
{
$input = array();
$input['store_id'] = 2;
$input['product_codename'] = $product_codename;
// Checkout
if (do_checkout($input, &$output, &$ResultStr))
{
// Save Order ID as a cookie so that we can access it later
$order_id = $output['order_id'];
setcookie("order_id", $order_id, time()+3600*24*7,"/");
// If successful, redirect
Header("Location: step2.php);
return;
}
}
Once the Order ID is saved as a cookie, you can easily access it on the thank you page.
Here's an example of how you would populate a PepperJam network tracking script with the order ID:
<img src="http://www.pepperjamnetwork.com/tracking/trackmerchant.php?PID=1977&AMOUNT=0&TYPE=2&OID=<?=$_COOKIE['order_id']?>&CURRENCY=USD"
height="1" width="1" border="0" />
You can use the same approach for storing the order amount.
How to display customer name and emailaddress on the thank you page
The customer name, shipping address and shipping method are also returned by do_checkout.
You can use a similar method as the one described above, storing the pieces of information you need (such as: customer name) in a cookie, so that they are accessible by other pages in your sales process.
Another approach you can use is a function called do_getcustomerinformation.
Once you have the Order ID, you can pass the Order ID to this function and receive all customer information related to this order.
For example on your thank you page, you can use the code below to display Hi FirstName:
// Use "Customer" as the default first name in case we don't have a valid Order ID
$firstname = "Customer";
// Fetch customer information from the database
$input = array();
$input['order_id'] = $order_id;
// Checkout
if (do_getcustomer($input, &$output, &$ResultStr))
{
// Set first name
$firstname = $output['firstname'];
}
// Display greeting
echo "Hello $firstname,";
|
|
Subscribe Now to receive new posts via Email as soon as they come out.
Comments
Post your comments
