Forums / General Questions / Use Of Notifiers - How To

Use Of Notifiers - How To

Sticky

Views: 81,115

Results 21 to 38 of 38
20 Aug 2007, 5:33 PM
#21
stevekim avatar

stevekim

New Zenner

Join Date:
Apr 2007
Location:
Los Angeles, CA
Posts:
44
Plugin Contributions:
0

Use Of Notifiers - How To

DrByte:

Try using this:```
$_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.
 

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

**www.ToolUSA.com** - Hand Tools for Jewelers, Crafters, Garden and Households. Also offers Safety Items and Scout Gadgets.
**www.OfficialCap.com** - MLB Licensed Caps by New Era and NFL Licensed Caps by Reebok.

1 Aug 2008, 7:23 PM
#22
chaoscube avatar

chaoscube

New Zenner

Join Date:
Jul 2008
Location:
Bald Knob, AR
Posts:
18
Plugin Contributions:
0

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?

My Zen Cart Store: Outdoor Survival Gear Shop

4 Aug 2008, 6:58 PM
#23
chaoscube avatar

chaoscube

New Zenner

Join Date:
Jul 2008
Location:
Bald Knob, AR
Posts:
18
Plugin Contributions:
0

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?

My Zen Cart Store: Outdoor Survival Gear Shop

5 Aug 2008, 5:16 PM
#24
stevekim avatar

stevekim

New Zenner

Join Date:
Apr 2007
Location:
Los Angeles, CA
Posts:
44
Plugin Contributions:
0

Re: Use Of Notifiers - How To

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?main_page=product_contrib_info&products_id=756

It's quite incomplete, but you can probably reference it to complete yours.

Steve.

**www.ToolUSA.com** - Hand Tools for Jewelers, Crafters, Garden and Households. Also offers Safety Items and Scout Gadgets.
**www.OfficialCap.com** - MLB Licensed Caps by New Era and NFL Licensed Caps by Reebok.

28 May 2009, 2:27 AM
#25
calixto avatar

calixto

New Zenner

Join Date:
Mar 2009
Posts:
30
Plugin Contributions:
0

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?

28 May 2009, 3:10 AM
#26
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

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.

.
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.

28 May 2009, 5:28 AM
#27
calixto avatar

calixto

New Zenner

Join Date:
Mar 2009
Posts:
30
Plugin Contributions:
0

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

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

28 May 2009, 9:06 PM
#28
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,927
Plugin Contributions:
3

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

$autoLoadConfig[90][] = array('autoType'=>'class',
                              'loadFile'=>'observers/class.freeProduct.php');
$autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
                              'className'=>'freeProduct',

however things will work if you use

$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

29 Nov 2010, 3:22 AM
#29
neekfenwick avatar

neekfenwick

New Zenner

Join Date:
Feb 2009
Posts:
101
Plugin Contributions:
0

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(....)".

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

29 Nov 2010, 6:14 AM
#30
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

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?

.
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.

30 Nov 2010, 4:57 AM
#31
neekfenwick avatar

neekfenwick

New Zenner

Join Date:
Feb 2009
Posts:
101
Plugin Contributions:
0

Re: Use Of Notifiers - How To

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

30 Nov 2010, 5:31 AM
#32
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Use Of Notifiers - How To

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.

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

.
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.

1 Dec 2010, 10:04 AM
#33
neekfenwick avatar

neekfenwick

New Zenner

Join Date:
Feb 2009
Posts:
101
Plugin Contributions:
0

Re: Use Of Notifiers - How To

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.

DrByte:

http://www.zen-cart.com/forum/showthread.php?t=150127

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.php/Developers_API_Tutorials#Notifiers:_Big_Brother_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.

28 Jan 2019, 10:01 AM
#34
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

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.

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

“Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison

28 Jan 2019, 1:01 PM
#35
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Use Of Notifiers - How To

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.

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?

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

28 Jan 2019, 2:50 PM
#36
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: Use Of Notifiers - How To

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

“Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison

28 Jan 2019, 4:08 PM
#37
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Use Of Notifiers - How To

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...

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

28 Jan 2019, 9:22 PM
#38
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: Use Of Notifiers - How To

ok! thanks for the reply!

“Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison