Skip to content

Commit

Permalink
Merge pull request #1691 from jhawthorn/remove_expedited_exchanges
Browse files Browse the repository at this point in the history
Extract expedited exchanges to an extension
  • Loading branch information
jhawthorn authored Jan 31, 2017
2 parents 0d2f986 + a322932 commit cfbfb87
Show file tree
Hide file tree
Showing 20 changed files with 0 additions and 804 deletions.
1 change: 0 additions & 1 deletion backend/app/assets/javascripts/spree/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
//= require spree/backend/product_picker
//= require spree/backend/progress
//= require spree/backend/promotions
//= require spree/backend/returns/expedited_exchanges_warning
//= require spree/backend/returns/return_item_selection
//= require spree/backend/routes
//= require spree/backend/select_payments
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,3 @@
max-width: 150px;
}
}
.expedited-exchanges-warning {
display: none;
color: black;
padding: 15px;
margin: 10px 0;
font-weight: bold;
background-color: $color-6;
border-radius: 4px;
opacity: 0.6;
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,3 @@
<%= f.error_message_on :memo %>
<% end %>
</div>

<% if Spree::Config[:expedited_exchanges] %>
<div class="expedited-exchanges-warning"><%= Spree.t(:expedited_exchanges_warning, days_window: Spree::Config[:expedited_exchanges_days_window]) %></div>
<% end %>
1 change: 0 additions & 1 deletion core/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ require 'rake'
require 'rake/testtask'
require 'rspec/core/rake_task'
require 'spree/testing_support/common_rake'
load 'lib/tasks/exchanges.rake'

RSpec::Core::RakeTask.new

Expand Down
19 changes: 0 additions & 19 deletions core/app/models/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ class AppConfiguration < Preferences::Configuration
# @return [Boolean] Request company field for billing and shipping addresses. (default: +false+)
preference :company, :boolean, default: false

# @!attribute [rw] create_rma_for_unreturned_exchange
# @return [Boolean] allows rma to be created for items after unreturned exchange charge has been made (default: +false+)
preference :create_rma_for_unreturned_exchange, :boolean, default: false

# @!attribute [rw] currency
# Currency to use by default when not defined on the site (default: +"USD"+)
# @return [String] ISO 4217 Three letter currency code
Expand All @@ -132,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
15 changes: 0 additions & 15 deletions core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def states

# shows completed orders first, by their completed_at date, then uncompleted orders by their created_at
scope :reverse_chronological, -> { order('spree_orders.completed_at IS NULL', completed_at: :desc, created_at: :desc) }
scope :unreturned_exchange, -> { joins(:shipments).where('spree_orders.created_at > spree_shipments.created_at') }

def self.by_customer(customer)
joins(:user).where("#{Spree.user_class.table_name}.email" => customer)
Expand Down Expand Up @@ -507,8 +506,6 @@ def ensure_shipping_address
end

def create_proposed_shipments
return shipments if unreturned_exchange?

if completed?
raise CannotRebuildShipments.new(Spree.t(:cannot_rebuild_shipments_order_completed))
elsif shipments.any? { |s| !s.pending? }
Expand Down Expand Up @@ -597,18 +594,6 @@ def token
guest_token
end

def unreturned_exchange?
# created_at - 1 is a hack to ensure that this doesn't blow up on MySQL,
# records loaded from the DB on MySQL will have a precision of 1 second,
# but records in memory may still have miliseconds on them, causing this
# to be true where it shouldn't be.
#
# FIXME: find a better way to determine if an order is an unreturned
# exchange
shipment = shipments.first
shipment.present? ? (shipment.created_at < created_at - 1) : false
end

def tax_total
additional_tax_total + included_tax_total
end
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
</td>
</tr>
<% end %>
<% if @reimbursement.return_items.awaiting_return.present? && Spree::Config[:expedited_exchanges] %>
<tr>
<td colspan="3">
<%= Spree.t('reimbursement_mailer.reimbursement_email.days_to_send', days: Spree::Config[:expedited_exchanges_days_window]) %>
</td>
</tr>
<% end %>
</table>
<% end %>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,4 @@
<% @reimbursement.return_items.exchange_requested.each do |return_item| %>
<%= return_item.variant.sku %> <%= raw(return_item.variant.name) %> <%= "(#{raw(return_item.variant.options_text)})" if return_item.variant.options_text.present? %> -> <%= return_item.exchange_variant.sku %> <%= raw(return_item.exchange_variant.name) %> <%= "(#{raw(return_item.exchange_variant.options_text)})" if return_item.exchange_variant.options_text.present? %>
<% end %>


<% if @reimbursement.return_items.awaiting_return.present? && Spree::Config[:expedited_exchanges] %>
<%= Spree.t('reimbursement_mailer.reimbursement_email.days_to_send', days: Spree::Config[:expedited_exchanges_days_window]) %>
<% end %>
<% end %>
1 change: 0 additions & 1 deletion core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,6 @@ en:
exceptions:
count_on_hand_setter: Cannot set count_on_hand manually, as it is set automatically by the recalculate_count_on_hand callback. Please use `update_column(:count_on_hand, value)` instead.
exchange_for: Exchange for
expedited_exchanges_warning: "Any specified exchanges will ship to the customer immediately upon saving. The customer will be charged the full amount of the item if they do not return the original item within %{days_window} days."
excl: excl.
expected: Expected
expected_items: Expected Items
Expand Down
1 change: 0 additions & 1 deletion core/lib/spree/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class DestroyWithOrdersError < StandardError; end
require 'spree/core/controller_helpers/search'
require 'spree/core/controller_helpers/store'
require 'spree/core/controller_helpers/strong_parameters'
require 'spree/core/unreturned_item_charger'
require 'spree/core/role_configuration'
require 'spree/core/stock_configuration'
require 'spree/permission_sets'
Expand Down
4 changes: 0 additions & 4 deletions core/lib/spree/core/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ class Engine < ::Rails::Engine
isolate_namespace Spree
engine_name 'spree'

rake_tasks do
load File.join(root, "lib", "tasks", "exchanges.rake")
end

config.generators do |g|
g.test_framework :rspec
end
Expand Down
106 changes: 0 additions & 106 deletions core/lib/spree/core/unreturned_item_charger.rb

This file was deleted.

47 changes: 0 additions & 47 deletions core/lib/tasks/exchanges.rake

This file was deleted.

Loading

0 comments on commit cfbfb87

Please sign in to comment.