Skip to content

Commit

Permalink
Merge pull request #388 from bonobos/always-pass-new-order
Browse files Browse the repository at this point in the history
Always pass the new order number on unreturned exchange failures
  • Loading branch information
Andrew Thal committed Dec 23, 2015
2 parents 028dfb6 + 9bf8206 commit 7f971e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 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 @@ -55,9 +57,7 @@ def charge_for_items

private

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

def add_exchange_variants_to_order
@return_items.group_by(&:exchange_variant).map do |variant, variant_return_items|
Expand Down
7 changes: 4 additions & 3 deletions core/lib/tasks/exchanges.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ namespace :exchanges do
begin
item_charger.charge_for_items
rescue Spree::UnreturnedItemCharger::ChargeFailure => e
failure = {message: e.message, new_order: e.new_order.try(:number)}
rescue Exception => e
failure = {message: "#{e.class}: #{e.message}"}
failure = { message: e.message }
rescue => e
failure = { message: "#{e.class}: #{e.message}" }
end

if failure
failure[:new_order] = item_charger.new_order.number if item_charger.new_order
failures << failure.merge({
order: item_charger.original_order.number,
shipment: shipment.number,
Expand Down

0 comments on commit 7f971e1

Please sign in to comment.