Merge pull request #3604 from luisramos0/2-0-fix-splitters

[Spree Upgrade] Override default spree splitters config
This commit is contained in:
Luis Ramos
2019-04-09 09:19:00 +01:00
committed by GitHub
6 changed files with 54 additions and 7 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

@@ -427,7 +427,7 @@ FactoryBot.define do
payment_method = create(:payment_method, calculator: payment_calculator)
create(:payment, order: order, amount: order.total, payment_method: payment_method, state: 'checkout')
create(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee)
create(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee, distributors: [order.distributor])
order.reload
while !order.completed? do break unless order.next! end
@@ -443,6 +443,7 @@ FactoryBot.define do
shipment = order.reload.shipments.first
if shipment.nil?
shipping_method = create(:shipping_method_with, :shipping_fee, shipping_fee: shipping_fee)
shipping_method.distributors << order.distributor if order.distributor
shipment = create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order)
end
shipment

View File

@@ -78,7 +78,9 @@ describe ProxyOrder, type: :model do
describe "resume" do
let!(:payment_method) { create(:payment_method) }
let!(:shipment) { create(:shipment) }
let(:order) { create(:order_with_totals, ship_address: create(:address), shipments: [shipment]) }
let(:order) { create(:order_with_totals, ship_address: create(:address),
shipments: [shipment],
distributor: shipment.shipping_method.distributors.first) }
let(:proxy_order) { create(:proxy_order, order: order, canceled_at: Time.zone.now) }
let(:order_cycle) { proxy_order.order_cycle }

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,30 @@ 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 << 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

View File

@@ -8,7 +8,7 @@ describe OrderFactory do
let(:shop) { create(:distributor_enterprise) }
let(:order_cycle) { create(:simple_order_cycle) }
let!(:other_shipping_method_a) { create(:shipping_method) }
let!(:shipping_method) { create(:shipping_method) }
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
let!(:other_shipping_method_b) { create(:shipping_method) }
let(:payment_method) { create(:payment_method) }
let(:ship_address) { create(:address) }