オンライン ショップに Spree Commerce を使用しています。app/models/spree/order/checkout.rb
spree gem 内で定義されている、チェックアウト プロセス中の動作を変更したいと考えています。だから私はcheckout_decorator.rb
自分のアプリケーションで同じポイントを作成しました。
問題は、私の変更がロードされていないことです。もう 1 つの問題は、モジュール内のすべてが 1 つのメソッド (メソッド) 内にあるdef self.included(klass)
ことです。したがって、1 つのメソッドだけでなく、ファイル全体を上書きする必要があると思います。私のデコレータは次のようになります。
checkout_decorator.rb
Spree::Order::Checkout.module_eval do
def self.included(klass)
klass.class_eval do
class_attribute :next_event_transitions
class_attribute :previous_states
class_attribute :checkout_flow
class_attribute :checkout_steps
def self.define_state_machine!
# here i want to make some changes
end
# and the other methods are also include here
# for readability, i don't show them here
end
end
end
spree gemの元のファイルcheckout.rb
は次のようになります。
module Spree
class Order < ActiveRecord::Base
module Checkout
def self.included(klass)
klass.class_eval do
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!
# some code
end
# and other methods that are not shown here
end
end
end
end
end
私の質問は次のとおりです。なぜこれが機能しないのですか? module_eval
これを行う正しい方法はありますか?試してみclass_eval
ましたが、うまくいきません。どうすればこれを解決できますか?