Forums / Upgrading from 1.3.x to 1.3.9 / Order class notifiers

Order class notifiers

Locked

Started by cjpinder on 13 Apr 2010, 10:38 AM · Views: 1,549

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
13 Apr 2010, 10:38 AM
#1
cjpinder avatar

cjpinder

Totally Zenned

Join Date:
Apr 2007
Location:
Herts. UK
Posts:
893
Plugin Contributions:
0

Order class notifiers

In /includes/classes/order.php the notifiers have been changed from using...

$zco_notifier->notify();
```...to...
```php
$this->notify();
```This makes the code look cleaner but doesn't it make the notifiers unusable? My understanding is that to use these notifiers you would now have to attach the observers to the order object. However the order object isn't created until after all the auto-loaders have finished loading.

Am I missing something? Is there now a way to attach an observer to the order object, or even the order classs?

Regards,
Christian.
13 Apr 2010, 10:51 AM
#2
drbyte avatar

drbyte

Sensei

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

Re: Order class notifiers

That's very intentional, as it now makes the notifiers in the order class actually work :blush:

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

13 Apr 2010, 10:57 AM
#3
wilt avatar

wilt

Oji-san

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

Re: Order class notifiers

Just to expand on the above.

When you do something like

$this->attach($this, array('NOTIFY_ORDER_CART_ADD_PRODUCT_LIST'));

you are not actually attaching to the class the notifier exists in, you are merely setting a callback to your observer for when that notifier happens.

It is only when the notifier happens that the class that the notifier exists in is passed to your observer classes update method.

13 Apr 2010, 11:21 AM
#4
cjpinder avatar

cjpinder

Totally Zenned

Join Date:
Apr 2007
Location:
Herts. UK
Posts:
893
Plugin Contributions:
0

Re: Order class notifiers

Hi,

Thanks for the replies. Sorry if I'm being a bit stupid but I still don't quite understand. I'm used to attaching notifiers like...

$_SESSION['cart']->attach($this, array('NOTIFIER_CART_ADD_CART_END'));
$zco_notifier->attach($this, array('NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION'));
```How would I now do a similar thing with the notifiers in the order class code?

Do I just create my own order object and use that to attach the notifiers?

Many thanks,
Christian.
13 Apr 2010, 12:15 PM
#5
drbyte avatar

drbyte

Sensei

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

Re: Order class notifiers

Example:
In the order class, there's a notifier point NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL.
So, to hook it, I simply use:```
$this->attach($this, array('NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL'));

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

13 Apr 2010, 12:18 PM
#6
drbyte avatar

drbyte

Sensei

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

Re: Order class notifiers

You'll use the $this->attach() method to hook notifier points that are inside a class.
You'll use the $zco_notifier->attach() method to hook notifier points that are NOT inside a class.

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

13 Apr 2010, 12:35 PM
#7
wilt avatar

wilt

Oji-san

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

Re: Order class notifiers

Note also,

Attaching to the cart class is slightly different because of the fact that the instantiated object is stored in the session.

13 Apr 2010, 12:50 PM
#8
cjpinder avatar

cjpinder

Totally Zenned

Join Date:
Apr 2007
Location:
Herts. UK
Posts:
893
Plugin Contributions:
0

Re: Order class notifiers

DrByte:

You'll use the $this->attach() method to hook notifier points that are inside a class.
You'll use the $zco_notifier->attach() method to hook notifier points that are NOT inside a class.

wilt:

Attaching to the cart class is slightly different because of the fact that the instantiated object is stored in the session.

Thank you both for your help. I think it was the cart class example that was confusing me. I assumed the other observers had to be attached to specific instantiated objects.

Many thanks,
Christian.