0

I've been reading a almost everything I find about Spree promotions but i didn't find the way to define a new trigger for promotions.

I only find how to define actions and rules but nothing about defining events. I already know that it uses ActiveSupport::Notifications but i can't find the way to get through this.

promotion event trigger select

aanfuso
  • 53
  • 8

1 Answers1

5

This is a bit of a tough one. The first thing you'll need to do is fire an event when your condition occurs. fire_event in the common controller helpers delegates that to ActiveSupport::Notification.

Then you'll need to decorate Spree::Promotion to add a new Activator like this code which adds the coupon code activator.

This code subscribes to the spree.* events and will fire the appropriate event based on the activator. It calls the activate method on the appropriate class which you'll need to override in your decorated promotion. The default promotion activate does this, so you'll need to extend that code to do whatever you'd like on your event.

Hope that gives you somewhere to get started.

gmacdougall
  • 4,901
  • 1
  • 16
  • 21