Display shipping fee at all steps of the checkout process, not just after delivery method is chosen

This commit is contained in:
Rohan Mitchell
2012-08-02 16:24:08 +10:00
parent a6c2490597
commit fe61b4aab1
2 changed files with 30 additions and 0 deletions

View File

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

View File

@@ -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)