创建自定义计算器时遇到问题。我按照这里的说明进行操作:
http://guides.spreecommerce.org/developer/calculators.html
我的计算器里面有狂欢/计算器:
class CustomCalculator < Spree::Calculator
def self.description
# Human readable description of the calculator
end
def compute(object=nil)
p "Test"
10.0
# Returns the value after performing the required calculation
end
end
在spree.rb中我添加了:
config = Rails.application.config
config.spree.calculators.tax_rates << CustomCalculator
但是当我运行服务器时,我会收到这个服务器:
config/initializers/spree.rb:24:in `<top (required)>': uninitialized constant CustomCalculator (NameError)
我已经环顾四周,尝试了不同的方法来创建我的自定义计算器...但没有什么是对的。
我正在使用Spree 3.1。
答案 0 :(得分:2)
由于您的计算器在狂欢/计算器内,请在Spree :: Calculator下进行范围调整:
Spree::Core::Engine.config.after_initialize do
config = Rails.application.config
config.spree.calculators.tax_rates << Spree::Calculator::CustomCalculator
end
并在spree.rb中添加:
{{1}}
答案 1 :(得分:0)
1.在models / spree / calculators文件夹中使用class_name创建一个文件
module Spree
class Calculator::CustomCalculator < Calculator
def self.description
# Human readable description of the calculator
end
def compute(object=nil)
p "Test"
10.0
# Returns the value after performing the required calculation
end
end
end
Rails.application.config.spree.calcualtors.tax_rates << Spree::Calculator::CustomCalculator