Override default spree splitters config (was Shipping Category and Backordered) to use only Base splitter, this splitter does not split the orders into multiple shipments

In OFN we cannot split the orders because one order can only have one shipment

Additionally, add spec to validate that the order workflow now works with products with different shipping categories
This commit is contained in:
luisramos0
2019-03-14 17:37:59 +00:00
parent a8f81ae7a2
commit beb19cdc8a
3 changed files with 50 additions and 4 deletions

View File

@@ -83,6 +83,17 @@ module Openfoodnetwork
]
end
# Every splitter (except Base splitter) will split the order in multiple packages
# Each package will generate a separate shipment in the order
# Base splitter does not split the packages
# So, because in OFN we have locked orders to have only one shipment,
# we must use this splitter and no other
initializer "spree.register.stock_splitters" do |app|
app.config.spree.stock_splitters = [
Spree::Stock::Splitter::Base
]
end
# Register Spree payment methods
initializer "spree.gateway.payment_methods", :after => "spree.register.payment_methods" do |app|
app.config.spree.payment_methods << Spree::Gateway::Migs

View File

@@ -0,0 +1,9 @@
require 'spec_helper'
describe Openfoodnetwork::Application, 'configuration' do
let(:config) { described_class.config }
it "sets Spree::Stock::Splitter::Base as the only stock splitter" do
expect(config.spree.stock_splitters).to eq [Spree::Stock::Splitter::Base]
end
end

View File

@@ -2,9 +2,9 @@ require 'spec_helper'
describe Spree::Order do
describe 'event :restart_checkout' do
context 'when the order is not complete' do
let(:order) { create(:order) }
let(:order) { create(:order) }
context 'when the order is not complete' do
before { allow(order).to receive(:completed?) { false } }
it 'does transition to cart state' do
@@ -13,8 +13,6 @@ describe Spree::Order do
end
context 'when the order is complete' do
let(:order) { create(:order) }
before { allow(order).to receive(:completed?) { true } }
it 'raises' do
@@ -26,4 +24,32 @@ describe Spree::Order do
end
end
end
describe "order with products with different shipping categories" do
let(:order) { create(:order_with_totals_and_distribution, ship_address: create(:address) ) }
let(:shipping_method) { create(:shipping_method, distributors: [order.distributor]) }
let(:other_shipping_category) { create(:shipping_category) }
let(:other_product) { create(:product, shipping_category: other_shipping_category ) }
let(:other_variant) { other_product.variants.first }
before do
order.order_cycle = create(:simple_order_cycle,
distributors: [order.distributor],
variants: [order.line_items.first.variant, other_variant])
order.line_items = [order.line_items.first, create(:line_item,
order: order,
variant: other_variant)]
end
it "can progress to delivery" do
shipping_method.shipping_categories << other_shipping_category
# If the shipping category package splitter is enabled,
# an order with products with two shipping categories will be split into two shipments
# and the spec will fail with a unique constraint error on index_spree_shipments_on_order_id
order.next
order.next
expect(order.state).to eq "delivery"
end
end
end