-
Use Of Notifiers - How To
I have read the wiki tutorial and previous v1.3 anouncment posts in the forum and I understand the concept of notifieriers, but cannot get it working...
I presumed, that when I save a new class which has
Code:
$_SESSION['cart']->attach($this, array('NOTIFIER_CART_ADD_CART_END', 'NOTIFIER_CART_REMOVE_END'));
or similar in the class consturctor, then the observer class should implement the code and wake it up, when notified, but nothing... [Tried also with the original code in the wiki]
As far as I understand, the application_top does not read in the classes that are saved under includes/classes/observers catalog, so the class and its constructor that should attach notifier to praticular event is never called and observers array stays empty... Should aplication_top read in all observers that are saved into this folder or should I explicitly say somewhere, that these classes should be included, so the class constructors are waked and observers are added to observers array?
Debuging the code with breakpoint at class.base notify function indicates indeed that $this->observers array is empty in spite of the fact that I copied the observer code from the wiki API...
-
Hi,
The includes/classes/observers directory is not an autoload directory, so you will need to arrange for application_top.php to autlload the class.
lets assume you are using the freeProduct class example, and you have saved this in includes/classes/observers/class.freeProduct.php
You now need to arrange for this class to be loaded and instantiated.
To do this tou need to use tha application_top.php autoload system.
In includes/autoloaders xreate a file called config.freeProduct.php containing
Code:
<?php
$autoLoadConfig[90][] = array('autoType'=>'class',
'loadFile'=>'observers/class.freeProduct.php');
$autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
'className'=>'freeProduct',
'objectName'=>'freeProduct');
?>
Note: I chose 90 as the offset as the observer needs to attach to the $SESSION['cart'] class. This is instantiated at offset 80.
The free product class should now work as advertised :)
-
Thank you! :)
I copied your reply into Wiki as well, see at between "Observe and Prosper" and "Real World examples" chapters.
-
I am still learning it...
I got it working with the example above! However, when I just changed the notifier into NOTIFY_HEADER_START_CHECKOUT_CONFIRMATION or NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION then the script cannot find the observing script anymore...
Debug'ign the code shows that the $this->observers array is empty, when the notifier returns from the checkout_process header, but the same array is filled when the notifier returns from chart (during the same debuging process :blink: ).
I presume that $_SESSION['cart'] is not the right place to attach the notifier in the case when I would like to be notified by checkout_confirmation header (I tried to play around with the autoload position), but what is then a right place?
Are there some tricks, how to load notifiers from different parts of the script?
-
Quote:
I copied your reply into Wiki as well, see at between "Observe and Prosper" and "Real World examples" chapters.
::tup
On your other point.
the observer/notifier system is really written for a completely OOPs based application, as the observer expects to attach to a class that has notifiers within its methods. However a lot of the code within ZC is still procedural in nature and not contained withn a class.
To work around this, we added the 'stub' notifier class. So if you want ot create an observer for a notifier that lies within procedural code you should do something like
Code:
$zco_notifier->attach($this, array('NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION'));
I seemed to have missed this from the docs :(
-
Thanks!
I just discovered it out just few moments ago and -- "boom" -- found also your reply in the forums :)
The point, where I got stucked yesterday, was really silly: I actually tried to attach the notifier into $zco_notifier notifier class, but just forgot to add:
Code:
global $zco_notifier;
before the $zco_notifier->attach statement in my observer class...
-
So quick question then. I've got the notifier working fine. Trying to write a plugin that will sync newsletter subscriptions with PHPlist. However what means are there for passing parameters? I need to find out whether the person signed up to the newsletter or not.
-
Hi,
There is no parameter passing at all.
variables are available in a number of ways.
If you are writing a notifier that attaches to a class, then the class is passed to the observer as $class, you can therefore query class variables as $class->class-variable.(note the above does not work for session based classes, like the cart, however you can reference these as normal as $_SESSION['cart'] etc.
You can accesss procedural code variables using the superglobal $GLOBALS array, and of course all normal superglobals e.g. $_SESSION, $_POST, $_GET are available as normal.
In your example you can access the $_SESSION['customer_id'] directly and then do a quick sql query to see if that customer is signed up to newsletters.
HTH
-
Ok, I'm beggining to get the picture here.
Next challenge. I've written a class to modify the description before it is displayed. I've used the NOTIFY_MAIN_TEMPLATE_VARS_EXTRA_PRODUCT_INFO notifier to run my code after the database has been queried and before it is displayed.
I can get the description by using the GET variable products_id. However then how would I modify the variable products_description?
What I'm trying to do is parse through the description text looking for keywords I have in an array (from a glossary table). I want to make any matching terms into hyperlinks.
Related to this, I'm a little sketchy on how to tell the notifier is in a class or not. I'm assuming the class declaration should be in the same file as the notifier? ie NOTIFY_MAIN_TEMPLATE_VARS_EXTRA_PRODUCT_INFO is not in a class.
thanks, I'm liking this notifier system more and more! Any idea what phase will see all notifiers contained in classes?
-
Re: Use Of Notifiers - How To
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?
-
Re: Use Of Notifiers - How To
Hi all,
I need to add a product to the shopping cart when the user is visiting the site for the first time and a new shopping cart object is created. Can anyone please help me with the event i should attach to? I was trying to attach to event 'NOTIFIER_CART_INSTANTIATE_END' but it does not work at all.
Please help.
Thanks
Sumit Pilankar
-
Re: Use Of Notifiers - How To
Howdy All,
Just a quick question regarding the procedural workaround code.
If the notification that I am watching for happens in /includes/modules/checkout_process.php
as
$zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE');
Is it right to assume that I need to implement my observer class with the procedural:
Code:
global $zco_notifier;
$zco_notifier->attach($this, array('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE'));
rather than the OOP version:
Code:
$this->attach($this, array('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE'));
I suppose I could just do a simple test to find out, but for the benefit of those reading, I'll go ahead and put it here in writing.
-
Re: Use Of Notifiers - How To
The first form is correct. Use zco_notifier for procedural cases.
-
Re: Use Of Notifiers - How To
Hi!
I'm trying to generate a file with shipping & order detail using the notifiers (NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL).
The problem is that I need certain values be also included in the output file such as order id, product details and shipping weight.
I think when the trigger calls for my notifier, it is attached to order.php class only and $order->variables works just fine (except $order->order_id).
But I'd definitely like $shipping_weight (all cart weight + tare or large_tare) and $order_id be included.
How do I pass variables from shipping.php class?
And why wouldn't $order->order_id not working whereas $order->total_weight does?
-
Re: Use Of Notifiers - How To
Without looking in great detail, I suspect you will need to "global" the $shipping_weight variable in order to use it in your notifier class.
Also global the $insert_id if you want the number of the current order.
-
Re: Use Of Notifiers - How To
Quote:
Originally Posted by
DrByte
Without looking in great detail, I suspect you will need to "global" the $shipping_weight variable in order to use it in your notifier class.
Also global the $insert_id if you want the number of the current order.
Thanks Dr. Byte!
'global'ling $insert_id worked. However, I still can't get the $shipping_weight to work, which I suspect that my observer is attached so well only to class order.php. Perhaps use a different notifier than NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL?
Below is the code:
Code:
<?php
class xml_generate extends base {
function xml_generate() {
global $zco_notifier;
$zco_notifier->attach($this, array('NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL'));
}
function xml_config_switch() {
if ( defined('GENERATE_XML') && (GENERATE_XML == 'false') ) {
return false;
}
return true;
}
function update(&$callingClass, $eventID) {
if (!$this->xml_config_switch()) return;
global $order, $shipping_weight, $insert_id;
//Begin USPS Domestic clause
if (strpos($order->info['shipping_module_code'], 'usps') !== FALSE) {
$xml_msg = "<DAZzle Layout='c:\endicia\dazzle7\Zebra Label.lyt' OutputFile='C:\endicia\dazzle7\xmlout\domestic" . strftime('%Y%b%d-%H%M%S') . ".xml' Start='PRINTING' Test='YES' Prompt='NO' AutoClose='NO'>" . "\r\n";
$xml_msg .= "<Package ID='1'>\r\n";
if (strpos($order->info['shipping_method'], 'Parcel') !== FALSE) {$xml_msg .= "<MailClass>PARCELPOST</MailClass>\r\n";}
if (strpos($order->info['shipping_method'], 'First') !== FALSE) {$xml_msg .= "<MailClass>FIRST</MailClass>\r\n";}
if (strpos($order->info['shipping_method'], 'Priority') !== FALSE) {$xml_msg .= "<MailClass>PRIORITY</MailClass>\r\n";}
if (strpos($order->info['shipping_method'], 'Express') !== FALSE) {$xml_msg .= "<MailClass>EXPRESS</MailClass>\r\n";}
$xml_msg .= "<DateAdvance>0</DateAdvance>\r\n";
$xml_msg .= "<PackageType>NONRECTPARCEL</PackageType>\r\n";
$xml_msg .= "<Oversize>FALSE</Oversize>\r\n";
$xml_msg .= "<WeightOz>" . ($order->total_weight * 16) . "</WeightOz>\r\n"; //works without handling charge
$xml_msg .= "<WeightOz>" . ($shipping->shipping_weight * 16) . "</WeightOz>\r\n"; //returns 0
$xml_msg .= "<WeightOz>" . ($shipping_weight * 16) . "</WeightOz>\r\n"; //returns 0
$xml_msg .= "<Services>CertifiedMail='OFF' DeliveryConfirmation='OFF' ></Services>\r\n";
$xml_msg .= "<Value>" . $order->info['total'] . "</Value>\r\n";
$xml_msg .= "<Description>" . $order->products_ordered . "</Description>\r\n";
$xml_msg .= "<ReferenceID>" . $insert_id . "</ReferenceID>\r\n";
$xml_msg .= "<ToName>" . $order->delivery['firstname'] . " " . $order->delivery['lastname'] . " - " . $order->delivery['company'] . "</ToName>\r\n";
$xml_msg .= "<ToAddress1>" . $order->delivery['street_address'] . "</ToAddress1>\r\n";
$xml_msg .= "<ToCity>" . $order->delivery['city'] . "</ToCity>\r\n";
$xml_msg .= "<ToState>" . $order->delivery['state'] . "</ToState>\r\n";
$xml_msg .= "<ToPostalCode>" . $order->delivery['postcode'] . "</ToPostalCode>\r\n";
$xml_msg .= "<ToEMail>" . $order->customer['email_address'] . "</ToEMail>\r\n";
$xml_msg .= "</Package>\r\n</DAZzle>\r\n";
$OutFile = "includes/xml/usps/domestic" . strftime('%Y%b%d-%H%M%S') . ".xml"; //Setting path n file name to USPS domestic
} //End if USPS Domestic clause
//Generate XML File
$fp = fopen($OutFile, 'a');
$fout = fwrite( $fp , $xml_msg );
fclose($fp);
}
}
?>
Notice I'm trying 3 possible weight (in oz)?
-
Re: Use Of Notifiers - How To
$order->total_weight is likely your only option.
The $shipping_weight is only available in the shopping cart, which is empty after the order is placed.
Or you could write your own weight recalculator using the weight calculations in the calculate() function of the shopping_cart class.
-
Re: Use Of Notifiers - How To
Quote:
Originally Posted by
DrByte
$order->total_weight is likely your only option.
The $shipping_weight is only available in the shopping cart, which is empty after the order is placed.
Or you could write your own weight recalculator using the weight calculations in the calculate() function of the shopping_cart class.
Thanks Dr. Byte.
As I'm not much of a programmer, I'm just putting the static tare value matching what I've put on the configuration, unless there is a method of saving $weight in shopping_cart class to some other (global?) varible that does not get reset and passed onto my observer. Or should resetting of $weight commented out from shopping_cart class and be reset at the end of my observer?
-
Re: Use Of Notifiers - How To
Quote:
Originally Posted by
SteveKim
a method of saving $weight in shopping_cart class to some other (global?) varible that does not get reset and passed onto my observer. Or should resetting of $weight commented out from shopping_cart class and be reset at the end of my observer?
Options:
a. extend the order database table to also store the total weight as calculated by shopping cart, and then write code to ensure that info gets stored appropriately
b. add a $_SESSION['shipping_weight'] variable before the shopping cart is reset, and then refer to that during your observer activities
c. alter the order-total class to store the weight in the shipping method details, and then extract that information during your export
d. recalculate the entire weight from scratch, rewriting much of the shopping-cart class
-
Re: Use Of Notifiers - How To
Quote:
Originally Posted by
SteveKim
I'm just putting the static tare value matching what I've put on the configuration, unless there is a method of saving $weight in shopping_cart class to some other (global?) varible that does not get reset and passed onto my observer.
Try using this:
Code:
$_SESSION['cart']->weight
-
Re: Use Of Notifiers - How To
Quote:
Originally Posted by
DrByte
Try using this:
Code:
$_SESSION['cart']->weight
$_SESSION['cart']->weight returns what's same as $total_weight.
Below (within the notifier class' function update), derived from class shipping did the job calculating proper [actual] shipping weight.
Code:
function update(&$callingClass, $eventID) {
if (!$this->xml_config_switch()) return;
global $order, $insert_id;
//Begin Shipping Weight Calculation
$shipping_weight = $order->total_weight;
$za_tare_array = split("[:,]" , SHIPPING_BOX_WEIGHT);
$zc_tare_percent= $za_tare_array[0];
$zc_tare_weight= $za_tare_array[1];
$za_large_array = split("[:,]" , SHIPPING_BOX_PADDING);
$zc_large_percent= $za_large_array[0];
$zc_large_weight= $za_large_array[1];
switch (true) {
// large box add padding
case(SHIPPING_MAX_WEIGHT <= $shipping_weight):
$shipping_weight = $shipping_weight + ($shipping_weight*($zc_large_percent/100)) + $zc_large_weight;
break;
default:
// add tare weight < large
$shipping_weight = $shipping_weight + ($shipping_weight*($zc_tare_percent/100)) + $zc_tare_weight;
break;
} //End Shipping Weight Calculation
-
Re: Use Of Notifiers - How To
I was wondering if anyone has gone any further with this? Such as integrating in with the admin? If not, I guess I'll just have to do it myself.
Has anyone got this to work on a production site?
-
Re: Use Of Notifiers - How To
I've nearly got that XML generation integrated, but I'm running into one little problem.
I can write a properly formatted XML file for a particular order, and even write it to a file on my server. How do I then get that file down to the local system which is where Dazzle apparently checks for XML files?
What I am trying to do is create an automated system, where the admin will just click a button on the order page and an Endicia label will print.
Any ideas?
-
Re: Use Of Notifiers - How To
Quote:
Originally Posted by
chaoscube
I've nearly got that XML generation integrated, but I'm running into one little problem.
I can write a properly formatted XML file for a particular order, and even write it to a file on my server. How do I then get that file down to the local system which is where Dazzle apparently checks for XML files?
What I am trying to do is create an automated system, where the admin will just click a button on the order page and an Endicia label will print.
Any ideas?
Set up an FTP server on your server and use something like NetworkAutomation's Automate, or even a regular FTP clients (not all of them does the job, but some do have scheduling capabilities) to schedule download every .xml files to Dazzle folder.
I'm using Automate 6.2, which is a great programming tool that costs little less than $1,000 to do lots of other things, too, in addition to a simple scheduled downloading task I mentioned above.
But all you need is schedule download using a regular FTP client.
Or compose a batch file that would authenticate, get all files from a specific location, delete from the original location, and schedule it using the windows' Schedule Task found under Control Panel.
BTW, there is a mod that would generate a packing slip and xml file for Dazzle by me found here: http://www.zen-cart.com/index.php?ma...roducts_id=756
It's quite incomplete, but you can probably reference it to complete yours.
Steve.
-
Re: Use Of Notifiers - How To
What if combining in the same observer class the watch of events coming from both classes and procedural code?
like
$this->notify('NOTIFIER_CART_ADD_CART_END');
and
$zco_notifier->notify('NOTIFY_HEADER_END_CHECKOUT_SUCCESS');
is it possible?
-
Re: Use Of Notifiers - How To
Should be fine, since the observer class is still watching for the notifier point. Granted, if you're trying to use the observer class to alter something inside the procedural code loop, you'll have a little more difficulty than if you were watching a point that was hooked from inside a class. It may be necessary to set or use session variables or other global variables for those purposes. But, if you're just having the observer do something to a database record or sending an email, and not passing data back to the calling point, then things are pretty simple.
-
Re: Use Of Notifiers - How To
Thanks.
I am still strugling with the observer concept
first , in the free product example if I replace
$_SESSSION['cart']->attach
with
$this->attach
it does not work, why?
regarding my original question
if i put together
$this->attach
and
$zco_notifier->attach
in the same class, in a sample code
Code:
class calixto extends base {
function calixto() {
global $zco_notifier;
$zco_notifier->attach($this,
array( 'NOTIFY_HEADER_START_PRODUCT_INFO'
)
);
$_SESSION['cart']->attach($this,
array( 'NOTIFIER_CART_ADD_CART_END', /* class shopping_cart */
'NOTIFIER_CART_REMOVE_END', /* class shopping_cart */
'NOTIFIER_CART_UPDATE_QUANTITY_END', /* class shopping_cart */
'NOTIFIER_CART_RESET_END' /* class shopping_cart */
)
);
}
function update(&$class, $notifier, $paramsArray) {
if ( $notifier == 'NOTIFY_HEADER_START_PRODUCT_INFO' )
$_SESSION['add_delivery'] = 'product_info';
else
$_SESSION['add_delivery'] = 'the cart';
}
}
update is called in the case of the first event
if updating the CART, zencart stops, white screen
I wonder about this scenario
will each X->attach call generate different eventID?
so that they cannot share same update function?
thanks
-
Re: Use Of Notifiers - How To
Hopefully you got my email.
But for others wondering about the same thing. I have to apologise.
The documentation is wrong.
You can use $this->attach to watch a notifier in the shopping cart class rather than $_SESSION['cart']->attach
The trick is to change the autoloader.
Documentation suggests using
PHP Code:
$autoLoadConfig[90][] = array('autoType'=>'class',
'loadFile'=>'observers/class.freeProduct.php');
$autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
'className'=>'freeProduct',
however things will work if you use
PHP Code:
$autoLoadConfig[10][] = array('autoType'=>'class',
'loadFile'=>'observers/class.freeProduct.php');
$autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
'className'=>'freeProduct',
Notice the load point for the class has been changed to 10.
HTH
-
Re: Use Of Notifiers - How To
Resurrecting an old thread. I'm working on 1.3.8a, trying to observe events on the shopping cart.
I've been going crazy trying to use the notifier system. I've hacked the shopping_cart.php and would now like to extract my work into an observer so I can port my work more easily to other versions.
My observer is loaded, instantiated, and the constructor is run, so the attach() call completes. However, I never get the update() method fired. I've spent over an hour looking at this and debugging with error_log() calls, but I don't see how the code is supposed to work.
I'm wanting to hook onto NOTIFIER_CART_RESTORE_CONTENTS_START. The docs say I should create an observer and call "$this->attach($this, array('NOTIFIER_CART_RESTORE_CONTENTS_START'));" in the constructor. This succeeds, and $this->observers is added to, but the update() method is not called when the shopping cart calls "$this->notify(....)".
Quote:
Originally Posted by
wilt
You can use $this->attach to watch a notifier in the shopping cart class rather than $_SESSION['cart']->attach
'base' has a $this->observers array, but the array isn't static, right? That is, my observer class (derived from base) has its own 'observers' array, distinct to the shopping_cart instance's observers array. I don't see why calling $this->attach() in my observer (which adds to $this->observers) would achieve the required callback hook when shopping_cart calls $this->notify().
If I change my observer to use "$_SESSION['cart']->attach($this, array('NOTIFIER_CART_RESTORE_CONTENTS_START')" the notification works fine. (also have to change the auto_loader priorities to 90 and 90 - above we were instructed to use 10 and 90 but this breaks use of $_SESSION['cart']->attach()).
I presume this was working fine in 1.3.8a (can't see anything in the changelog)? What could I be doing wrong?
Thanks
Nick
-
Re: Use Of Notifiers - How To
A number of things were addresed with respect to notifiers in v1.3.9. Have you tested the same thing in the latest version of Zen Cart yet?
-
Re: Use Of Notifiers - How To
Quote:
Originally Posted by
DrByte
A number of things were addresed with respect to notifiers in v1.3.9. Have you tested the same thing in the latest version of Zen Cart yet?
Sorry, I hadn't tried it, and should have before posting.
I'm not sure I'll have time or willpower to look at completely upgrading this 1.3.8a to 1.3.9. This shop has been installed for 4 or 5 years and has had some quite extensive hacking done to it before I started work on it, so even where the override system was followed, the job of merging the hacks into the 1.3.9 file base seems insurmountable.
However, I'm happy to code against the 1.3.9 model.. I just need the same code to work on my 1.3.8a shop.
I was hoping to determine what's wrong with this 1.3.8a installation, in terms of how the code is going wrong, and fix it up. The other Zen Cart I will be migrating the same code to is a much more recent one and hopefully won't suffer from this bug. Diff shows some fairly simple modifications to class.base.php, some kind of StaticObserver code that looks like it fixes the problem I identified above. It looks like there is now a single static array of observer info, which stores references to all the different 'base'-derived objects that registered for notifications.
I wonder if I'll be safe just taking the 1.3.9f class.base.php and using it in a 1.3.8a Zen Cart? it looks pretty safe :) I'll try it soon.
Thanks
Nick
-
Re: Use Of Notifiers - How To
Quote:
Originally Posted by
neekfenwick
I'm not sure I'll have time or willpower to look at completely upgrading this 1.3.8a to 1.3.9. This shop has been installed for 4 or 5 years and has had some quite extensive hacking done to it before I started work on it, so even where the override system was followed, the job of merging the hacks into the 1.3.9 file base seems insurmountable.
If you're comfortable keeping up a site that's using software with known security vulnerabilities, then that's your call I guess.
Quote:
Originally Posted by
neekfenwick
I was hoping to determine what's wrong with this 1.3.8a installation, in terms of how the code is going wrong, and fix it up.
...
I wonder if I'll be safe just taking the 1.3.9f class.base.php and using it in a 1.3.8a Zen Cart?
http://www.zen-cart.com/forum/showthread.php?t=150127
-
Re: Use Of Notifiers - How To
Quote:
Originally Posted by
DrByte
If you're comfortable keeping up a site that's using software with known security vulnerabilities, then that's your call I guess.
Fair point. I've applied the applicable security patches over the past two years, and will rename my admin directory .. I think I'm keeping up with security concerns.
Quote:
Originally Posted by
DrByte
Wonderful.. shame I didn't see that thread before. I've changed my class.base.php and everything seems to be working well. It's very refreshing working with notifiers and not having to hack core code! :) I'm having to re-write some of my work to make it work in this new way, but I'm sure I'll be left with a cleaner, better, shinier final product.
A clarification on http://www.zen-cart.com/wiki/index.p...er_is_watching would be nice, to make it clear why 1.3.8 code had to use $_SESSION['cart']->attach instead of $this->attach, referencing the changed base class implementation. I don't seem to be able to create a user account to edit the wiki.
Thanks again.
-
Re: Use Of Notifiers - How To
Auto load notifier:
I had this working loading the config. and init_ files. But since init_canonical it loaded at point 161 and this autoload at 175, would be 2 less files.
However, I'm not getting this right.
I've also tried to use function updateNotifyInitCanonicalParamWhitelist(&$class, $eventID,$paramsArray = array()), but that would be for the update function (?)
two more files , two less files is not the issue, but I would like to understand how this works.
PHP Code:
class zcObserverBookxCanonical extends base
{
public function __construct()
{
$this->attach($this, array(
'NOTIFY_INIT_CANONICAL_PARAM_WHITELIST',
'NOTIFY_INIT_CANONICAL_DEFAULT'));
}
//$zco_notifier->notify ('NOTIFY_INIT_CANONICAL_PARAM_WHITELIST', $current_page, $excludeParams, $keepableParams, $includeCPath);
function updateNotifyInitCanonicalParamWhitelist(&$class, $eventID, $current_page, &$excludeParams, &$keepableParams, $includeCPath)
{
global $keepableParams; // ??
pr($keepableParams, '$paramsArray');
$keepableParams[] = 'bookx_publisher_id';
$keepableParams[] = 'bookx_genre_id';
$keepableParams[] = 'bookx_author_id';
$keepableParams[] = 'bookx_author_type_id';
$keepableParams[] = 'bookx_author_type_id';
$keepableParams[] = 'bookx_imprint_id';
$keepableParams[] = 'bookx_series_id';
}
thanks
-
Re: Use Of Notifiers - How To
Quote:
Originally Posted by
mesnitu
Auto load notifier:
I had this working loading the config. and init_ files. But since init_canonical it loaded at point 161 and this autoload at 175, would be 2 less files.
However, I'm not getting this right.
I've also tried to use function updateNotifyInitCanonicalParamWhitelist(&$class, $eventID,$paramsArray = array()), but that would be for the update function (?)
two more files , two less files is not the issue, but I would like to understand how this works.
PHP Code:
class zcObserverBookxCanonical extends base
{
public function __construct()
{
$this->attach($this, array(
'NOTIFY_INIT_CANONICAL_PARAM_WHITELIST',
'NOTIFY_INIT_CANONICAL_DEFAULT'));
}
//$zco_notifier->notify ('NOTIFY_INIT_CANONICAL_PARAM_WHITELIST', $current_page, $excludeParams, $keepableParams, $includeCPath);
function updateNotifyInitCanonicalParamWhitelist(&$class, $eventID, $current_page, &$excludeParams, &$keepableParams, $includeCPath)
{
global $keepableParams; // ??
pr($keepableParams, '$paramsArray');
$keepableParams[] = 'bookx_publisher_id';
$keepableParams[] = 'bookx_genre_id';
$keepableParams[] = 'bookx_author_id';
$keepableParams[] = 'bookx_author_type_id';
$keepableParams[] = 'bookx_author_type_id';
$keepableParams[] = 'bookx_imprint_id';
$keepableParams[] = 'bookx_series_id';
}
thanks
Couple of things. For your observer to trigger, it needs to be loaded into the workspace before the notifier that would trigger it. So, if your notifier is triggered at load point 161, then somehow your observer needs to be loaded before then. It could possibly loaded at load point 161 if it can be brought in before the core code's loading of the asociated file. Better to just pick something convenient before then and give yourself some expansion room.
Then because the variable keepableParams is passed as an editable variable, it is not needed to bring the same variable from the global space at least for ZC 1.5.3 and higher. There are some other things that would need to be done to populate that variable in the parameter list if working with an older version of ZC.
Besides that I assume the function pr is some debug utility that has been added allowing you to retrieve the specified data?
-
Re: Use Of Notifiers - How To
Quote:
Originally Posted by
mc12345678
Couple of things. For your observer to trigger, it needs to be loaded into the workspace before the notifier that would trigger it. So, if your notifier is triggered at load point 161
So, in this case is not going to work ( if I'm understanding right)
Canonical is loaded at 161
/**
* point 161 was selected specifically based on dependancies
*/
From the init_observers.php:
* This fires at AutoLoader point 175, so all previously-processed system dependencies are in place.
* If you need an observer class to fire at a much earlier point so it fires before other system processes, you'll need to add your own auto_loaders/config.yyyyy.php file with relevant rules to load those observers.
ps: yes, ignore de pr
-
Re: Use Of Notifiers - How To
Quote:
Originally Posted by
mesnitu
So, in this case is not going to work ( if I'm understanding right)
Canonical is loaded at 161
/**
* point 161 was selected specifically based on dependancies
*/
From the init_observers.php:
* This fires at AutoLoader point 175, so all previously-processed system dependencies are in place.
* If you need an observer class to fire at a much earlier point so it fires before other system processes, you'll need to add your own auto_loaders/config.yyyyy.php file with relevant rules to load those observers.
ps: yes, ignore de pr
You are correct, you will need to add an includes/init_includes file that loads your observer before 161 and not be able to use the auto load observer when working with a default ZC store. There are examples in that directory that you could use as a template.
If you only need one of the notifiers to be picked up early you could split the two from the file. If they need to interact with each other then it may make sense for them both to be loaded early, etc...
-
Re: Use Of Notifiers - How To
ok! thanks for the reply!