Show Recent History (Items Clicked) By a Shopper

Find addons/modules/scripts for AOM. Post your own.
Post Reply
User avatar
bmcaulif
Experience Level 3
Experience Level 3
Posts: 190
Joined: Tue Jun 27, 2006 11:06 pm
Location: USA
Contact:

Show Recent History (Items Clicked) By a Shopper

Post by bmcaulif » Sun Aug 29, 2010 8:30 am

Ever want to show the last few items the user clicked on so they can go back to them? Here's one way...

I use these scripts on all of my sites and right now the script placement is limited to the right or left columns. Feel free to edit the output script but you need to be very familiar with how quoting works because this requires some javascript magic to work right.

It has to be done via javascript because of the page caching (otherwise your users would see only the history of the first user to cache the page).

It requires a php file custom box, a raw html custom box, as well as an inclusion of a css script or additions to the one you may already be calling.

Upload the following 2 scrpits to your AOM store root (above the AOM directory).

historysetvars.php

Code: Select all

<?
//--------------------------------------------------
$theuri = @$_SERVER['REQUEST_URI'];
$thehost = @$_SERVER['HTTP_HOST'];
$theurl = ("http://$thehost$theuri");
echo '<script type="text/javascript">';
echo "var name='".addslashes($page["Name"])."';";
if (isset($page["n"])){
        echo "var n='".addslashes($page["n"])."';";
} else {
         echo "var n='';";
}
if (isset($page["i"])){
        echo "var i='".addslashes($page["i"])."';";
} else {
         echo "var i='';";
}
if (isset($page["i"])){
        echo "var asin='".addslashes($page["i"])."';";
} else {
         echo "var asin='';";
}
if (isset($theurl)){
        echo "var u='".addslashes($theurl)."';";
} else {
         echo "var u='';";
}
if (isset($page["c"])){
        echo "var c='".addslashes($page["c"])."';";
} else {
         echo "var c='';";
}
if (isset($page["x"])){
        echo "var x='".addslashes($page["x"])."';";
} else {
         echo "var x='';";
}
echo '</script>';
?>
historyshow.php

Code: Select all

<?
//start the session
session_start();
//register the history  array
session_register('history');
//not used yet $alignment = 'VERTICAL';
//How many in the list
$listCount = '5'; //change this to alter the number of history items to show
//not used yet $hCols = '4';
//not used yet $vCols = '1';
//not used yet $categoryClass="aom_stn";
//not used yet $nameClass="aom_stn";
//class to use for display
$urlClass="aom_stn";
$ulClass="aom_stn";
//products in this category
//all products
//set the history var to the current session var
$theuri = @$_SERVER['REQUEST_URI'];
$thehost = @$_SERVER['HTTP_HOST'];
$theurl = ("http://$thehost$theuri");
$history = $_SESSION['history'];
//first see if we are on an item page
$i = @$_GET['i'];
$c = @$_GET['c'];
$name = @$_GET['name'];
$u = @$_GET['u'];
if (isset($i)) {
        //is there any thing in the history yet
        if (isset($history) ) {
                //how many in the list now
                $count = count($history);
                //set the duplicate flag to zero
                $inList=0;
                foreach ($history as $v) {
                        //see if the asin is already in the list
                        if ($v["asin"]==$i) {
                                //it is in the list so do not add
                                $inList=1;
                        };
                }
                //if it is not in the list then add it
                if ($inList == 0){
                        //if the current list is as big as $listCount remove the oldest one
                        if ($count >= $listCount) {
                                array_shift($history);
                        }
                        //add the new page to the list
                        $history[$count+1] = array( "category" => $c,"asin" => $i, "name" => $name, "url"=>$u);
                        $_SESSION['history'] = $history;
                        session_write_close();
                }
        } else {
                //nothing in the history so add the first item
                $history = array (array( "category" => $c,"asin" => $i, "name" => $name, "url"=>$u) );
                $_SESSION['history'] = $history;
                session_write_close();
        }
}
//--------------------------------------------------
if (isset($history) ) { // display the history
        echo "document.write('<ul class=history>');";
        foreach ($history as $v) {
                echo "document.write('".'<li><a href="'.$v["url"].'"><span class="'.$urlClass.'">'.addslashes($v["name"])."</a></span></li>');";
        }
        echo "document.write('</ul>');";
}
?>
First, make a php custom box that is set to Page Top (PT) and order of '1'. MAKE SURE the box is set to 'HTML/PHP File'. Set the border to '0' and the background to a color that is the same as your site background.

put /path-to-your-root/historysetvars.php as the box content (replace 'path-to-yor-root' with the FILESYSTEM not web path, i.e. /public_html/mysite/historysetvars.php

Next, make another custom box. Make the box type 'Raw HTML', set the position to 'R' or 'L' only (because I have formatted the script for the right or left columns at this point) then add the following into the box contents:

THERE IS AN EDIT IN THIS SCRIPT YOU MUST DO! Change 'yoursitename.com' to, well, your site name.

Code: Select all

<script type="text/javascript"><!--
var qry='http://www.yoursitename.com/historyshow.php?c='+c+'&i='+asin+'&u='+escape(u)+'&name='+escape(name);
var jsstart='<scr'+'ipt type="text/javascript" src="';
var jsend='">';
document.write(jsstart+qry+jsend);
document.write('</scr'+'ipt>');
//-->
</script>
For the formatting of the output, add the following to a css file set in the 'CSS' section of the AOM interface. You could probaby include the settings in a <STYLE> tag above the code above as well:

Code: Select all

ul.history {margin-left: 0.5em; padding-left: 0.5em;}
So if you included it as a style in the box above, that box would look like:

Code: Select all

<STYLE>
ul.history {margin-left: 0.5em; padding-left: 0.5em;}
</STYLE>
<script type="text/javascript"><!--
var qry='http://www.yoursitename.com/historyshow.php?c='+c+'&i='+asin+'&u='+escape(u)+'&name='+escape(name);
var jsstart='<scr'+'ipt type="text/javascript" src="';
var jsend='">';
document.write(jsstart+qry+jsend);
document.write('</scr'+'ipt>');
//-->
</script>
Though please note I have not tested this! Let me know if you try it so others can use that technique.

I hope you find the script useful, let me know if you have issues with it. It has been tested under PHP 5 and Apache 2, and I know it works with IE 6 up and Mozilla.
Associate-O-Matic is changing. For the better. 8)

Please CLICK HERE for our important announcement.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests