I am trying to write the observer class attached to events during the checkout process. I need the session class with several variables storing values for session.
But I can not properly initialize them and get them reinitialized several times during the checkout process. A a result I loose the values assigned to these variables on previous entry to the class. It looks like I do not understand how does the ONS work.
For test purposes I wrote a stupid testclass attached to the same events. But it does not work at all. I would appreciate if someone could advice what is wrong.
The file config.testclass.php in the includes/auto_loaders directory contains:
Code:
<?php
/*
* instantiate class.testclass at 180 - when
* everything is initialized
* in <root>/includes/auto_loaders
*/
$autoLoadConfig[180][]= array('autoType' => 'class',
'loadFile' => 'observers/class.testclass.php');
$autoLoadConfig[180][]= array('autoType' => 'classInstantiate',
'className' => 'testclass',
'objectName' => 'testClassObject',
'checkInstantiated' => true,
'classSession' => true );
?>
and class.testclass.php in includes/classes/observers looks like this:
Code:
<?php
class testclass extends base {
var $initialized= false;
var $field;
/*constructor*/
function testclass() {
global $zco_notifier;
$this->test_log($this->initialized ."\t=initialized at start constructor");
$this->test_log($this->field ."\t=field at start constructor");
$zco_notifier -> attach($this,
array('NOTIFY_HEADER_START_CHECKOUT_CONFIRMATION',
'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION',
/*'NOTIFY_HEADER_END_CHECKOUT_SUCCESS',*/
'NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS',
'NOTIFY_HEADER_START_ACCOUNT_HISTORY_INFO'));
if( !($this->initialized) ) {
$this->initialized= true;
$this->field= -10;
}
$this->test_log($this->initialized ."\t=initialized at end constructor");
$this->test_log($this->field ."\t=field at end constructor");
}
/* update method */
function update(&$callingClass, $eventID, $paramsArray) {
if($eventID == 'NOTIFY_HEADER_START_CHECKOUT_CONFIRMATION') {
$this->test_log($this->initialized ."\t=initialized at start " .$eventID);
$this->test_log($this->field ."\t=field at start " .$eventID);
$this->field= 200;
$this->test_log($this->initialized ."\t=initialized at end " .$eventID);
$this->test_log($this->field ."\t=field at end " .$eventID);
} else if($eventID == 'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION') {
$this->test_log($this->initialized ."\t=initialized at start " .$eventID);
$this->test_log($this->field ."\t=field at start " .$eventID);
$this->field= 300;
$this->test_log($this->initialized ."\t=initialized at end " .$eventID);
$this->test_log($this->field ."\t=field at end " .$eventID);
} else if($eventID == 'NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS') {
$this->test_log($this->initialized ."\t=initialized at start " .$eventID);
$this->test_log($this->field ."\t=field at start " .$eventID);
$this->field= 400;
$this->test_log($this->initialized ."\t=initialized at end " .$eventID);
$this->test_log($this->field ."\t=field at end " .$eventID);
} else if($eventID == 'NOTIFY_HEADER_START_ACCOUNT_HISTORY_INFO') {
$this->test_log($this->initialized ."\t=initialized at start " .$eventID);
$this->test_log($this->field ."\t=field at start " .$eventID);
$this->field= 500;
$this->test_log($this->initialized ."\t=initialized at end " .$eventID);
$this->test_log($this->field ."\t=field at end " .$eventID);
}
}
/* write debug */
function test_log($message) {
$flog= fopen("/tmp/zc_log.txt","a");
fwrite($flog,$message ."\n");
fclose($flog);
}
} /* end testclass */
?>
As you can see the class only changes the value of the $this->field and writes simple trace to the file. But the written zc_log.txt file contains only the output from the constructor method. It seems the update method is never called.
What is wrong here?
Bookmarks