Contributions
Recently Viewed Products
This is a simple mod that tracks which products a visitor clicks on and displays text
links to those products in a box, (column left/right or wherever you want) thereby giving them the oppotunity to easily revisit those products with just one click.
The code included assumes you will use one of the columns. The text links displayed in the box are updated each time the visitor navigates to another product's page and the most recently visited product sits at the top of the list.
The code relys on a cookie to hold a unique identifying number for the product tracking to work. You can see an example of this mod by visiting the following web site: http://www.frigidfluidco.com
Click around the site and visit a few product pages to see it work.
Expand All / Collapse All
THIS IS NOT A FULL INSTALLATION
****************************
This is an optional replacement of the latest viewed_products.php file. All I’ve done here is changed the HTML formatting a little. For my purposes Recently Viewed Products works better in a box in the right column. So that’s all this is here – but thought that other people may be able to make use of this seeing as how it took me awhile to find where to make all the changes to within all the PHP.
No instructions here on how to implement this – but if you’re familiar with osC it shouldn’t be too difficult. Basically what I did was followed the instructions for the lastest full release but rather than making changes to my footer.php I made the changes to my column_right.php along with this edited viewed_products.php file. You can do this with colum_left.php or column_right.php
Huge thanks to the original author Steve Yeazel and all preceding folks who helped to developed this contrib to the point it’s at now. This is an excellent addition to osC which mimics the same type of thing some of the bigger online shops I’ve seen do. Excellent work everyone!
dilirum
4 Feb 2005 - Added French Language files and modifications for French Author: Oneill from French Team
Changed in:
/includes/modules/viewed_products.php:
old line 124
<td nowrap class="pageHeading">' . BOX_HEADING_VIEWED_ITEMS . '<font size="1"> (last ' . $disp . ' items)</font></td>
new:
<td nowrap class="pageHeading">' . BOX_HEADING_VIEWED_ITEMS . '<font size="1"> (Les ' . $disp . ' derniers articles)</font></td>
.
Always back-up please?
.
New version: viewed_products_1.8.zip
All files mentioned here are now combined.
New install.txt (including previous text).
.
http://www.oscommerce.com/community/contributions,1567
Version: 9 Dec 2004 - Added Language files Author: Steve Quinn
Version: 7 Dec 2004 - Latest FULL version 4.0 Author: Amanda
.
"viewed products (user switch)"
http://www.oscommerce.com/community/contributions,2724
Versiob: 15 Dec 2004 - viewed products (user switch) Author: Amanda
.
Hi all, this is my first contribution back to the community so please backup the two files changed in this mod before you alter them.
ADDED: require_once(DIR_WS_LANGUAGES . $language . '/' . 'viewed_products.php'); to top of modules/viewed_products.php
CREATED: includes/languages/english,french and german/viewed_products.php language define files.
I have not translated these, merely copied the english definitions accross so if someone would be kind enough to translate the various languages and post back the files that would be great.
FURTHER: I will be working later today on the /modules/viewed_products.php to allow full design options via some custom css styles and an option to have this as a box on the side of your site.
Thanks to original author for the obvious work put in here, its a doddle to install!
The latest version FULL install:
copy the class into the classes directory
copy the module into the modules directory
copy the images into the images directory
this version assumes your product images are in the images directory.
in application_top.php find this code :
// include shopping cart class
require(DIR_WS_CLASSES . 'shopping_cart.php');
after that add:
// include viewed products class
require(DIR_WS_CLASSES . 'viewed_products.php');
in footer.php where you would like it add:
<?php
include(DIR_WS_MODULES . 'viewed_products.php');
?>
The functionallity:
this module will remember the products viewed by the customer as long as the session is alive.
in the top of the module there are 3 setting:
1) the number of products per column
2) the maximum number of products to display
3) the number of products on display before we start reminding customers
This because we do not want to say "remember me" after the first product.
That basically insinuates that the customer has a memory problem.
The module sequence:
1) determine if we need to erase the history because the user requested that.
2) determine if we have history
if we do we display it, if we do not, no box display and it all ends there.
3) if we have history, a random product is taken from the ones on display.
Then the "also purchased" query is done.
if we find a result, that product is shown on the right side.
if we do not get a result, a random product is taken from the products on display BEYOND the memory trigger.
so only if we display more than the memory trigger and that product is displayed with the remember me text.
if however we are not yet displaying more than the memory trigger, the description text is shown, otherwise
the right side would be soo empty.
4) we determine if we have a products_id in the page variables.
if that product in not in the products on display and we are not coming back from an erase request we add it
to the history. That product will then be in the list the next time.
NOTE:
because this information is customer (session) specific, page caching will not be a good idea.
Therefore, in the top of the module there is this IF statement:
if (((tep_session_is_registered('customer_id')) or (ENABLE_PAGE_CACHE == 'false')) and (!$spider_flag)){
this means that we activate the module only if the customer is logged in OR we have disabled the page caching module.
If you do not have the page caching module from Chemo installed, ERASE this condition and the module will be active
at all times.
simplified viewed products class:
I have simplified the class so that the array handling is simpler.
no more foreeach loops etc.
1) replace the viewed_products.php class with this one.
2) in the module viewed_products.php
find in the first query this line :
where p.products_id = '" . $items[$i]['id'] . "' and
replace it with :
where p.products_id = '" . $items[$i] . "' and
find right under that :
$items_on_display[$i] = array('id' => $items[$i]['id'],
replace it with :
$items_on_display[$i] = array('id' => $items[$i],
Simply added a few missing language defines, images and changed css calls to reflect stock os system - all functionality credit to original author.
Simplified structure:
Most of the code is moved to the module itself.
making the installation and maintenance a lot easier.
to install:
in application_top.php:
after:
// include shopping cart class
require(DIR_WS_CLASSES . 'shopping_cart.php');
add:
// include viewed products class
require(DIR_WS_CLASSES . 'viewed_products.php');
in footer.php or where you want it:
add:
// include the viewed products module
include(DIR_WS_MODULES . 'viewed_products.php');
in you language files:
add:
define('TEXT_HIST_ALSO_PURCHASED_PRODUCTS', 'Customers who bought products in your Recent History<br>also purchased:');
define('TEXT_DO_YOU_REMEMBER','Do you remember this one?');
define('TEXT_HIST_EXPL1',' Your Recent History records the last ');
define('TEXT_HIST_EXPL2',' products you have viewed.<br><br>This to enable you to go back and re-visit those products at your convenience.');
add the class viewed_products.php to you classes directory
add the module viewed_products.php to your modules directory
that is it.
NOTE:
ALL actions are now done in the module.
This includes the session variable registration, the displaying as well as the product adding and erase function.
NOTE:
In the top of the module you will find this IF statement:
if (((tep_session_is_registered('customer_id')) or (ENABLE_PAGE_CACHE == 'false')) and (!$spider_flag)){
This statement means that IF your customer is logged on OR you have the page cache mod from chemo disabled AND IN ANY CASE we are not dealing with a spider
THEN this module is active. You do not want to show the history when caching entire pages.
SO, the module still works with the page cache mod but only after the customer logs on.
This because then the page cache mod is disabled anyway.
If you do not use the page cache mod, remove this IF statement.
Any questions, go to the forum:
http://forums.oscommerce.com/index.php?showtopic=123203
This update removes more queries.
previously, the class would query the names and image paths of all recorded products.
now, we only query that info for the products you actually display.
so the query is out of the class and into the module.
1) only replace the viewed_products.php class and the viewed_products.php module.
This update of the viewed_products.php module will eliminate an unnecessary query for product name and image path. That info is already supplied by the class.
only replace the viewed_products.php module.
Extention of the view box :
Screenshots included.
I have added the "also purchased" option into the box.
the box randomly selects a product from your recent history list (only the ones on display)
and tries to determine the also purchased function (same as the existing info box).
If it finds results it will display it as shown in screenshot 2.
If it cannot find one, it will take the selected item and simply display the product with image
as shown in screenshot 3.
There is a memory triggger variable in there so that the box will only start to display the product
as in screenshot 3 after a certain number of products are in the list.
NOTE: in this box I use my own tep_image_dyn function which only takes a percentage variable to
display the product images. If you do not have this function (derived from thumbnail mod) you will have
to alter that statement to suit your own image display.
So, to UPDATE:
1) replace the module viewed_products.php
2) add the following lines to your language files
define('TEXT_HIST_ALSO_PURCHASED_PRODUCTS', 'Customers who bought products in your Recent History<br>also purchased:');
define('TEXT_DO_YOU_REMEMBER','Do you remember this one?');
3) change the tep_image_dyn() function in the module to suit your own needs. You may just replace it with the
original tep_image() function.
I forgot this statement which needs to go into the large action switch in application_top.
case 'viewed_remove' : $viewed->remove();
break;
you can put it in any spot between the other case statements. This will empty the viewed_products session variable.
amanda.
This is a variation on this mod which uses session variables. The class is not created by me but by.. I cant remember but it is somewhere in the contributions.
To install:
1) add the following to your applicaton_top.php
NOTE: I do not enable this function when pages are cached or when a spider is active.
require(DIR_WS_CLASSES . 'viewed_products.php');
if (((tep_session_is_registered('customer_id')) or (ENABLE_PAGE_CACHE == 'false')) and (!$spider_flag)){
if (!is_object($viewed)) {
tep_session_register('viewed');
$viewed = new viewed_products;
$viewed->viewed_items = array();
}
}
2) put the class viewed_products.php in the classes directory.
3) put the module viewed_products.php in the modules directory.
4) At the bottom of product_info.php after the footer include add:
if (((tep_session_is_registered('customer_id')) or (ENABLE_PAGE_CACHE == 'false')) and ($spider_flag == false)) {
$viewed->add_viewed($HTTP_GET_VARS['products_id']);
}
5) put in the footer.php (i do) or where you would like the information:
<?php
if (((tep_session_is_registered('customer_id')) or (ENABLE_PAGE_CACHE == 'false')) and ($spider_flag == false)) {
if ($viewed->count_viewed() > 0) {
require(DIR_WS_MODULES . 'viewed_products.php');
}
}
?>
This box looks a little like the one from amazon.
options for the module products_viewed.php:
DEFINE('HIST_ROWS',5); // number of rows per column
DEFINE('HIST_MAX_ROWS',15); // max number of products
6) put the image "indicator.gif" in the images directory but you can use any image you like.
7) add the following to your language files :
define('BOX_HEADING_VIEWED_ITEMS', 'Your Recent History');
define('TEXT_RESET_VIEWED_ITEMS', 'Erase Your Recent History');
Again, disable it when using page_cache or when guest because registered customers dont get the cached pages.
example at http://www.crystallight.com.tw
just go over a view products and see the box get filled in the footer.
Kudos to the author for this mod.
If you're getting an error running it, try the following in the modification for application_top.php:
CHANGE FROM:
mt_srand ((double) microtime() * 1000000);
$rand_num = mt_rand(14568, 96587); //these numbers are arbitrary
if (!($HTTP_COOKIE_VARS['prod_view'])) {
setcookie('prod_view', $rand_num, time()+14400);
}
TO:
mt_srand ((double) microtime() * 1000000);
$rand_num = mt_rand(14568, 96587); //these numbers are arbitrary
if (!isset($HTTP_COOKIE_VARS['prod_view'])) {
setcookie('prod_view', $rand_num, time()+14400);
}
Cheers,
Mike Chu
michaelbc@gmail.com
Forgot to add the clean up script in the original package
This is a simple mod that tracks which products a visitor clicks on and displays text
links to those products in a box, (column left/right or wherever you want) thereby giving them the oppotunity to easily revisit those products with just one click.
The code included assumes you will use one of the columns. The text links displayed in the box are updated each time the visitor navigates to another product's page and the most recently visited product sits at the top of the list.
The code relys on a cookie to hold a unique identifying number for the product tracking to work. You can see an example of this mod by visiting the following web site: http://www.frigidfluidco.com
Click around the site and visit a few product pages to see it work.
Note: Contributions are used at own risk.