Skip to content

Commit

Permalink
Safer new_order handling
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusvk committed Sep 23, 2015
1 parent 2244915 commit 5ecca06
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/lib/spree/core/unreturned_item_charger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(message, new_order)

class_attribute :failure_handler

attr_reader :original_order
attr_reader :original_order, :new_order

def initialize(shipment, return_items)
@shipment = shipment
Expand All @@ -19,6 +19,8 @@ def initialize(shipment, return_items)
end

def charge_for_items
self.new_order = Spree::Order.create!(exchange_order_attributes)

new_order.associate_user!(@original_order.user) if @original_order.user

add_exchange_variants_to_order
Expand Down Expand Up @@ -53,12 +55,10 @@ def charge_for_items

end

def new_order
@new_order ||= Spree::Order.create!(exchange_order_attributes)
end

private

attr_writer :new_order

def add_exchange_variants_to_order
@return_items.group_by(&:exchange_variant).map do |variant, variant_return_items|
variant_inventory_units = variant_return_items.map(&:exchange_inventory_unit)
Expand Down

0 comments on commit 5ecca06

Please sign in to comment.