Change app config to keep using the same v1 shipping method calculators and not the ones spree v2 introduces, these are copy pasted versions that work with packages

See this commit for more details: 18e5b98f5c (diff-b0846898827183f530c113ad7b83b8ea)

Also:
- remove shipping method restriction on calculators to inherit from Spree::Shipping::ShippingCalculator so that OFN customized calculators keep working
- add shipping method serializer spec to test serialization of all shipping methods configured
This commit is contained in:
luisramos0
2019-01-27 17:35:49 +00:00
parent 937aaf67c3
commit 8a86c0473d
3 changed files with 38 additions and 1 deletions

View File

@@ -42,6 +42,14 @@ Spree::ShippingMethod.class_eval do
]
end
# This method is overriden so that we can remove the restriction added in Spree
# Spree restricts shipping method calculators to the ones that inherit from Spree::Shipping::ShippingCalculator
# Spree::Shipping::ShippingCalculator makes sure that calculators are able to handle packages and not orders as input
# This is not necessary in OFN because calculators in OFN are already customized to work with different types of input
def self.calculators
spree_calculators.send model_name_without_spree_namespace
end
def has_distributor?(distributor)
self.distributors.include?(distributor)
end

View File

@@ -55,7 +55,15 @@ module Openfoodnetwork
# Register Spree calculators
initializer 'spree.register.calculators' do |app|
app.config.spree.calculators.shipping_methods << Calculator::Weight
app.config.spree.calculators.shipping_methods = [
Spree::Calculator::FlatPercentItemTotal,
Spree::Calculator::FlatRate,
Spree::Calculator::FlexiRate,
Spree::Calculator::PerItem,
Spree::Calculator::PriceSack,
Calculator::Weight
]
app.config.spree.calculators.add_class('enterprise_fees')
config.spree.calculators.enterprise_fees = [
Calculator::FlatPercentPerItem,

View File

@@ -0,0 +1,21 @@
require 'spec_helper'
describe Api::ShippingMethodSerializer do
let(:shipping_method) { create(:shipping_method) }
it "serializes a test shipping_method" do
serializer = Api::ShippingMethodSerializer.new shipping_method
expect(serializer.to_json).to match(shipping_method.name)
end
it "can serialize all configured shipping method calculators" do
Rails.application.config.spree.calculators.shipping_methods.each do |calculator|
shipping_method.calculator = calculator.new
serializer = Api::ShippingMethodSerializer.new shipping_method
allow(serializer).to receive(:options).and_return(current_order: create(:order))
expect(serializer.price).to eq(0.0)
end
end
end