diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb index b6f2fedc978..25628292925 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -18,7 +18,6 @@ class Order < ActiveRecord::Base go_to_state :payment, :if => lambda { |order| # Fix for #2191 if order.shipping_method - order.create_shipment! order.update_totals end order.payment_required? @@ -32,7 +31,8 @@ class Order < ActiveRecord::Base attr_accessible :line_items, :bill_address_attributes, :ship_address_attributes, :payments_attributes, :ship_address, :bill_address, :payments_attributes, :line_items_attributes, :number, - :shipping_method_id, :email, :use_billing, :special_instructions, :currency, :coupon_code + :shipping_method_id, :email, :use_billing, :special_instructions, :currency, :coupon_code, + :shipments_attributes attr_reader :coupon_code @@ -338,19 +338,6 @@ def create_tax_charge! Spree::TaxRate.adjust(self) end - # Creates a new shipment (adjustment is created by shipment model) - def create_shipment! - shipping_method(true) - if shipment.present? - shipment.update_attributes!(:shipping_method => shipping_method) - else - self.shipments << Shipment.create!({ :order => self, - :shipping_method => shipping_method, - :address => self.ship_address, - :inventory_units => self.inventory_units}, :without_protection => true) - end - end - def outstanding_balance total - payment_total end diff --git a/core/app/models/spree/order/checkout.rb b/core/app/models/spree/order/checkout.rb index bc54425e3a8..537f01622b9 100644 --- a/core/app/models/spree/order/checkout.rb +++ b/core/app/models/spree/order/checkout.rb @@ -69,14 +69,12 @@ def self.define_state_machine! end end - before_transition :to => :delivery, :do => :remove_invalid_shipments! + before_transition :to => :delivery, :do => :create_proposed_shipments after_transition :to => :complete, :do => :finalize! after_transition :to => :delivery, :do => :create_tax_charge! after_transition :to => :resumed, :do => :after_resume after_transition :to => :canceled, :do => :after_cancel - - after_transition :from => :delivery, :do => :create_shipment! end end diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb index 6747179f085..42644d6ebf2 100644 --- a/core/app/models/spree/shipment.rb +++ b/core/app/models/spree/shipment.rb @@ -15,18 +15,18 @@ class Shipment < ActiveRecord::Base has_one :adjustment, :as => :source, :dependent => :destroy before_create :generate_shipment_number - after_save :ensure_correct_adjustment, :update_order + after_save :ensure_correct_adjustment, :ensure_selected_shipping_rate, :update_order attr_accessor :special_instructions attr_accessible :order, :special_instructions, - :tracking, :address, :inventory_units + :tracking, :address, :inventory_units, :selected_shipping_rate_id accepts_nested_attributes_for :address accepts_nested_attributes_for :inventory_units + validates :inventory_units, :presence => true, :if => :require_inventory - #validates :shipping_method, :presence => true make_permalink :field => :number @@ -57,6 +57,20 @@ def add_shipping_method(shipping_method, selected=false) :selected => selected) end + def selected_shipping_rate_id + shipping_rates.where(selected: true).first.try(:id) + end + + def selected_shipping_rate_id=(id) + shipping_rates.update_all(selected: false) + shipping_rates.update(id, selected: true) + end + + def ensure_selected_shipping_rate + shipping_rates.exists?(selected: true) || + shipping_rates.limit(1).update_all(selected: true) + end + def currency order.nil? ? Spree::Config[:currency] : order.currency end diff --git a/frontend/app/controllers/spree/checkout_controller.rb b/frontend/app/controllers/spree/checkout_controller.rb index 74b10395681..3ee0646eb17 100644 --- a/frontend/app/controllers/spree/checkout_controller.rb +++ b/frontend/app/controllers/spree/checkout_controller.rb @@ -126,7 +126,6 @@ def before_address def before_delivery return if params[:order].present? - # @order.shipping_method ||= (@order.rate_hash.first && @order.rate_hash.first[:shipping_method]) end def rescue_from_spree_gateway_error diff --git a/frontend/app/views/spree/checkout/_delivery.html.erb b/frontend/app/views/spree/checkout/_delivery.html.erb index 729b50b4745..78107239340 100644 --- a/frontend/app/views/spree/checkout/_delivery.html.erb +++ b/frontend/app/views/spree/checkout/_delivery.html.erb @@ -2,19 +2,25 @@
- <% @order.create_proposed_shipments.each_with_index do |shipment, idx| %> -
Package from <%= ship_form.object.stock_location.name %>
+contents:
- <% shipment.manifest.each do |item| %> + <% ship_form.object.manifest.each do |item| %> <%= item.variant.name %> <%= item.quantity %> <% end %> - <% shipment.shipping_rates.each do |shipping_rate| %> -<%= radio_button_tag "shipment_{shipment.id}", shipping_rate.id, shipping_rate.selected %><%= shipping_rate.name %> <%= shipping_rate.cost %>
+ +shipping method
+ <% ship_form.object.shipping_rates.each do |rate| %> ++ <%= ship_form.radio_button :selected_shipping_rate_id, rate.id %> <%= rate.name %> <%= rate.cost %>
+ <% end %> <% end %> - +diff --git a/frontend/app/views/spree/shared/_order_details.html.erb b/frontend/app/views/spree/shared/_order_details.html.erb index 0531df8894c..c718b0b580f 100644 --- a/frontend/app/views/spree/shared/_order_details.html.erb +++ b/frontend/app/views/spree/shared/_order_details.html.erb @@ -13,9 +13,12 @@ <% if @order.has_step?("delivery") %>