Frage

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:

  • When logged as a registered user - the observer method is called as expected
  • When checking out as a guest user, the "sales_order_payment_pay" Event is fired when the "payment transaction" (Mastercard, VISA) was successful" and a second time after clicking the "return Button" to get back to the Magento Shop. because this behavior the E-Mail is sent twice.

Is there a way to prevent the observer method from beeing executed twice?

Kind Regards, Bertie

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top