-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3003e2a
commit a3babeb
Showing
24 changed files
with
454 additions
and
388 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
backend/app/controllers/spree/admin/promotion_code_batches_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Spree | ||
module Admin | ||
class PromotionCodeBatchesController < ResourceController | ||
belongs_to 'spree/promotion' | ||
|
||
create.after :build_promotion_code_batch | ||
|
||
def download | ||
require "csv" | ||
|
||
@promotion_code_batch = Spree::PromotionCodeBatch.find( | ||
id: params[:promotion_code_batch_id] | ||
) | ||
|
||
respond_to do |format| | ||
format.csv do | ||
filename = "promotion-code-batch-list-#{@promotion_code_batch.id}.csv" | ||
headers["Content-Type"] = "text/csv" | ||
headers["Content-disposition"] = "attachment; filename=\"#{filename}\"" | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def build_promotion_code_batch | ||
@promotion_code_batch.process | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
backend/app/views/spree/admin/promotion_code_batches/download.csv.ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CSV.generate do |csv| | ||
csv << ['Code'] | ||
@promotion_code_batch.promotion_codes.order(:id).pluck(:value).each do |value| | ||
csv << [value] | ||
end | ||
end |
65 changes: 65 additions & 0 deletions
65
backend/app/views/spree/admin/promotion_code_batches/index.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<% 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.id)) %> | ||
<% admin_breadcrumb(plural_resource_name(Spree::PromotionCodeBatch)) %> | ||
|
||
<% content_for :page_actions do %> | ||
<li> | ||
<% if can?(:create, Spree::PromotionCodeBatch) %> | ||
<%= button_link_to Spree.t(:new_promotion_code_batch), new_object_url %> | ||
<% end %> | ||
</li> | ||
<% end %> | ||
|
||
<% if @promotion_code_batches.any? %> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th><%= Spree.t("promotion_code_batches.base_code") %></th> | ||
<th><%= Spree.t("promotion_code_batches.total_codes") %></th> | ||
<th><%= Spree.t("promotion_code_batches.status") %></th> | ||
<th><%= Spree.t("promotion_code_batches.email") %></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @promotion_code_batches.each do |promotion_code_batch| %> | ||
<tr> | ||
<td><%= promotion_code_batch.base_code %></td> | ||
<td><%= promotion_code_batch.number_of_codes %></td> | ||
<td> | ||
<% if promotion_code_batch.error.present? %> | ||
<%= Spree.t( | ||
"promotion_code_batches.errored", | ||
error: promotion_code_batch.error | ||
) %> | ||
<% elsif promotion_code_batch.finished? %> | ||
<%= Spree.t( | ||
"promotion_code_batches.finished", | ||
number_of_codes: promotion_code_batch.number_of_codes | ||
) %> | ||
<%= link_to( | ||
Spree.t(:download_promotion_code_list), | ||
admin_promotion_promotion_code_batch_download_path( | ||
promotion_code_batch_id: promotion_code_batch.id, | ||
format: :csv | ||
) | ||
) %> | ||
<% else %> | ||
<%= Spree.t( | ||
"promotion_code_batches.processing", | ||
number_of_codes: promotion_code_batch.number_of_codes, | ||
number_of_codes_processed: promotion_code_batch.promotion_codes.count | ||
) %> | ||
<% end %> | ||
</td> | ||
<td><%= promotion_code_batch.email %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% else %> | ||
<div class="no-objects-found"> | ||
<%= render 'spree/admin/shared/no_objects_found', | ||
resource: Spree::PromotionCodeBatch, | ||
new_resource_url: new_object_url %> | ||
</div> | ||
<% end %> |
23 changes: 23 additions & 0 deletions
23
backend/app/views/spree/admin/promotion_code_batches/new.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<% admin_breadcrumb(link_to plural_resource_name(Spree::Promotion), spree.admin_promotions_path) %> | ||
<% admin_breadcrumb(link_to @promotion.name, spree.admin_promotion_path(@promotion.id)) %> | ||
<% admin_breadcrumb(plural_resource_name(Spree::PromotionCodeBatch)) %> | ||
|
||
<%= form_for :promotion_code_batch, url: collection_url do |f| %> | ||
<%= f.hidden_field :promotion_id, value: params[:promotion_id] %> | ||
|
||
<%= f.field_container :base_code do %> | ||
<%= f.label :base_code %> | ||
<%= f.text_field :base_code, class: "fullwidth" %> | ||
<% end %> | ||
|
||
<%= f.field_container :number_of_codes do %> | ||
<%= f.label :number_of_codes %> | ||
<%= f.text_field :number_of_codes, class: "fullwidth" %> | ||
<% end %> | ||
|
||
<%= f.field_container :email do %> | ||
<%= f.label :email %> | ||
<%= f.text_field :email, class: "fullwidth", value: spree_current_user.email %> | ||
<% end %> | ||
<%= button Spree.t('actions.create') %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Spree | ||
class PromotionCodeBatchJob < ActiveJob::Base | ||
queue_as :default | ||
|
||
def perform(promotion_batch) | ||
PromotionCode::BatchBuilder.new( | ||
promotion_batch | ||
).build_promotion_codes | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Spree | ||
class PromotionCodeBatchMailer < ApplicationMailer | ||
def promotion_code_batch_finished(promotion_code_batch) | ||
mail( | ||
to: promotion_code_batch.email, | ||
body: Spree.t( | ||
"promotion_code_batches.finished", | ||
number_of_codes: promotion_code_batch.number_of_codes | ||
), | ||
subject: Spree.t( | ||
"promotion_code_batches.email_subject.batch_finished", | ||
promotion_code_batch_id: promotion_code_batch.id | ||
), | ||
) | ||
end | ||
|
||
def promotion_code_batch_errored(promotion_code_batch) | ||
mail( | ||
to: promotion_code_batch.email, | ||
body: Spree.t( | ||
"promotion_code_batches.errored", | ||
error: promotion_code_batch.error | ||
), | ||
subject: Spree.t( | ||
"promotion_code_batches.email_subject.batch_errored", | ||
promotion_code_batch_id: promotion_code_batch.id | ||
), | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.