Skip to content

Commit

Permalink
Add promotion batch default action -
Browse files Browse the repository at this point in the history
csv_export.
  • Loading branch information
tomdonarski committed Nov 24, 2023
1 parent 26b1756 commit 7c538d2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/helpers/spree/admin/navigation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ def variants_actions
def product_properties_actions
Rails.application.config.spree_backend.actions[:product_properties]
end

def promotion_batch_actions
Rails.application.config.spree_backend.actions[:promotion_batch_actions]
end
# rubocop:enable Metrics/ModuleLength
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Spree
module Admin
module Actions
class PromotionBatchDefaultActionsBuilder
include Spree::Core::Engine.routes.url_helpers

def build
root = Root.new
export_codes_to_csv_action(root)
root
end

private

def export_codes_to_csv_action(root)
action =
ActionBuilder.new('csv_export', ->(resource) { csv_export_admin_promotion_batch_path(resource) }).
with_icon_key('download.svg').
with_style(::Spree::Admin::Actions::ActionStyle::PRIMARY).
build

root.add(action)
end
end
end
end
end
14 changes: 13 additions & 1 deletion app/views/spree/admin/promotion_batches/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
<% content_for :page_title do %>
<%= Spree.t(:promotion_batch) %>
<% end %>
<% end %>

<% content_for :page_actions do %>
<% promotion_batch_actions.items.each do |action| %>
<% next unless action.available?(current_ability) %>
<%= button_link_to(
Spree.t(action.label_translation_key),
action.url(@promotion_batch),
class: action.classes,
icon: action.icon_key
) %>
<% end %>
<% end %>
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

resources :promotion_categories, except: [:show]

resources :promotion_batches
resources :promotion_batches do
member do
get :csv_export
end
end

resources :zones

Expand Down
1 change: 1 addition & 0 deletions lib/spree/backend/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Engine < ::Rails::Engine
Rails.application.config.spree_backend.actions[:payments] = Spree::Admin::Actions::PaymentsDefaultActionsBuilder.new.build
Rails.application.config.spree_backend.actions[:variants] = Spree::Admin::Actions::VariantsDefaultActionsBuilder.new.build
Rails.application.config.spree_backend.actions[:product_properties] = Spree::Admin::Actions::ProductPropertiesDefaultActionsBuilder.new.build
Rails.application.config.spree_backend.actions[:promotion_batch_actions] = Spree::Admin::Actions::PromotionBatchDefaultActionsBuilder.new.build
end
end
end
Expand Down

0 comments on commit 7c538d2

Please sign in to comment.