Sort payment and shipping methods by distributor name

This commit is contained in:
David Cook
2013-09-19 15:18:13 +10:00
parent 2e13abf933
commit 2df2096d74
5 changed files with 29 additions and 4 deletions

View File

@@ -1,14 +1,14 @@
Spree::Admin::PaymentMethodsController.class_eval do
# Only show payment methods that user has access to.
# Only show payment methods that user has access to and sort by distributor name
# ! Redundant code copied from Spree::Admin::ResourceController with two added lines
def collection
return parent.send(controller_name) if parent_data.present?
if model_class.respond_to?(:accessible_by) && !current_ability.has_block?(params[:action], model_class)
model_class.accessible_by(current_ability, action).
managed_by(spree_current_user) # this line added
managed_by(spree_current_user).by_distributor # this line added
else
model_class.scoped.
managed_by(spree_current_user) # this line added
managed_by(spree_current_user).by_distributor # this line added
end
end
end

View File

@@ -3,6 +3,19 @@ module Spree
ShippingMethodsController.class_eval do
before_filter :do_not_destroy_referenced_shipping_methods, :only => :destroy
# Sort shipping methods by distributor name
# ! Redundant code copied from Spree::Admin::ResourceController with two added lines
def collection
return parent.send(controller_name) if parent_data.present?
if model_class.respond_to?(:accessible_by) && !current_ability.has_block?(params[:action], model_class)
model_class.accessible_by(current_ability, action).
by_distributor # this line added
else
model_class.scoped.
by_distributor # this line added
end
end
# This method was originally written because ProductDistributions referenced shipping
# methods, and deleting a referenced shipping method would break all the reports that
# queried it.

View File

@@ -14,6 +14,12 @@ Spree::PaymentMethod.class_eval do
end
}
scope :by_distributor, lambda {
joins(:distributors).
order('enterprises.name, spree_payment_methods.name').
select('enterprises.*, spree_payment_methods.*')
}
def has_distributor?(distributor)
self.distributors.include?(distributor)
end

View File

@@ -4,6 +4,12 @@ Spree::ShippingMethod.class_eval do
validates_presence_of :distributor_id
scope :by_distributor, lambda {
joins(:distributor).
order('enterprises.name, spree_shipping_methods.name').
select('enterprises.*, spree_shipping_methods.*')
}
def available_to_order_with_distributor_check?(order, display_on=nil)
available_to_order_without_distributor_check?(order, display_on) &&
(order.distributor == self.distributor)

View File

@@ -1,4 +1,4 @@
/ insert_top "[data-hook='admin_payment_methods_index_rows']"
%td.align-center
= method.distributors.map(&:name).join(', ')
= method.distributors.map(&:name).sort.join(', ')