按照此页面上的文档... http://guides.spreecommerce.com/developer/calculators.html
我在模型/狂欢/计算器/中创建了一个类
module Spree
class Calculator::ZipTax < Calculator
def self.description
"Calculates Tax Rates From Zipcode in TaxRates Table"
end
def compute(computable)
case computable
when Spree::Order
compute_order(computable)
when Spree::LineItem
compute_line_item(computable)
end
end
def compute_order(order)
zipcode = order.bill_address.zipcode[0,5]
zip = TaxTable.where(:zipcode => zipcode).first
if(zip.present?)
rate = zip.combined_rate
order.line_items.sum(&:total) * rate
else
0
end
end
end
end
在 initializers/spree.rb 我添加了:
config = Rails.application.config
config.spree.calculators.tax_rates << Spree::Calculator::ZipTax
但我无法让 Rails 启动。我在初始化程序/spree.rb 文件上得到了 nil:NilClass (NoMethodError) 的未定义方法 `<<'。
如何注册自定义计算器?使用狂欢 1.3.2。