diff --git a/app/controllers/spree/admin/payment_methods_controller_decorator.rb b/app/controllers/spree/admin/payment_methods_controller_decorator.rb index db2579e054..443e50a6d1 100644 --- a/app/controllers/spree/admin/payment_methods_controller_decorator.rb +++ b/app/controllers/spree/admin/payment_methods_controller_decorator.rb @@ -1,14 +1,21 @@ Spree::Admin::PaymentMethodsController.class_eval do # 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 + # ! Redundant code copied from Spree::Admin::ResourceController with modifications marked 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).by_distributor # this line added - else - model_class.scoped. - managed_by(spree_current_user).by_distributor # this line added + collection = 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).by_distributor # this line added + else + model_class.scoped. + managed_by(spree_current_user).by_distributor # this line added + end + + if params.key? :enterprise_id + distributor = Enterprise.find params[:enterprise_id] + collection = collection.for_distributor(distributor) end + + collection end -end \ No newline at end of file +end diff --git a/app/models/spree/payment_method_decorator.rb b/app/models/spree/payment_method_decorator.rb index 865ec5bcd5..a74a023ca8 100644 --- a/app/models/spree/payment_method_decorator.rb +++ b/app/models/spree/payment_method_decorator.rb @@ -14,6 +14,11 @@ Spree::PaymentMethod.class_eval do end } + scope :for_distributor, lambda { |distributor| + joins(:distributors). + where('enterprises.id = ?', distributor) + } + scope :by_distributor, lambda { joins(:distributors). order('enterprises.name, spree_payment_methods.name'). diff --git a/app/views/admin/enterprises/index.html.erb b/app/views/admin/enterprises/index.html.erb index 8be8afdc37..c9332020f4 100644 --- a/app/views/admin/enterprises/index.html.erb +++ b/app/views/admin/enterprises/index.html.erb @@ -11,6 +11,14 @@ <%= form_for @enterprise_set, :url => main_app.bulk_update_admin_enterprises_path do |f| %>
| Name | @@ -23,14 +31,19 @@||||
|---|---|---|---|---|
| <%= link_to enterprise.name, main_app.admin_enterprise_path(enterprise) %> | <%= 'PP ' if enterprise.is_primary_producer %><%= 'D' if enterprise.is_distributor %> | <%= enterprise_form.text_field :next_collection_at %> | <%= enterprise.description %> |
- <%= link_to_edit enterprise, :class => 'edit' %>
- <%= link_to_delete_enterprise enterprise %>
+
+ <%= link_to_with_icon('icon-edit', 'Edit Profile', main_app.admin_enterprise_path(enterprise), class: 'edit') %> + <%= link_to_delete_enterprise enterprise %> + + <%= link_to_with_icon 'icon-chevron-right', 'Payment Methods', spree.admin_payment_methods_path(enterprise_id: enterprise.id) %> (<%= enterprise.payment_methods.count %>) + <%#= link_to_with_icon 'icon-plane', 'Shipping Methods', spree.admin_shipping_methods_path %> + <%#= link_to_with_icon 'icon-money', 'Enterprise Fees', main_app.admin_enterprise_fees_path %> |