Zen Follower
- Join Date:
- Mar 2004
- Location:
- Calgary, Alberta
- Posts:
- 289
- Plugin Contributions:
- 0
Notifier Class - attempt
- Will this work? I'm trying to audit all products viewed.
- What needs to be changed?
- Should a notifier forum be created?
-
- 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.php/Developers_API_Tutorials
*/
- Save below as includes/classes/observers/class.tgi_productsviewed.php.
/**
- 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);}
}
}
?>
Cheers,
Quentin J Sarafinchan
Total Garage - Garage Organizers and Enhancement
http://www.totalgarage.ca