Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2008
    Posts
    21
    Plugin Contributions
    0

    Default Cannot get Observer to trigger

    Using v1.3.9h

    I am trying to learn how to use Observers, I've followed examples and searched forum but I cannot find what I'm doing wrong.

    I have class.mycheckoutobs.php located at /includes/classes/observers

    PHP Code:
    <?php
     
    class mycheckoutobs extends base {
       function 
    mycheckoutobs() {
         
    $this->attach($this, array('NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL'));
       }
       function 
    update(&$callingClass$notifier$paramsArray) {
        
    $filename 'test.txt'
        
    $somecontent "Add this to the file\n"
        echo 
    "Current directory is " getcwd();
        
    // Let's make sure the file exists and is writable first. 
        
    if (is_writable($filename)) { 
        
            
    // In our example we're opening $filename in append mode. 
            // The file pointer is at the bottom of the file hence 
            // that's where $somecontent will go when we fwrite() it. 
            
    if (!$handle fopen($filename'a')) { 
             print 
    "Cannot open file ($filename)"
             exit; 
            } 
        
            
    // Write $somecontent to our opened file. 
            
    if (!fwrite($handle$somecontent)) { 
            print 
    "Cannot write to file ($filename)"
            exit; 
            } 
             
            print 
    "Success, wrote ($somecontent) to file ($filename)"
             
            
    fclose($handle); 
                     
        } else { 
            print 
    "The file $filename is not writable"
        } 
       }
     }
    ?>
    I have config.mycheckoutobs.php at /includes/auto_loaders

    PHP Code:
    <?php

    $autoLoadConfig
    [10][] = array('autoType'=>'class',
                                  
    'loadFile'=>'observers/class.mycheckoutobs.php');
    $autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
                                  
    'className'=>'mycheckoutobs',
                                  
    'objectName'=>'mycheckoutobs');
    ?>
    This is just a test to learn. Anyone see what is wrong?

  2. #2
    Join Date
    Dec 2008
    Posts
    21
    Plugin Contributions
    0

    Default Re: Cannot get Observer to trigger

    I found the the issue. Spaces and carriage returns after the closing ?> in the observer.

  3. #3
    Join Date
    Jun 2003
    Posts
    33,720
    Plugin Contributions
    0

    Default Re: Cannot get Observer to trigger

    Thanks for posting back that you found the problem. You may have helped someone else with a similar problem.
    Please do not PM for support issues: a private solution doesn't benefit the community.

    Be careful with unsolicited advice via email or PM - Make sure the person you are talking to is a reliable source.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Cannot get Observer to trigger

    Quote Originally Posted by D-man View Post
    I found the the issue. Spaces and carriage returns after the closing ?> in the observer.
    Related articles, for reference:
    https://www.zen-cart.com/tutorials/i...hp?article=313
    https://www.zen-cart.com/tutorials/index.php?article=87
    .

    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.

 

 

Similar Threads

  1. v150 Cannot get multiple images.
    By antonart in forum Templates, Stylesheets, Page Layout
    Replies: 10
    Last Post: 30 Sep 2012, 07:59 PM
  2. v139e Cannot get emails to send
    By irishshopper in forum Basic Configuration
    Replies: 1
    Last Post: 18 Sep 2012, 03:45 PM
  3. Cannot get VAT to show
    By MelodyW in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 6
    Last Post: 5 Dec 2011, 05:43 PM
  4. Cannot get FCKeditor to show up
    By coolbreeze3 in forum All Other Contributions/Addons
    Replies: 4
    Last Post: 2 May 2010, 03:12 PM

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