ruby on rails - Spree module decorator -
i'm using spree commerce online shop. want change behaviour during checkout process, defined in app/models/spree/order/checkout.rb inside spree gem. made checkout_decorator.rb @ same point in application.
the problem is, changes aren't loaded. , problem is, inside module inside 1 method, def self.included(klass) method. think have overwrite whole file, instead of 1 method. here decorator looks like:
checkout_decorator.rb
spree::order::checkout.module_eval   def self.included(klass)     klass.class_eval       class_attribute :next_event_transitions       class_attribute :previous_states       class_attribute :checkout_flow       class_attribute :checkout_steps        def self.define_state_machine!          # here want make changes       end        # , other methods include here       # readability, don't show them here     end   end end   the original file checkout.rb spree gem looks this:
module spree   class order < activerecord::base     module checkout       def self.included(klass)         klass.class_eval           class_attribute :next_event_transitions           class_attribute :previous_states           class_attribute :checkout_flow           class_attribute :checkout_steps            def self.checkout_flow(&block)             if block_given?               @checkout_flow = block               define_state_machine!             else               @checkout_flow             end           end            def self.define_state_machine!              # code           end            # , other methods not shown here         end       end     end   end end   so questions are: why not work? module_eval right way this? tried class_eval doesn't work either. how can solve this?
the module_eval method isn't going work you.
you should @ spree checkout flow documentation examples on how customize checkout flow. recommended way customizing checkout flow won't need copy/paste whole bunch of code.
you need to include Spree::Order::Checkout in order_decorator.rb and use .class_eval
ReplyDelete