diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index e1127d131e..bced2e5a17 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -47,6 +47,8 @@ Spree::Order.class_eval do if self.shipping_method self.save! self.create_shipment! + else + raise 'No default shipping method found' end end diff --git a/app/views/spree/orders/_inside_cart_form.html.haml b/app/views/spree/orders/_inside_cart_form.html.haml index 18e3d6f0b3..117b0fed9e 100644 --- a/app/views/spree/orders/_inside_cart_form.html.haml +++ b/app/views/spree/orders/_inside_cart_form.html.haml @@ -6,15 +6,15 @@ %h5 Item total \: - %span.order-total= order_subtotal(@order) + %span.order-total.item-total= number_to_currency @order.item_total %h5 Shipping total \: - %span.order-total= order_delivery_fee_subtotal(@order) + %span.order-total.shipping-total= order_delivery_fee_subtotal(@order) %h4 Total \: - %span.order-total= number_to_currency(order_subtotal(@order, :format_as_currency => false) + order_delivery_fee_subtotal(@order, :format_as_currency => false)) + %span.order-total.grand-total= order_subtotal(@order) .links{'data-hook' => "cart_buttons"} = button_tag :class => 'primary', :id => 'update-button' do diff --git a/spec/controllers/distributors_controller_spec.rb b/spec/controllers/distributors_controller_spec.rb index 2d83e5ea45..3595b780e0 100644 --- a/spec/controllers/distributors_controller_spec.rb +++ b/spec/controllers/distributors_controller_spec.rb @@ -4,9 +4,11 @@ require 'spree/core/current_order' describe Spree::DistributorsController do include Spree::Core::CurrentOrder - before do + before :each do stub!(:before_save_new_order) stub!(:after_save_new_order) + + create(:itemwise_shipping_method) end diff --git a/spec/factories.rb b/spec/factories.rb index 47fbf6f3b8..0bc105d592 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -24,7 +24,7 @@ FactoryGirl.define do factory :product_distribution, :class => Spree::ProductDistribution do product { |pd| Spree::Product.first || FactoryGirl.create(:product) } distributor { |pd| Spree::Distributor.first || FactoryGirl.create(:distributor) } - shipping_method { |pd| Spree::ShippingMethod.first || FactoryGirl.create(:shipping_method) } + shipping_method { |pd| Spree::ShippingMethod.where("name != 'Delivery'").first || FactoryGirl.create(:shipping_method) } end factory :itemwise_shipping_method, :parent => :shipping_method do @@ -50,12 +50,25 @@ FactoryGirl.modify do # before(:create) do |product, evaluator| # product.product_distributions = [FactoryGirl.create(:product_distribution, :product => product)] # end + + # Do not create products distributed via the 'Delivery' shipping method + after(:create) do |product, evaluator| + pd = product.product_distributions.first + if pd.andand.shipping_method.andand.name == 'Delivery' + pd.shipping_method = Spree::ShippingMethod.where("name != 'Delivery'").first || FactoryGirl.create(:shipping_method) + pd.save! + end + end end factory :line_item do shipping_method { |li| li.product.shipping_method_for_distributor(li.order.distributor) } end + factory :shipping_method do + display_on '' + end + factory :address do state { Spree::State.find_by_name 'Victoria' } country { Spree::Country.find_by_name 'Australia' || Spree::Country.first } diff --git a/spec/requests/consumer/add_to_cart_spec.rb b/spec/requests/consumer/add_to_cart_spec.rb index 9172519292..d528866647 100644 --- a/spec/requests/consumer/add_to_cart_spec.rb +++ b/spec/requests/consumer/add_to_cart_spec.rb @@ -24,26 +24,38 @@ feature %q{ # And the product should not have been added to my cart Spree::Order.last.should be_nil - #order.line_items.should be_empty end scenario "adding the first product to the cart" do - # Given a product and some distributors + create(:itemwise_shipping_method) + + # Given a product, some distributors and a defined shipping cost d1 = create(:distributor) d2 = create(:distributor) - p = create(:product, :distributors => [d1]) create(:product, :distributors => [d2]) + p = create(:product, :price => 12.34) + create(:product_distribution, :product => p, :distributor => d1, :shipping_method => create(:shipping_method)) + + # ... with a flat rate shipping method of cost $1.23 + sm = p.product_distributions.first.shipping_method + sm.calculator.preferred_amount = 1.23 + sm.calculator.save! # When I choose a distributor visit spree.root_path click_link d2.name - # When I add an item to my cart from a different distributor + # And I add an item to my cart from a different distributor visit spree.product_path p select d1.name, :from => 'distributor_id' click_button 'Add To Cart' - # Then the item should be in my cart, with shipping method set for the line item + # Then the correct totals should be displayed + page.should have_selector 'span.item-total', :text => '$12.34' + page.should have_selector 'span.shipping-total', :text => '$1.23' + page.should have_selector 'span.grand-total', :text => '$13.57' + + # And the item should be in my cart, with shipping method set for the line item order = Spree::Order.last line_item = order.line_items.first line_item.product.should == p