<p>You don't show what code you're trying to use to access the parameters, but something like this should work from your main plugin class:</p>

<pre><code>public function init()
{
    parent::init();

    craft()-&gt;on('commerce_emails.beforeSendEmail', function($event) {
        $params = $event-&gt;params;

        $craftEmail = $params['craftEmail'];
        $commerceEmail = $params['commerceEmail'];
        $order = $params['order'];
        $orderHistory = $params['orderHistory'];

        ...
    });
}
</code></pre>

CC BY-SA 3.0
2017-06-07T08:29:01.973Z
Hi Brad, turns out I was looking at the basic emails event `email.onBeforeSendEmail` and not the one for commerce `commerce_emails.beforeSendEmail` (which by the way is not listed on the events reference page: https://craftcommerce.com/docs/events-reference). Thanks again Brad.
ijust
CC BY-SA 3.0
2017-06-06T17:21:31.923Z
2017-06-06T17:21:31.923Z
Brad Bell
<p>I'm trying to access the <code>order</code> and <code>orderHistory</code> model via <code>onBeforeSendEmail</code> event. I can see that in <code>Commerce_EmailsService.php</code> file on line 311 the event is created with those params and passed to <code>onBeforeSendEmail</code>, but when I try to access them from my plugin, they are not there. I thought they would be available in the <code>variables</code> param, but they are not (or I'm doing something wrong here).</p>

<p>Does anyone know if/how I can access those models from <code>onBeforeSendEmail</code> event?</p>

<plugin-craftcommerce><events>
onBeforeSendEmail event triggered from Commerce_EmailsService
# onBeforeSendEmail event triggered from Commerce_EmailsService

(Asked by: username_0 on 2017-06-06)

I'm trying to access the `order` and `orderHistory` model via `onBeforeSendEmail` event. I can see that in `Commerce_EmailsService.php` file on line 311 the event is created with those params and passed to `onBeforeSendEmail`, but when I try to access them from my plugin, they are not there. I thought they would be available in the `variables` param, but they are not (or I'm doing something wrong here).

Does anyone know if/how I can access those models from `onBeforeSendEmail` event?

**Tags:** plugin-craftcommerce, events

---

## 1 answers

### Answer by username_1 on 2017-06-06. Score: 2 | Accepted answer

You don't show what code you're trying to use to access the parameters, but something like this should work from your main plugin class:
public function init()
{
    parent::init();

    craft()->on('commerce_emails.beforeSendEmail', function($event) {
        $params = $event->params;

        $craftEmail = $params['craftEmail'];
        $commerceEmail = $params['commerceEmail'];
        $order = $params['order'];
        $orderHistory = $params['orderHistory'];

        ...
    });
}

> **Comments:**
> **username_0**: Hi Brad, turns out I was looking at the basic emails event `email.onBeforeSendEmail` and not the one for commerce `commerce_emails.beforeSendEmail` (which by the way is not listed on the events reference page: https://craftcommerce.com/docs/events-reference). Thanks again Brad.  

---

