<p>I've built a plugin which uses it's own events before, I guess the way to do it would be the same for separate plugins, however this is untested for your use case.</p>

<p><em>This should go in your plugin service</em></p>

<pre><code>// Import the event from the other plugin
Craft::import('plugins.otherPluginHandle.events.OtherPluginEvent');

/Initialise the plugins event and pass whatever is required to it.
$event = new OtherPluginEvent($this, array('request' =&gt; $request));

// Raise it.
$this-&gt;raiseEvent('OtherPluginEvent', $event);
</code></pre>

<p>Again I haven't tried this from the context of calling another plugins event, but that is what I do from a plugins own event...</p>

CC BY-SA 3.0
2017-04-21T15:38:15.810Z
2017-04-21T15:38:15.810Z
Alec Ritson
<p>I have created an Adjuster which is attached to <code>commerce_lineItems.onPopulateLineItem</code>.</p>

<p>The discount criteria is based on validation of a completely separate coupon API, so I created a permission-less user group in order to allow my client to continue using the Commerce Discounts UI. In my adjuster, I had to override the the <code>matchLineItem()</code> method in order to bypass the <code>$discount-&gt;allGroups</code> check. I'm using Craft's <code>httpSession</code> to persist the criteria through the checkout process.</p>

<p>Everything works fine, however if the user adds a product to the cart and THEN authenticates, the discount doesn't get applied until they either a.) update the cart or b.) raise the <code>commerce_lineItems.onPopulateLineItem</code> event again.</p>

<p>I've tried adding <code>craft()-&gt;commerce_orders-&gt;saveOrder($cart)</code> at the end of a successful API call, however that doesn't seem to trigger the event.
Is there another event I can use that will also update the cart or can I somehow raise an already declared <code>CEvent</code>? I've tried everything I know including hitting <code>actionUpdateCart()</code> with Guzzle!</p>

<p>I know this is a very edge case situation, so just to (briefly) illustrate I've added a portion of my base plugin below.</p>

<pre><code>public function init()
{
    require_once __DIR__ .'/vendor/autoload.php';
    $this-&gt;check_membership();
    /*
     Load Premium Member Adjusters if $is_premium_member is true
    */
    craft()-&gt;on('commerce_lineItems.onPopulateLineItem', function($event){

        $lineItem    = $event-&gt;params['lineItem'];

        if ($lineItem-&gt;purchasable instanceof Commerce_VariantModel){
            if ($this-&gt;is_premium_member) {
                $this-&gt;adjusters = [
                  599 =&gt; new WorkshopAdjuster
                ];
            }
        }
    });
}
</code></pre>

<plugin-craftcommerce><events><hook><extends><adjusters>
Can a plugin manually raise another plugin's Event?
# Can a plugin manually raise another plugin's Event?

(Asked by: username_0 on 2017-04-21)

I have created an Adjuster which is attached to commerce_lineItems.onPopulateLineItem.
The discount criteria is based on validation of a completely separate coupon API, so I created a permission-less user group in order to allow my client to continue using the Commerce Discounts UI. In my adjuster, I had to override the the matchLineItem() method in order to bypass the $discount->allGroups check. I'm using Craft's httpSession to persist the criteria through the checkout process.
Everything works fine, however if the user adds a product to the cart and THEN authenticates, the discount doesn't get applied until they either a.) update the cart or b.) raise the commerce_lineItems.onPopulateLineItem event again.
I've tried adding craft()->commerce_orders->saveOrder($cart) at the end of a successful API call, however that doesn't seem to trigger the event.
Is there another event I can use that will also update the cart or can I somehow raise an already declared CEvent? I've tried everything I know including hitting actionUpdateCart() with Guzzle!
I know this is a very edge case situation, so just to (briefly) illustrate I've added a portion of my base plugin below.
public function init()
{
    require_once __DIR__ .'/vendor/autoload.php';
    $this->check_membership();
    /*
     Load Premium Member Adjusters if $is_premium_member is true
    */
    craft()->on('commerce_lineItems.onPopulateLineItem', function($event){

        $lineItem    = $event->params['lineItem'];

        if ($lineItem->purchasable instanceof Commerce_VariantModel){
            if ($this->is_premium_member) {
                $this->adjusters = [
                  599 => new WorkshopAdjuster
                ];
            }
        }
    });
}

**Tags:** plugin-craftcommerce, events, hook, extends, adjusters


---

## 1 answers

### Answer by username_1 on 2017-04-21. Score: 1 | Accepted answer

I've built a plugin which uses it's own events before, I guess the way to do it would be the same for separate plugins, however this is untested for your use case.
This should go in your plugin service
// Import the event from the other plugin
Craft::import('plugins.otherPluginHandle.events.OtherPluginEvent');

/Initialise the plugins event and pass whatever is required to it.
$event = new OtherPluginEvent($this, array('request' => $request));

// Raise it.
$this->raiseEvent('OtherPluginEvent', $event);

Again I haven't tried this from the context of calling another plugins event, but that is what I do from a plugins own event...


---

