Reputation: 165
i am using Magento 1.5.1.0 and the "mPAY24 Payment Gateway" Extension. I have an Observer class for the event "sales_order_payment_pay" sending notification E-Mails to the manufacturer of the items.
This solution has some strange behavour:
Is there a way to prevent the observer method from beeing executed twice?
Kind Regards, Bertie
Upvotes: 2
Views: 2919
Reputation: 166076
No. As a client (vs. system) developer, you don't get to decide when an event fires.
Here's some general jumping off points for solving this problem:
Instead, you need to change the behavior of your observer method. Instead of blindly firing off an email in the observer method, you'll need to examine the state of the system and/or the objects in the $observer->getData()
array, and determine if the event was fired after a payment transaction, or if it was fired after clicking the "clicking the return Button".
If it's the former, send your email as expected. If it's the later, just return
from the observer method and/or skip the email with a conditional.
If this isn't your own observer method that's the problem (it's a core observer or a an observer that's part of the module), use a class rewrite to replace the observer method with your own. If you detect the correct state, call the return parent::observerMethodName
, if it's the "clicking the return Button" state, just return null and skip calling the parent.
If the observer was setup with a hard-coded class name (not a class alias), then you'll need to use a code pool override to change the behavior of your method.
Upvotes: 1