Get customer object on an event

I’m trying to createan observer on the following event.:
‘sales_order_payment_pay’.

However according to magento doc
http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/magento_events

I don’t have so much parameters avalaible on this event..

Do you have any idea how I could retrieve the customer object (i would need info such as customer id and customer email)?

Thanks for your feedback and anyway I wish you a nice day,

Anselme

2 thoughts on “Get customer object on an event”

  1. This event does expose the payment object, so you should be able to chain off of that to get the object you want:

    public function yourObserverFunction($event) {
        $payment = $event['payment'];
        $customer = $payment->getOrder()->getCustomer();
        // ... do something useful
    }
    

    Generally objects in Magento can be chained like this, and now your code doesn’t rely on the event being triggered from a customer session (which is not a good assumption anyway).

    Hope that helps!

    Thanks,
    Joe

  2. Every event exposes different objects inside of the $observer object that is passed around. In Magento you can often get a lot of stuff by referring to any number of objects that are in the request or session. In this case there is a customer/session object (Mage_Customer_Model_Session) which has the customer attached.

    if(Mage::getSingleton('customer/session')->isLoggedIn()){
      Mage::getSingleton('customer/session')->getCustomer();
    }
    

Leave a Reply

Your email address will not be published. Required fields are marked *