Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add promotion codes index view #1545

Merged
merged 1 commit into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require 'csv'

module Spree
module Admin
class PromotionCodesController < Spree::Admin::BaseController
require 'csv'

class PromotionCodesController < Spree::Admin::ResourceController
def index
@promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id])
@promotion_codes = @promotion.promotion_codes

respond_to do |format|
format.html do
@promotion_codes = @promotion_codes.page(params[:page]).per(50)
end
format.csv do
filename = "promotion-code-list-#{@promotion.id}.csv"
headers["Content-Type"] = "text/csv"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CSV.generate do |csv|
csv << ['Code']
@promotion.codes.order(:id).pluck(:value).each do |value|
@promotion_codes.order(:id).pluck(:value).each do |value|
csv << [value]
end
end
28 changes: 28 additions & 0 deletions backend/app/views/spree/admin/promotion_codes/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<% admin_breadcrumb link_to plural_resource_name(Spree::Promotion), spree.admin_promotions_path %>
<% admin_breadcrumb link_to(@promotion.name, spree.edit_admin_promotion_path(@promotion)) %>
<% admin_breadcrumb plural_resource_name(Spree::PromotionCode) %>

<% content_for :page_actions do %>
<li>
<%= button_link_to Spree.t(:download_promotion_code_list), admin_promotion_promotion_codes_path(promotion_id: @promotion.id, format: :csv) %>
</li>
<% end %>

<div class="pagination-summary">
<%= page_entries_info(@promotion_codes) %>
</div>

<table>
<thead>
<th><%= Spree::PromotionCode.human_attribute_name :value %></th>
</thead>
<tbody>
<% @promotion_codes.each do |promotion_code| %>
<tr>
<td><%= promotion_code.value %></td>
</tr>
<% end %>
</tbody>
</table>

<%= paginate @promotion_codes, theme: "solidus_admin" %>
3 changes: 3 additions & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ en:
spree/promotion_code_batch:
one: Promotion Code Batch
other: Promotion Code Batches
spree/promotion_code:
one: Promotion Code
other: Promotion Codes
spree/property:
one: Property Type
other: Property Types
Expand Down