retaining additional variables
In addition to the usual variables for the product ID and quantity that we include in our QuickCode Tag, we want to include several more and have them available for use on our checkout pages. Is there a way to pass these additional variables, and have them retained?
For demonstration purposes, let's say that the goal is to create an "Add to Cart" link that adds 1 unit of product SID 311 to the cart and include two additional variables, referrer_id and checksum. The store should retain the values for referrer_id and checksum, so that they're available for reference by code on the checkout page.
The first question is, "can this be accomplished by using a standard QuickCheckout "Add to Cart" link like this?"
code http://www.my-store.com/quick_checkout.php?id1=311&qty1=1&referrer_id=007&checksum=ABC
The answer to that question is "no, that approach would not work."
So, the second question is, "okay, smart guy, then how would it be accomplished?"
Here's how:
This would be accomplished by adding a page before the call to quick_checkout.php, which we'll call new_page.php. This new_page.php would first save the additional variables in the desired location (such in the session, cookies, database, etc.) and then forward the user on to the QuickCheckout page.
For example, the URL above would be changed to something like this:
code http://www.my-store.com/new_page.php?id1=311&qty1=1&referrer_id=007&checksum=ABC
The new_page.php file may contain code similar to:
code <?php
//Start the PHP session.
session_start();
//Save the incoming variables in session memory.
$_SESSION["referrer_id"] = $_REQUEST["referrer_id"];
$_SESSION["checksum"] = $_REQUEST["checksum"];
//Wrap things up and redirect to the checkout area...
session_write_close();
header("location: http://www.my-store.com/quick_checkout.php?id1=311&qty1=1");
exit();
?>
The new_page.php file could also be written to save the incoming variables in cookies, in a database, or whatever other imaginative things you come up with.
tip
To ensure that the session and/or cookie variables are accessible by the store's checkout page, new_page.php would need to be on the same website as the quick_checkout.php page.
By putting both on the same website, the two pages will share to the same session and cookie variables, allowing one page to access data saved by the other.
The additional variables would then be accessible for use or display on the checkout page. The storefront's checkout template could then display these variables by using code like this:
code <?php
echo("Your referrer_id is: ".$_SESSION["referrer_id"]);
echo("Your checksum is: ".$_SESSION["checksum"]);
?>
That's one suggestion as to how additional incoming variables could be retained and used on other storefront pages. I hope this helps point you in the right direction! |