Page 1 of 3 123 LastLast
Results 1 to 10 of 21
  1. #1
    Join Date
    Mar 2004
    Location
    Calgary, Alberta
    Posts
    290
    Plugin Contributions
    1

    Default Notifier Class - attempt

    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);

    }
    }
    }
    ?>

  2. #2
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,684
    Plugin Contributions
    123

    Default Re: Notifier Class - attempt

    Before you go further with this, did you look at Admin->Reports->Products Viewed?
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  3. #3
    Join Date
    Mar 2004
    Location
    Calgary, Alberta
    Posts
    290
    Plugin Contributions
    1

    Default Re: Notifier Class - attempt

    That is the reason for this class, as the products viewed currently just accrues totals, I want to create detailed reports from the data. Reports will be the next phase once the data exists.

    Right now I have a library of reports created for ZenCart, but its not in line with the ZenCart way currently. That will also be refactored as I do this reporting tool.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Notifier Class - attempt

    A few thoughts and feedback:

    1. The new table you mentioned ... should be TABLE_PRODUCTS_VIEWED, not DESCRIPTION

    2. No need to edit the core "/includes/database_tables.php" file. Simply add a new file, like this: /includes/extra_datafiles/tables_products_viewed.php and insert the define statement in that file, even if that's all the file contains (with php wrapper tags of course).

    3. Your question #4 about whether "91" matters and what if it's a duplicate? Duplicates just mean they will both be processed together, after 90 and before 92. Entries are processed in the order of the array sequence. Duplicates are processed in the order in which they are added.

    4. The only difference in functionality which I see in the code you posted vs the Zen Cart core is the "potential" to exclude certain products from being tracked. Granted, you probably have more "in mind" than what you've shared here thus far. I'm just thinking that if the tracked data is no different than the core, why is there a need for this additional infrastructure? Just a thought. I'm sure you have a reason, and it's likely related to the bigger picture that you're working with.

    Hope that helps
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Mar 2004
    Location
    Calgary, Alberta
    Posts
    290
    Plugin Contributions
    1

    Default Re: Notifier Class - attempt

    Your question #4 is a good one. Here is my vision.....

    I look at my products viewed and it tells me 500 people have viewed bike hoists, and 400 have viewed epoxy, which is great.... what if I now add 10 new products, and want to know what people are now viewing this week, it will take a year before those products even get enough hits to count. What if I start 5 sales, which products are people now looking at.... or what do people look for in thhe spring vs fall, should I be promoting products at different times of thhe year.....its really for marketing, if I tweek a category name, or make some change, how can I see if that has helped to make it a better experience for the potential customer.

    Now the other way of doing this is to schedule an even that does a copy of the viewed data every night, but that isn't the zen way ;-) Now the BIG difference is my method tracks on a daily basis, which is much more granular then the current zen approach.

    Does my explanation make sense and is it a worth while task or am I off my rocker and should devote my energy to a different problem, like shipping.....

    and thanks for the tips, I'll add them to my notifier attempt. I'm glad that the basics are good.

  6. #6
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Notifier Class - attempt

    ack! I totally missed the "date" portion of that. Glazed right over it.

    Yes -- excellent idea. Handy method to track the statistics in a way that helps you use the data for marketing and product-mgmt purposes.




    I musta missed that when my brain hiccupped because it didn't see a step #3 in your post and was trying to reconcile that vs what it had read earlier. Or, that's my excuse anyway
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Mar 2004
    Location
    Calgary, Alberta
    Posts
    290
    Plugin Contributions
    1

    Default Re: Notifier Class - attempt

    whew, as with 2 people basically asking if I had missed the boat, I was wondering if I set sail without taking along an anchor.... good to see I didn't.

    What I'd like to do is some form of graphical report next with this, which is something new for me, but I'm sure someone has done something I can piggy back on. Need to get this class notifier working first though. There is nothing like working on a project at 2am in the morning.

    When I get my notifer working I'll post thhe whole set up here as well, so others have a road map they can use to make theres as well. (unless there is a better place I should be doing that).

  8. #8
    Join Date
    Mar 2004
    Location
    Calgary, Alberta
    Posts
    290
    Plugin Contributions
    1

    Default Re: Notifier Class - attempt

    Questions:
    1. after adding the class and auto_loader, does it just immediately start working, or does php or something else need to be restarted?
    2. What is the easiest way to tell if the class is working... is there a way of logging?
    3. How can we tell what notifiers are in zencart and what notifiers are active, and there should be a way in the admin system to see these and activate or turn them off. (nice future tool).

  9. #9
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Notifier Class - attempt

    Quote Originally Posted by quentinjs View Post
    Questions:
    1. after adding the class and auto_loader, does it just immediately start working, or does php or something else need to be restarted?
    2. What is the easiest way to tell if the class is working... is there a way of logging?
    3. How can we tell what notifiers are in zencart and what notifiers are active, and there should be a way in the admin system to see these and activate or turn them off. (nice future tool).

    1. Once they're in, they're active. ie: if they get loaded by the autoloader system, they will function immediately.
    2. If there are no errors, you know they're not crashing. Logging is a little more challenging. You could have it write to a file or send you an email, using normal methods for such activity.
    3. What notifiers are installed? There is no report on that at present.
    4. Which notifiers are active? No indicators.
    5. Enable/disable via admin. Some configuration switches could be added for this. I suggest a naming convention of NOTIFIER_ENABLE_STATUS_XXXXXXXXXX
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  10. #10
    Join Date
    Nov 2003
    Location
    Haarlem | Netherlands
    Posts
    1,987
    Plugin Contributions
    15

    Default Re: Notifier Class - attempt

    Quote Originally Posted by DrByte View Post
    4. Which notifiers are active? No indicators.
    That reminds me I need to upload the new version of the Superglobals viewer :-)

    Would having a live list like this help?:
    (of course with much better layout instead)
    # autoLoadConfig (array)

    * 0 (array)
    o 0 (array)
    + autoType (string) => class
    + loadFile (string) => class.base.php
    o 1 (array)
    + autoType (string) => class
    + loadFile (string) => class.notifier.php
    o 2 (array)
    + autoType (string) => classInstantiate
    + className (string) => notifier
    + objectName (string) => zco_notifier
    o 3 (array)
    + autoType (string) => class
    + loadFile (string) => class.phpmailer.php
    o 4 (array)
    + autoType (string) => class
    + loadFile (string) => class.smtp.php
    o 5 (array)
    + autoType (string) => class
    + loadFile (string) => boxes.php
    o 6 (array)
    + autoType (string) => class
    + loadFile (string) => category_tree.php
    o 7 (array)
    + autoType (string) => class
    + loadFile (string) => template_func.php

    <snip>skipped a lot here to shorten the post</snip>

    * 160 (array)
    o 0 (array)
    + autoType (string) => classInstantiate
    + className (string) => breadcrumb
    + objectName (string) => breadcrumb
    o 1 (array)
    + autoType (string) => init_script
    + loadFile (string) => init_category_path.php
    * 170 (array)
    o 0 (array)
    + autoType (string) => init_script
    + loadFile (string) => init_add_crumbs.php
    * 180 (array)
    o 0 (array)
    + autoType (string) => init_script
    + loadFile (string) => init_header.php

 

 
Page 1 of 3 123 LastLast

Similar Threads

  1. Class notifier usage
    By fe1lho in forum General Questions
    Replies: 1
    Last Post: 6 Oct 2011, 03:35 PM
  2. Class notifier not found
    By psychosis in forum Upgrading from 1.3.x to 1.3.9
    Replies: 2
    Last Post: 14 Sep 2011, 08:55 PM
  3. 1.38a to 1.39b - Fatal Error Class 'notifier' not found
    By DCDC in forum Upgrading from 1.3.x to 1.3.9
    Replies: 1
    Last Post: 11 May 2010, 12:16 AM
  4. Fatal Error class 'notifier' not found
    By wingedwench in forum General Questions
    Replies: 1
    Last Post: 6 Nov 2009, 08:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR