How can I get the current user who purchased a product from the onOrderComplete event? I have a plugin that is listening to the onOrderComplete event within commerce. I am able to get the email address like this:

craft()-&gt;on('commerce_orders.onOrderComplete', function (Event $event) {
    $event-&gt;params['order']-&gt;email;  // name@email.com

});


I can see the Id in the log, but since I'm in the order class, I'm not sure how to get to it. I can see customerId:

$event-&gt;params['order']-&gt;customerId; // 3


But I've noticed the customerId and the userId are different. I need to be able to get the logged in userId vs. the customerId

When I try getting just the id, I get the product id back (Which is what I would expect).

$event-&gt;params['order']-&gt;id;  // 123


To relate to the twig side it would be something like this (obviously won't work):

$event-&gt;params['order']['currentUser']-&gt;id;  // 12


Here is a part of the log: 

...
[_attributes:Craft\BaseModel:private] =&gt; Array
(
    [enabled] =&gt; 1
    [archived] =&gt; 0
    [locale] =&gt; en_us
    [localeEnabled] =&gt; 1
    [itemTotal] =&gt; 375
    [baseDiscount] =&gt; 0
    [baseShippingCost] =&gt; 0
    [totalPrice] =&gt; 375
    [totalPaid] =&gt; 375.00
    [billingAddressId] =&gt; 122
    [shippingAddressId] =&gt; 123
    [paymentMethodId] =&gt; 1
    [customerId] =&gt; 3
    [id] =&gt; 12   //  &lt;-- This guy right here
    [orderStatusId] =&gt; 1
...
Since this is happening from the onOrderComplete event, the easiest way to get the currently logged in user is with UserSessionService::getUser():



$user = craft()-&gt;userSession-&gt;getUser();


Alternatively, if you want to go through the actual Commerce_OrderModel that was passed as a parameter on the event, you can do this:

$user = $event-&gt;params['order']-&gt;getCustomer()-&gt;getUser();


Either way, it’s a good idea to verify that $user gets set to something, just in case:

if ($user) {
    // ...
}