Tiếp theo các tài liệu trên trang này ... http://guides.spreecommerce.com/developer/calculators.htmlĐăng ký một tính tùy chỉnh Spree không làm việc
tôi đã tạo ra một lớp trong mô hình/Spree/máy tính/
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
Và trong initializers/Spree .rb Tôi đã thêm:
config = Rails.application.config
config.spree.calculators.tax_rates << Spree::Calculator::ZipTax
Nhưng tôi không thể bắt đầu Rails. Tôi nhận được phương thức undefined `< < 'cho nil: NilClass (NoMethodError) trên tập tin initializer/spree.rb.
Làm cách nào để đăng ký Máy tính tùy chỉnh? Sử dụng Spree 1.3.2.
Cảm ơn rất nhiều. Lần sau tôi sẽ biết rõ hơn là theo dõi các tài liệu của Spree một cách chặt chẽ;) –
Trên một lưu ý phụ cho máy tính giao hàng, hãy đảm bảo rằng tên lớp là 'Spree :: Shipping ::' cho máy tính của bạn để hiển thị trong bảng điều khiển quản trị https://github.com/spree/spree/blob/2a3f91229f65e1c0c7e16eb47da455d3488195bc/core/app/models/spree/shipping_method.rb#L50. Chẳng bao lâu để phát hành các phiên bản Spree chỉ yêu cầu máy tính giao hàng kế thừa từ 'Spree :: ShippingCalculator' https://github.com/spree/spree/blob/82fd0e0f762f17493c1609a998192272dab83e07/core/app/models/spree/shipping_method.rb#L50 –
davidtingsu
I nghĩ rằng điều này thực sự nên là một tên lớp của Spree :: Calculator :: Shipping :: để làm cho nó hiển thị trong Admin Panel. –
lightcap