mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Display shipping fee at all steps of the checkout process, not just after delivery method is chosen
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
Spree::Order.class_eval do
|
||||
belongs_to :distributor
|
||||
|
||||
after_create :set_default_shipping_method
|
||||
|
||||
|
||||
def can_change_distributor?
|
||||
# Distributor may not be changed once an item has been added to the cart/order
|
||||
line_items.empty?
|
||||
@@ -31,6 +34,20 @@ Spree::Order.class_eval do
|
||||
before_validation :shipping_address_from_distributor
|
||||
|
||||
private
|
||||
|
||||
# On creation of the order (when the first item is added to the user's cart), set the
|
||||
# shipping method to the first one available and create a shipment.
|
||||
# order.create_shipment! creates an adjustment for the shipping cost on the order,
|
||||
# which means that the customer can see their shipping cost at every step of the
|
||||
# checkout process, not just after the delivery step.
|
||||
# This is based on the assumption that there's only one shipping method visible to the user,
|
||||
# which is a method using the itemwise shipping calculator.
|
||||
def set_default_shipping_method
|
||||
self.shipping_method = Spree::ShippingMethod.where("display_on != 'back_end'").first
|
||||
self.save!
|
||||
self.create_shipment!
|
||||
end
|
||||
|
||||
def shipping_address_from_distributor
|
||||
if distributor
|
||||
self.ship_address = distributor.pickup_address.clone
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Order do
|
||||
it "initialises a default shipping method after creation" do
|
||||
shipping_method_back_end = create(:shipping_method, :display_on => :back_end)
|
||||
shipping_method_both = create(:shipping_method, :display_on => :both)
|
||||
|
||||
subject.shipping_method.should be_nil
|
||||
subject.adjustments.should be_empty
|
||||
|
||||
subject.save!
|
||||
|
||||
subject.shipping_method.should == shipping_method_both
|
||||
subject.adjustments.where(:label => "Shipping").should be_present
|
||||
end
|
||||
|
||||
it "reveals permission for changing distributor" do
|
||||
p = build(:product)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user