Forums / General Questions / Specific notifier question - experts please!

Specific notifier question - experts please!

Locked

Views: 4,545

Results 1 to 20 of 36
This thread is locked. New replies are disabled.
6 Jan 2007, 6:55 PM
#1
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Specific notifier question - experts please!

I'm dumbfounded here... I created some custom functions that are triggered when the following event notifier is triggered:

NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS

The functions do some extra stock management duties after an order is completed and I thought this would be the best notifier to use. And it works fine... so long as the customer pays by cheque or money order. If they choose PayPal, it never gets triggered and I can't figure out why.

Anyone have any ideas? Or if someone is very familiar with the notifiers... is there a better one for me to use? I want my functions to happen right when the stock is decremented at the end of a purchase.

Thanks.

  • Steven
6 Jan 2007, 7:53 PM
#2
wilt avatar

wilt

Oji-san

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

Re: Specific notifier question - experts please!

Hi,

The problem occurs because paypal IPN does not use the standard checkout process to create orders. (as the order is only created when the ipn_main_handler code is called by paypal)

In a sense this is our fault, in that it would have been better to put the notifier in the order class method itself. Rarther than in checkout process.

Fixing that is a little bit more difficult, as it needs to be done in a way that won't affect upgrades and suits your purpose.

what should work for u is to add a notifier to the order class. At line 860 directly after

$order_total_modules->apply_credit();//ICW ADDED FOR CREDIT CLASS SYSTEM

e.g.

$this->notify('NOTIFY_ORDER_AFTER_ORDER_CREATE_ADD_PRODUCTS');

I'll ensure this is added to our SVN so it does not break future code.

U can then use the new notifier instead of the one u were using. This should then work with paypal ipn.

6 Jan 2007, 8:01 PM
#3
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Specific notifier question - experts please!

Thanks wilt!

Will this still work as expected if the customer ends up bailing on the order during the PayPal transaction? I want to execute my code if AND ONLY IF the order gets "completed"... that is, an order number is generated and the order is commited to the DB.

Thanks again.

  • Steven
6 Jan 2007, 8:10 PM
#4
wilt avatar

wilt

Oji-san

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

Re: Specific notifier question - experts please!

yes. The function is only ever called when processing a completed order, whether ftom the checkout_process module for the majority of payment methods, or from paypal IPN handler.

6 Jan 2007, 9:15 PM
#5
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Specific notifier question - experts please!

Thanks again!

One more question... does this become obsolete in 1.3.7?? I saw one of the "features" was no longer relying on the IPN send back?? I could very well be interpreting what that means incorrectly.

  • Steven
7 Jan 2007, 1:38 AM
#6
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Specific notifier question - experts please!

actually... that's not right either :)

I tested it and it didn't work at all. Changing it to this seems to work (at least for cheque/money order - still haven't tested for PP yet)

$zco_notifier->notify('NOTIFY_ORDER_AFTER_ORDER_CREATE_ADD_PRODUCTS');
  • Steven
7 Jan 2007, 3:30 AM
#7
drbyte avatar

drbyte

Sensei

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

Re: Specific notifier question - experts please!

$this->notify should work fine from within the order class, as the notifier components are inherited from the base class.
Not sure why you're having a problem with that ...

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

7 Jan 2007, 3:33 AM
#8
drbyte avatar

drbyte

Sensei

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

Re: Specific notifier question - experts please!

s_mack:

Thanks again!

One more question... does this become obsolete in 1.3.7?? I saw one of the "features" was no longer relying on the IPN send back?? I could very well be interpreting what that means incorrectly.

  • Steven

The IPN is not totally obsolete in 1.3.7, as even with Express Checkout it is used to process notifications related to events that occur within your PayPal account, such as echeck clearance notices (which also mark the order as Processing and releases downloads etc) and manual accepting of payments from unconfirmed addresses or non-standard currencies, etc.
And, the original PayPal IPN payment module also still relies on the IPN postback exclusively for its ability to function.

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

7 Jan 2007, 4:42 PM
#9
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Specific notifier question - experts please!

Thanks Dr.B

I don't know why $this doesn't work if it should... but it doesn't on mine. And if it should work, then why does EVERY reference to "notify" in that file have $zco_notifier-> in front of it rather than $this-> ?

Even though I've come a LONG way, its not like I ever read the PHP book from cover to cover :) And I admit I really don't understand those -> references and how they work (or even what they are called). I just see patterns and try to emulate them when it comes to those, and I saw all the other ones were called with a $zco_notifier.

Actually, while I'm on it, if you could give me some keywords to search for regarding the -> things, I'd appreciate it because I'd like to learn. Googling "$this->" doesn't really get me much :)

  • Steven
7 Jan 2007, 4:43 PM
#10
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Specific notifier question - experts please!

Hmm... this just crossed my mind. Is it because of the way I've set up my observer that it doesn't do anything??

class stockManager extends base {
	function stockManager() {
    	global $zco_notifier;
		$zco_notifier->attach($this, array('NOTIFY_ORDER_AFTER_ORDER_CREATE_ADD_PRODUCTS', 'NOTIFY_HEADER_END_SHOPPING_CART', 'NOTIFY_HEADER_START_CHECKOUT_SHIPPING', 'NOTIFY_HEADER_START_CHECKOUT_CONFIRMATION'));
	}
	function update(&$callingClass, $notifier, $paramsArray) {
		if ($notifier ==  'NOTIFY_ORDER_AFTER_ORDER_CREATE_ADD_PRODUCTS') { ...
  • Steven
7 Jan 2007, 6:49 PM
#11
drbyte avatar

drbyte

Sensei

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

Re: Specific notifier question - experts please!

I defer to the expert ... oh wilt ...

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

7 Jan 2007, 7:56 PM
#12
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,730
Plugin Contributions:
56

Re: Specific notifier question - experts please!

-> accesses a member (data or function) of an object.
An object is an instance of a class.
$this-> means "using the object that is running this function,
access the specified data or function member."

Scott

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

7 Jan 2007, 8:18 PM
#13
wilt avatar

wilt

Oji-san

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

Re: Specific notifier question - experts please!

Hi,

My fault. You are right, that the call from the order class should use $zco_notifier.

the confusion arises because generally we want to attach to an event fired by an object, and where possible use the native object (in this case the order class) to do that,

Unfortunately the order class will never be available to observer classes (due to it only being instantiated on a few pages, and even then only after observer classes have been instantiated) so in this case we have to rely on the global $zco_notifier class to do our work for us.

The pattern used to build the observer/notifier system is really better suited to PHP5 than PHP4, hence the reason for shoehorning things using the extra $zco_notifier class.

HTH

7 Jan 2007, 9:11 PM
#14
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Specific notifier question - experts please!

Great, thanks for that Wilt!

Amazingly, I still haven't tested it with PayPal :) So I still don't know if this fixed my original problem. I always do the changes on my local site first before commiting it to my live site... and I haven't yet figured out a good way to test PP from my local site.

Someone (I think it was Dr.B) gave me some very helpful suggestions about making my local site available to the outside world... but I tried it and it just didn't work :( Not sure why. Got the router set up, the firewall, and the no-ip.org address all done. I can ping the address from another computer and I can even connect on port 80 but I don't see my site (I'm using triad2apache) so I'm waiting for some help from their support forum.

In the meantime, I think we can consider this done! Thanks a lot for your help!

  • Steven
7 Jan 2007, 9:21 PM
#15
wilt avatar

wilt

Oji-san

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

Re: Specific notifier question - experts please!

Unfortuantely, I still think you are going to have problems with Paypal IPN. The problem now is that the IPN handler code uses a custom application_top and not the standard init_system based application_top code.

This means that no observer classes will ever get instantiated :(

I'll try and think of an easy workaround that does not involve hacking core code, if I can

7 Jan 2007, 9:26 PM
#16
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Specific notifier question - experts please!

Oh great :(

I just ran into another problem too... when I was relying on NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS, I had the luxury of knowing the order_id because it is passes as a session variable in the checkout process ($_SESSION['order_number_created']) but the order class doesn't do that. I need the order_id for my function.

Basically, all I need is the order id and a trigger. Thanks again for continuing to help.

  • Steven
7 Jan 2007, 11:22 PM
#17
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Specific notifier question - experts please!

So hey! I wonder...

Can I just tap into the the header file for the checkout_success page? The user goes there whether they use paypal or otherwise, so would that work? That page also "knows" the order_id value since it is reported to the user > Your Order Number is: 645

Are there any circumstances where the order would be generated in the system but where that page would not be loaded? Because that would be very bad. Or any other pitfalls you could imagine?

  • Steven
7 Jan 2007, 11:24 PM
#18
drbyte avatar

drbyte

Sensei

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

Re: Specific notifier question - experts please!

In the case of PayPal IPN, that order number is not reliable on the checkout_success page ... it's only correct if PayPal "instantly" posts the results back and they are successfully processed before the page is drawn.

PayPal Express Checkout would be correct though.

I suppose you could look at loading the whole notifier infrastructure via the ipn_application_top ...

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

7 Jan 2007, 11:50 PM
#19
wilt avatar

wilt

Oji-san

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

Re: Specific notifier question - experts please!

Just to expand on Drbytes post. when a customer uses paypal IPN they are taken to the paypal website. In a perfect world, as soon as they click on the PAY button an IPN callback will be generated and if the correct options are set they will be returned to the Zen cart site and checkout success will be invoked.

However its never a perfect world. Load on the paypal servers can mean the IPN call back might happen immediately, or not for minutes, even hours. Settings and other network problems mean that u can not guarantee that an IPN user will even be returned to checkout success,

As drbyte suggests, at the moment it probably means u will need to hack the ipn application_top to load and instantiate your observer class if you ever want your code to work with IPN,

7 Jan 2007, 11:50 PM
#20
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Specific notifier question - experts please!

Right. As well, I guess there's a good chance the customer never clicks the "return to merchant" link... duh :)

So that won't work.

About your last statement... is that something you would be willing to do? I don't mean for me... I'm sure I can figure it out... but I mean for future releases. I'm really trying to not mess with core code here. I wish I discovered this problem 5 months ago when I started my stockManager contrib... it works so well except for this PayPal problem that I didn't forsee.

Oh well, what's past is past.

Maybe I'll look at the PP EC option. As it is, I don't like it for my store at all... I like what it is supposed to do, but with my layout it becomes confusing. So I'll have to customize that and then we're back at messing with core code again :(

Isn't there anywhere common to all payments in the checkout system that is post-DB?

  • Steven