1. Will this work? I'm trying to audit all products viewed.
2. What needs to be changed?
3. Should a notifier forum be created?
<?php
/*
* 1. in table includes\database_tables.php, add the line
* define('TABLE_PRODUCTS_DESCRIPTION', DB_PREFIX . 'products_viewed');
*
* 2. Create table, if your using a db_prefix, make sure you prefix the table name with it.
* CREATE TABLE products_viewed(
products_id Int,
language_id Int,
viewed_date Date,
products_viewed int
)
*
* 4. In includes/autoloaders create file called config.tgi_productsviewed.php containing
* NOTE: does the # 91 really matter? what if another 91 exists?
<?php
$autoLoadConfig[91][] = array('autoType'=>'class',
'loadFile'=>'observers/class.freeProduct.php');
$autoLoadConfig[91][] = array('autoType'=>'classInstantiate',
'className'=>'tgi_productsviewed',
'objectName'=>'tgi_productsviewed');
?>
*
* 5. Save below as includes/classes/observers/class.tgi_productsviewed.php.
Note: The notifier list needs to be updated on page
http://www.zen-cart.com/wiki/index.p..._API_Tutorials
*/
/**
* Observer class used to track products viewed on a daily basis.
* great for seasonal marketing planning and active marketing analysis.
*
*/
class tgi_productsviewed extends base {
/**
* an array of ids of products to not track.
*
* @var array
*/
var $IgnoreArray = array(-1, -2); // Just place holders so something exists for demo purposes.
/**
* constructor method
*
* Attaches our class to the $_GET['products_id'] and $_SESSION['languages_id'] and watches for 1 notifier event.
*/
function tgi_productsviewed() {
// $_SESSION['cart']->attach($this, array('NOTIFY_MAIN_TEMPLATE_VARS_START_DOCUMENT_GENERAL_INFO'));
global $zco_notifier;
$zco_notifier->attach($this, array('NOTIFY_MAIN_TEMPLATE_VARS_START_DOCUMENT_GENERAL_INFO'));
}
/**
* Update Method
*
* Called by observed class when any of our notifiable events occur.
*
* We check to see if we have an entry for today for this item, if we don't then we create one,
* otherwise that item is incremented.
*
* @param object $class
* @param string $eventID
*/
function update(&$class, $eventID) {
// get the current date
$sql = "select curdate() as now";
$res = $db->Execute($sql);
$now = $res->fields['now'];
$now = getdate(); // just in case the date changes
// first see if we have a matching product entry.
$sql = "select count(*) as total
from " . TABLE_PRODUCTS . " p, " .
TABLE_PRODUCTS_DESCRIPTION . " pd
where p.products_status = '1'
and p.products_id = '" . (int)$_GET['products_id'] . "'
and pd.products_id = p.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";
$res = $db->Execute($sql);
if ( $res->fields['total'] >= 1 ) {
// see if a table entry exists
$sql = "select count(*) as total
from " . TABLE_PRODUCTS_VIEWED . " p, " .
and p.products_id = '" . (int)$_GET['products_id'] . "'
and p.language_id = '" . (int)$_SESSION['languages_id'] . "'";
and p.viewed_date = '" . $now . "'";
$res = $db->Execute($sql);
if ( $res->fields['total'] >= 1 ) {
$sql = "update " . TABLE_PRODUCTS_VIEWED . "
set products_viewed = products_viewed+1
where products_id = '" . (int)$_GET['products_id'] . "'
and language_id = '" . (int)$_SESSION['languages_id'] . "'"
and p.viewed_date = '" . $now . "'";
$res = $db->Execute($sql);
} else { /* create new entry */
$sql = "insert into " . TABLE_PRODUCTS_VIEWED . "
(products_viewed, products_id, language_id, viewed_date) values (
1, '" . (int)$_GET['products_id'] . "', '" . (int)$_SESSION['languages_id'] . "',"
'" . $now . "')";
$res = $db->Execute($sql);
}
}
}
?>
Bookmarks