mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Sort payment and shipping methods by distributor name
This commit is contained in:
@@ -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
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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(', ')
|
||||
|
||||
Reference in New Issue
Block a user