2

I'm creating a plugin called "Membership" to handle user subscriptions through Stripe. I want to use SproutEmail to handle notification.

I've created a custom event as per the Sprout instructions:

<?php
namespace Craft;

class SproutEmail_SubscribeEvent extends SproutEmailBaseEvent
{
    /**
     * Returns the qualified event name to use when registering with craft()->on
     *
     * @return string
     */
    public function getName()
    {
        return 'membership.onSubscribe';
    }

    /**
     * Returns the event title to use when displaying a label or similar use case
     *
     * @return string
     */
    public function getTitle()
    {
        return Craft::t('When a user subscribes to a membership plan.');
    }

    /**
     * Returns a short description of this event
     *
     * @return string
     */
    public function getDescription()
    {
        return Craft::t('Triggers after a user has subscribed.');
    }

    /**
     * Returns the data passed in by the triggered event
     *
     * @param Event $event
     *
     * @return mixed
     */
    public function prepareParams(Event $event)
    {
        return [
            'value' => $event->params['user']
        ];
    }
}

SproutEmail is picking this up and I can select it as a rule:

SproutEmail Rule

I added a listener to my plugin for membership.onSubscribe to ensure it's working properly:

craft()->on('membership.onSubscribe', function(Event $event) {
    MembershipPlugin::log('membership.onSubscribe was triggered.');
});

And it appears to be:

2017/02/16 15:07:33 [info] [plugin] membership.onSubscribe was triggered.
in /home/vagrant/Code/sbl.loc/craft/app/etc/plugins/BasePlugin.php (65)
in /home/vagrant/Code/sbl.loc/craft/plugins/membership/MembershipPlugin.php (56)
in /home/vagrant/Code/sbl.loc/craft/plugins/membership/services/MembershipService.php (15)

******************************************************************************************************

However SproutEmail doesn't sent out any notification email and when I check the logs for the plugin there is no mention that my custom event was triggered.

Does anyone have any idea what the issue might be?

1 Answers1

1

We got to the bottom of this issue and it turned out to be that the SproutEmail_SubscribeEvent::validateOptions() method was returning false. Updating this to ensure the options were being validated properly fixed the issue:

public function validateOptions()
{
  return true;
}

We've updated the docs and will also more clearly document this in the SproutEmailBaseEvent class in the next release.

Ben Parizek
  • 13,448
  • 1
  • 33
  • 98