1
votes

I am trying to fire an observer code upon specific event which will write transactions from Magento into other system after the successful online payment such as Paypal.

Following is my requirement:

(1) Upon on successful payment on paypal with Paypal standard, Magento shall fire an observer.

(2) Magento shall load the page checkout success page which will show order placed.

(3) Magento shall show “Complete” as an order status in admin area.

(4) Magento shall notify user.

(5) Magento shall show order into recent orders and order history for user logged on on front end.

(6) Invoice for an order shall be generated.

When I use event “sales_order_payment_pay”, Magento successfully fires an observer and writes the transaction into external system (requirement 1) and also load the checkout page (requirement 2) but requirements (3), (4), (5) and (6) are not met. Order status is in payment pending. Invoice is not generated. Users are not notified. Order does not appear in order history or recent orders for user.

public function myObserver (Varien_Event_Observer $observer) 
{ 
  $order_id = $observer->getPayment()->getOrder()->getId(); 

“""""""" REST OF THE CODE HERE “""""""" 
} 

When I use event “checkout_controller_onepage_success_action”, Magento DOES NOT fire an observer, Checkout Success Page is BLANK whereas requirements (3), (4), (5) and (6) are met. How would I get the event to fire and the page to load?

public function myObserver (Varien_Event_Observer $observer) 
{ 
 $order_id = $observer->getEvent()->getOrder()->getId(); 

  “""""""" REST OF THE CODE HERE “""""""" 
} 

When I use event “controller_action_layout_render_after_checkout_onepage_success”, Magento DOES NOT fire an observer. In this case, all other requirements are met including (2). How would I get the event to fire?

public function myObserver (Varien_Event_Observer $observer) 
{ 
 $order_id = $observer->getEvent()->getOrder()->getId(); 

 “""""""" REST OF THE CODE HERE “""""""" 
} 

I am interested to know if observer needs “exit ;” or “return true ;” statements at the end of the code.

Will someone please point me here in the right direction?

2

2 Answers

0
votes

Listening to Magento events should not impact standard Magento functionality. That is why they are there. Unless your code stops the PHP process with a Fatal error.

Have you enabled Developer mode and display of errors? (http://alanstorm.com/magento_exception_handling_developer_mode). Maybe there is an Error in your code stopping other events from firing.

Your code looks ok as far as you have posted, but I'm not sure there is an ID field in the Order class and getId() could return null, I think you should use getEntityId() or getIncrementId() if you want a Order ID (Magento API order id vs. increment id).

0
votes

First of all make sure your event is getting fired. Debug it by dieing it

public function myObserver (Varien_Event_Observer $observer) 
{ 
  echo "hello";die;
}

check if this work. If not plese check your config file. hopefully you are using the right event. Please see if you are using onepage or onestep they both have different events.

If this works check if you are getting the order id Try this code to get last ordered item details.

$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();        
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);