Skip to content

Commit

Permalink
Remove expedited exchanges
Browse files Browse the repository at this point in the history
  • Loading branch information
jhawthorn committed Jan 25, 2017
1 parent a9b3111 commit a322932
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 43 deletions.
15 changes: 0 additions & 15 deletions core/app/models/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,6 @@ class AppConfiguration < Preferences::Configuration
# prices are entered in the backend (default: nil)
preference :admin_vat_country_iso, :string, default: nil

# @!attribute [rw] expedited_exchanges
# Kicks off an exchange shipment upon return authorization save.
# charge customer if they do not return items within timely manner.
# @note this requires payment profiles to be supported on your gateway of
# choice as well as a delayed job handler to be configured with
# activejob.
# @return [Boolean] Use expidited exchanges (default: +false+)
preference :expedited_exchanges, :boolean, default: false

# @!attribute [rw] expedited_exchanges_days_window
# @return [Integer] Number of days the customer has to return their item
# after the expedited exchange is shipped in order to avoid being
# charged (default: +14+)
preference :expedited_exchanges_days_window, :integer, default: 14

# @!attribute [rw] generate_api_key_for_all_roles
# @return [Boolean] Allow generating api key automatically for user
# at role_user creation for all roles. (default: +false+)
Expand Down
28 changes: 0 additions & 28 deletions core/app/models/spree/return_authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@ class ReturnAuthorization < Spree::Base

before_create :generate_number

after_save :generate_expedited_exchange_reimbursements

accepts_nested_attributes_for :return_items, allow_destroy: true

validates :order, presence: true
validates :stock_location, presence: true
validate :must_have_shipped_units, on: :create
validate :no_previously_exchanged_inventory_units, on: :create

# These are called prior to generating expedited exchanges shipments.
# Should respond to a "call" method that takes the list of return items
class_attribute :pre_expedited_exchange_hooks
self.pre_expedited_exchange_hooks = []

state_machine initial: :authorized do
before_transition to: :canceled, do: :cancel_return_items

Expand Down Expand Up @@ -88,26 +81,5 @@ def no_previously_exchanged_inventory_units
def cancel_return_items
return_items.each { |item| item.cancel! if item.can_cancel? }
end

def generate_expedited_exchange_reimbursements
return unless Spree::Config[:expedited_exchanges]

items_to_exchange = return_items.select(&:exchange_required?)
items_to_exchange.each(&:attempt_accept)
items_to_exchange.select!(&:accepted?)

return if items_to_exchange.blank?

pre_expedited_exchange_hooks.each { |h| h.call items_to_exchange }

reimbursement = Spree::Reimbursement.new(return_items: items_to_exchange, order: order)

if reimbursement.save
reimbursement.perform!
else
errors.add(:base, reimbursement.errors.full_messages)
raise ActiveRecord::RecordInvalid.new(self)
end
end
end
end

0 comments on commit a322932

Please sign in to comment.