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($_POST['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 either store the Order ID in a cookie, or use do_getcustomerorders().
Here's how to store the Order ID 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.
// 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.
How to display customer name and order information
You can use a similar method as the one described above, storing the pieces of information returned by do_checkout() in a cookie, so that they are accessible by other pages in your sales process.
A cleaner approach is to use do_getcustomerorders() which returns all orders for the currently logged-in customer.
// Fetch customer information
$input = array();
do_getcustomer($input, &$customer, &$ResultStr);
// Fetch a list of all orders for the current customer
$input = array();
do_getcustomerorders($input, &$orders, &$ResultStr);
// Display greeting
echo "Hello ".$customer['firstname'].",<BR><BR>";
// Display order information
echo "Thank you for ordering from us today<BR><BR>";
foreach ($orders as $order)
{
echo "<li> ".$order['name'].' $'.$order['total']."<BR>";
}
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($_POST['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 either store the Order ID in a cookie, or use do_getcustomerorders().
Here's how to store the Order ID 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.
// 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.
How to display customer name and order information
You can use a similar method as the one described above, storing the pieces of information returned by do_checkout() in a cookie, so that they are accessible by other pages in your sales process.
A cleaner approach is to use do_getcustomerorders() which returns all orders for the currently logged-in customer.
// Fetch customer information
$input = array();
do_getcustomer($input, &$customer, &$ResultStr);
// Fetch a list of all orders for the current customer
$input = array();
do_getcustomerorders($input, &$orders, &$ResultStr);
// Display greeting
echo "Hello ".$customer['firstname'].",<BR><BR>";
// Display order information
echo "Thank you for ordering from us today<BR><BR>";
foreach ($orders as $order)
{
echo "<li> ".$order['name'].' $'.$order['total']."<BR>";
}
|
|
Subscribe Now to receive new posts via Email as soon as they come out.
Comments
Post your comments
