mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Copy distributor addr. when using a pick up method
This copies the distributor's address when at least one of the order shipments uses a shipping method that requires shipping address.
This commit is contained in:
@@ -44,9 +44,11 @@ class OrderUpdater < SimpleDelegator
|
||||
end
|
||||
|
||||
def shipping_address_from_distributor
|
||||
shipping_method = order.shipments.first.shipping_methods.first
|
||||
return if shipping_method.require_ship_address
|
||||
shipments.each do |shipment|
|
||||
shipping_method = shipment.shipping_method
|
||||
next if shipping_method.require_ship_address
|
||||
|
||||
order.ship_address = order.distributor.address
|
||||
order.ship_address = order.distributor.address
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -101,24 +101,43 @@ describe OrderUpdater do
|
||||
|
||||
context '#before_save_hook' do
|
||||
let(:distributor) { build(:distributor_enterprise) }
|
||||
let(:shipment) { build(:shipment) }
|
||||
let(:order) { build(:order, distributor: distributor) }
|
||||
let(:shipment) { build(:shipment) }
|
||||
let(:shipping_rate) do
|
||||
Spree::ShippingRate.new(
|
||||
shipping_method: shipping_method,
|
||||
selected: true
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
shipment.shipping_methods << shipping_method
|
||||
shipment.shipping_rates << shipping_rate
|
||||
order.shipments << shipment
|
||||
end
|
||||
|
||||
context 'when the shipping method doesn\'t require a delivery address' do
|
||||
context 'when any of the shipping methods doesn\'t require a delivery address' do
|
||||
let(:shipping_method) { build(:base_shipping_method, require_ship_address: false) }
|
||||
|
||||
let(:delivery_shipment) { build(:shipment) }
|
||||
let(:delivery_shipping_rate) do
|
||||
Spree::ShippingRate.new(
|
||||
shipping_method: build(:base_shipping_method, require_ship_address: true),
|
||||
selected: true
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
delivery_shipment.shipping_rates << delivery_shipping_rate
|
||||
order.shipments << delivery_shipment
|
||||
end
|
||||
|
||||
it "populates the shipping address" do
|
||||
order_updater.before_save_hook
|
||||
expect(order.ship_address.firstname).to eq(distributor.address.firstname)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the shipping method requires a delivery address' do
|
||||
context 'when any of the shipping methods requires a delivery address' do
|
||||
let(:shipping_method) { build(:base_shipping_method, require_ship_address: true) }
|
||||
let(:address) { build(:address, firstname: 'will') }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user