mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #3400 from luisramos0/2-0-ship-methods
[Spree Upgrade] Change app config to keep using ofn customized spree v1 shipping method calculators, not the new spree v2 ones
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -51,4 +51,4 @@ end
|
||||
spree_user = Spree::User.first
|
||||
spree_user && spree_user.confirm!
|
||||
|
||||
DefaultStockLocation.create!
|
||||
DefaultStockLocation.find_or_create
|
||||
|
||||
21
spec/serializers/api/shipping_method_serializer_spec.rb
Normal file
21
spec/serializers/api/shipping_method_serializer_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user