I am developing a spree extension. I want to do to create a new database record at the end of the order. I need some suggestion on how to do this. As far as I understand, one way is to create a custom method in the class of the class and register a new hook (where should I register a new hook? In the initializer?). Another way is to use activators, but I don't know how to subscribe to events. And where should I put code that subscribes to order events.
module Spree
class Credit < ActiveRecord::Base
def create_new_line(order)
end
end
end
I have found a solution. My order decorator looks like this.
Spree::Order.class_eval do
register_update_hook :add_user_credits
def add_user_credits
if (!self.user.nil? and !self.completed_at.nil?)
end
end
end
source
share