Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Admin: new promotions UI
Damian Legawiec5c939aff34dd
diff --git a/admin/app/assets/stylesheets/spree/admin/components/_cards.scss b/admin/app/assets/stylesheets/spree/admin/components/_cards.scssindex a5b3d65b6a..1cdb631b30 100644--- a/admin/app/assets/stylesheets/spree/admin/components/_cards.scss+++ b/admin/app/assets/stylesheets/spree/admin/components/_cards.scss@@ -44,7 +44,7 @@.card-header {display: flex;align-items: center;- min-height: 50px;+ min-height: 53px;border-bottom-color: $gray-50;.card-title {diff --git a/admin/app/assets/stylesheets/spree/admin/components/_dropdowns.scss b/admin/app/assets/stylesheets/spree/admin/components/_dropdowns.scssindex 4adfb07afb..46d32a64e1 100644--- a/admin/app/assets/stylesheets/spree/admin/components/_dropdowns.scss+++ b/admin/app/assets/stylesheets/spree/admin/components/_dropdowns.scss@@ -2,7 +2,7 @@color: $gray-500 !important;}.dropdown-menu {- @extend .p-2;+ @extend .p-1;box-shadow: 0px 4px 16px 0px hsla(0, 0%, 65%, 0.3);overflow: hidden !important;diff --git a/admin/app/controllers/spree/admin/coupon_codes_controller.rb b/admin/app/controllers/spree/admin/coupon_codes_controller.rbnew file mode 100644index 0000000000..9d58f7055f--- /dev/null+++ b/admin/app/controllers/spree/admin/coupon_codes_controller.rb@@ -0,0 +1,21 @@+module Spree+ module Admin+ class CouponCodesController < ResourceController+ belongs_to 'spree/promotion', find_by: :id++ def collection+ return @collection if @collection.present?++ @collection = super++ params[:q] ||= {}+ @search = @collection.ransack(params[:q])+ @collection = if request.format.csv?+ @search.result+ else+ @search.result.page(params[:page]).per(50)+ end+ end+ end+ end+enddiff --git a/admin/app/controllers/spree/admin/promotions_controller.rb b/admin/app/controllers/spree/admin/promotions_controller.rbnew file mode 100644index 0000000000..dfe505ed59--- /dev/null+++ b/admin/app/controllers/spree/admin/promotions_controller.rb@@ -0,0 +1,52 @@+module Spree+ module Admin+ class PromotionsController < ResourceController+ # POST /admin/promotions/:id/clone+ def clone+ promotion = current_store.promotions.find(params[:id])+ duplicator = Spree::PromotionHandler::PromotionDuplicator.new(promotion)++ @new_promo = duplicator.duplicate++ if @new_promo.errors.empty?+ flash[:success] = Spree.t('promotion_cloned')+ redirect_to spree.admin_promotion_path(@new_promo)+ else+ flash[:error] = Spree.t('promotion_not_cloned', error: @new_promo.errors.full_messages.to_sentence)+ redirect_to spree.admin_promotions_path(@new_promo)+ end+ end++ protected++ def location_after_save+ spree.admin_promotion_path(@promotion)+ end++ def collection+ return @collection if defined?(@collection)++ params[:q] ||= {}++ expired = params[:q].delete(:expired) == 'true'+ active = params[:q].delete(:active) == 'true'++ @collection = super++ @collection = @collection.active if active+ @collection = @collection.expired if expired++ @search = @collection.ransack(params[:q])+ @collection = @search.result(distinct: true).+ includes(:promotion_actions).+ page(params[:page]).+ per(params[:per_page])++ params[:q][:expired] = expired+ params[:q][:active] = active++ @collection+ end+ end+ end+enddiff --git a/admin/app/helpers/spree/admin/promotions_helper.rb b/admin/app/helpers/spree/admin/promotions_helper.rbnew file mode 100644index 0000000000..28fbdb476d--- /dev/null+++ b/admin/app/helpers/spree/admin/promotions_helper.rb@@ -0,0 +1,25 @@+module Spree+ module Admin+ module PromotionsHelper+ def promotion_filter_dropdown_value+ if params.dig(:q, :expired)+ Spree.t(:expired)+ elsif params.dig(:q, :active)+ Spree.t(:active)+ else+ Spree.t(:all_promotions)+ end+ end++ def promotion_status(promotion)+ if promotion.active?+ Spree.t(:active)+ elsif promotion.expired?+ Spree.t(:expired)+ elsif promotion.inactive?+ Spree.t(:inactive)+ end+ end+ end+ end+enddiff --git a/admin/app/models/spree/admin/updater.rb b/admin/app/models/spree/admin/updater.rbindex ca79b19812..8ee433da31 100644--- a/admin/app/models/spree/admin/updater.rb+++ b/admin/app/models/spree/admin/updater.rb@@ -16,7 +16,7 @@ module Spreedef self.fetch_updates@updates ||= Rails.cache.fetch("spree/admin/updater/fetch_updates/#{Spree.version}", expires_in: 1.day) douri = URI(SPREE_CLOUD_UPDATES_URL)- params = { version: Spree.version }+ params = { version: Spree.version, environment: Rails.env, url: Spree::Store.current.url_or_custom_domain }uri.query = URI.encode_www_form(params)http = Net::HTTP.new(uri.host, uri.port)diff --git a/admin/app/views/spree/admin/coupon_codes/_coupon_code.html.erb b/admin/app/views/spree/admin/coupon_codes/_coupon_code.html.erbnew file mode 100644index 0000000000..2c4f071243--- /dev/null+++ b/admin/app/views/spree/admin/coupon_codes/_coupon_code.html.erb@@ -0,0 +1,7 @@+<tr id="">+ <td class="w-50"><code><%= coupon_code[1].upcase %></code></td>+ <td class="w-25"><%= active_badge(coupon_code[2] == 'used') %></td>+ <td class="w-25"><%= local_time(coupon_code[3]) %></td>+ <td class="actions w-35 text-right">+ </td>+</tr>diff --git a/admin/app/views/spree/admin/coupon_codes/index.csv.erb b/admin/app/views/spree/admin/coupon_codes/index.csv.erbnew file mode 100644index 0000000000..d9f7e9d413--- /dev/null+++ b/admin/app/views/spree/admin/coupon_codes/index.csv.erb@@ -0,0 +1,14 @@+<%- headers = [+ 'Coupon',+ 'State',+ 'Created at'+ ]+-%>+<%= CSV.generate_line(headers).strip %>+<%- @coupon_codes.pluck(:code, :state, :created_at).each do |coupon_code| -%>+<%= CSV.generate_line([+ coupon_code[0].upcase,+ coupon_code[1],+ coupon_code[2]+ ]).strip.html_safe %>+<%- end -%>diff --git a/admin/app/views/spree/admin/coupon_codes/index.html.erb b/admin/app/views/spree/admin/coupon_codes/index.html.erbnew file mode 100644index 0000000000..9c68fc5ec8--- /dev/null+++ b/admin/app/views/spree/admin/coupon_codes/index.html.erb@@ -0,0 +1,59 @@+<% content_for :page_title do %>+ <%= page_header_back_button spree.admin_promotions_path, @promotion %>+ <%= @promotion.name %>+<% end %>++<% content_for :page_actions do %>+ <%= link_to spree.admin_promotion_coupon_codes_path(@promotion, format: :csv), class: 'btn btn-light bg-transparent with-tip', title: 'Download coupons ad a CSV file' do %>+ <%= icon 'download' %>+ <%= Spree.t(:download) %>+ <% end %>+<% end %>++<%= turbo_frame_tag :coupon_codes do %>++ <ul id="table-tabs" class="nav nav-pills d-inline-flex mb-3">+ <li class="nav-item">+ <%= link_to Spree.t('admin.orders.all'),+ spree.admin_promotion_coupon_codes_path,+ class: "nav-link #{'active' if (params[:q] || {}).values_at(:state_eq ).all?(&:blank?)}" %>+ </li>++ <li class="nav-item">+ <%= link_to Spree.t('admin.coupon_codes.used'),+ params.merge({q: {state_eq: :used}}).permit!,+ class: "nav-link #{'active' if params.dig(:q, :state_eq) == 'used'}" %>+ </li>++ <li class="nav-item">+ <%= link_to Spree.t('admin.coupon_codes.unused'),+ params.merge({q: {state_eq: :unused}}).permit!,+ class: "nav-link #{'active' if params.dig(:q, :state_eq) == 'unused'}" %>+ </li>+ </ul>++ <div class="table-responsive card-lg p-0">+ <% if @coupon_codes.any? %>+ <table class="table">+ <thead class="text-muted">+ <tr data-hook="rate_header">+ <th><%= Spree.t(:code) %></th>+ <th><%= Spree.t(:used) %></th>+ <th><%= Spree.t(:created_at) %></th>+ <th></th>+ </tr>+ </thead>+ <tbody>+ <%= render collection: @coupon_codes.pluck(:id, :code, :state, :created_at), partial: 'spree/admin/coupon_codes/coupon_code', cached: spree_base_cache_scope %>+ </tbody>+ </table>+ <% else %>+ <div class="text-muted p-5 d-flex align-items-center w-100 justify-content-center">+ <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::CouponCode)) %>+ </div>+ <% end %>+ </div>+++ <%= render 'spree/admin/shared/index_table_options', collection: @coupon_codes, simple: true if @coupon_codes.any? %>+<% end %>\ No newline at end of filediff --git a/admin/app/views/spree/admin/promotions/_actions.html.erb b/admin/app/views/spree/admin/promotions/_actions.html.erbnew file mode 100644index 0000000000..30eaec0cfa--- /dev/null+++ b/admin/app/views/spree/admin/promotions/_actions.html.erb@@ -0,0 +1,34 @@+<div class="card-header">+ <h5 class="card-title">+ <%= Spree.t(:promotion_actions) %>+ </h5>+</div>+<div id="action_fields" class="card-body">+ <%= form_tag spree.admin_promotion_promotion_actions_path(@promotion), remote: true, id: 'new_promotion_action_form', class: 'mb-3' do %>+ <% options = options_for_select( @actions.map(&:name).map {|name| [ Spree.t("promotion_action_types.#{name.demodulize.underscore}.name"), name] } ) %>++ <div class="form-group">+ <%= label_tag :action_type, Spree.t(:add_action_of_type) %>+ <%= select_tag 'action_type', options, class: 'custom-select' %>+ </div>+ <div class="form-actions">+ <%= button Spree.t(:add), 'plus', 'submit', class: "btn-light" %>+ </div>++ <% end %>++ <%= form_for @promotion, url: spree.admin_promotion_path(@promotion), method: :put do |f| %>+ <div id="actions" class="filter_list mt-3">+ <% if @promotion.actions.any? %>+ <%= render partial: 'promotion_action', collection: @promotion.actions %>+ <% else %>+ <div class="alert alert-warning">+ <%= Spree.t(:no_actions_added) %>+ </div>+ <% end %>+ </div>+ <div class="actions promotion-update">+ <%= turbo_save_button_tag Spree.t('actions.update') %>+ </div>+ <% end %>+</div>diff --git a/admin/app/views/spree/admin/promotions/_form.html.erb b/admin/app/views/spree/admin/promotions/_form.html.erbnew file mode 100644index 0000000000..220094d768--- /dev/null+++ b/admin/app/views/spree/admin/promotions/_form.html.erb@@ -0,0 +1,47 @@+<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @promotion } %>++<div class="row">+ <div class="col-12 col-lg-8">+ <div class="card mb-4">+ <div class="card-header">+ <h5 class="card-title">+ <%= Spree.t(:details) %>+ </h5>+ </div>+ <div class="card-body">+ <div class="form-group">+ <%= f.label :name %>+ <%= f.text_field :name, class: 'form-control', required: true, autofocus: true %>+ <%= f.error_message_on :name %>+ <span class="form-text text-muted mt-2">+ Customers will see this in their cart and at checkout.+ </span>+ </div>+ </div>+ </div>++ <div class="card">+ <div class="card-header">+ <h5 class="card-title">+ <%= Spree.t(:promotion_kind) %>+ </h5>+ </div>+ <div class="card-body">+ <%= render 'spree/admin/promotions/form/kind', f: f %>+ </div>+ </div>+ </div>++ <div class="col-12 col-lg-4">+ <div class="card">+ <div class="card-header">+ <h5 class="card-title">+ <%= Spree.t(:settings) %>+ </h5>+ </div>+ <div class="card-body">+ <%= render 'spree/admin/promotions/form/settings', f: f %>+ </div>+ </div>+ </div>+</div>diff --git a/admin/app/views/spree/admin/promotions/_promotion.html.erb b/admin/app/views/spree/admin/promotions/_promotion.html.erbnew file mode 100644index 0000000000..6a9b87eb7b--- /dev/null+++ b/admin/app/views/spree/admin/promotions/_promotion.html.erb@@ -0,0 +1,23 @@+<tr id="<%= spree_dom_id promotion %>" data-controller="row-link">+ <td class="w-20 p-0">+ <%= link_to promotion.name, spree.admin_promotion_path(promotion), class: 'font-weight-bold d-block py-2 px-3 w-100 h-100', data: { row_link_target: :link } %>+ </td>+ <td class="w-20 cursor-pointer" data-action="click->row-link#openLink">+ <% if promotion.coupon_code? && promotion.code.present? %>+ <code><%= promotion.code %></code>+ <% end %>+ </td>+ </td>+ <td class="w-10 cursor-pointer" data-action="click->row-link#openLink">+ <%= promotion.kind.humanize %>+ </td>+ <td class="w-10 cursor-pointer" data-action="click->row-link#openLink">+ <%= render 'spree/admin/promotions/usage_limit', promotion: promotion %>+ </td>+ <td class="w-10 cursor-pointer" data-action="click->row-link#openLink">+ <%= render 'spree/admin/promotions/status', promotion: promotion %>+ </td>+ <td class="actions w-10">+ <%= link_to_with_icon 'edit', Spree.t(:edit), spree.admin_promotion_path(promotion), icon: 'pencil', class: 'btn btn-sm btn-light' %>+ </td>+</tr>\ No newline at end of filediff --git a/admin/app/views/spree/admin/promotions/_status.html.erb b/admin/app/views/spree/admin/promotions/_status.html.erbnew file mode 100644index 0000000000..9d42e43a50--- /dev/null+++ b/admin/app/views/spree/admin/promotions/_status.html.erb@@ -0,0 +1,13 @@+<% if promotion.active? %>+ <span class="badge badge-success">+ <%= Spree.t(:active) %>+ </span>+<% elsif promotion.inactive? %>+ <span class="badge badge-light">+ <%= Spree.t(:inactive) %>+ </span>+<% else %>+ <span class="badge badge-danger">+ <%= Spree.t(:expired) %>+ </span>+<% end %>\ No newline at end of filediff --git a/admin/app/views/spree/admin/promotions/_table_filter_dropdown.html.erb b/admin/app/views/spree/admin/promotions/_table_filter_dropdown.html.erbnew file mode 100644index 0000000000..56d699417d--- /dev/null+++ b/admin/app/views/spree/admin/promotions/_table_filter_dropdown.html.erb@@ -0,0 +1,17 @@+<div class="dropdown h-100 mr-2">+ <button class="btn btn-light h-100 dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">+ <span class="text-muted font-weight-normal">+ <%= Spree.t(:status) %>+ </span>+ <%= promotion_filter_dropdown_value %>+ </button>+ <div class="dropdown-menu dropdown-menu-right w-100" style="min-width: 200px">+ <%= active_link_to 'All Promotions', params.to_unsafe_h.deep_merge({page: nil, q: {active: nil, expired: nil}}), class: 'dropdown-item', active: (params[:q] || {}).values_at(*%w[expired active] ).all?(&:blank?) %>+ <%= link_to Spree.t(:expired),+ params.to_unsafe_h.deep_merge({page: nil, q: {active: nil, expired: true}}),+ class: "dropdown-item #{'active' if params[:q][:expired]}" %>+ <%= link_to Spree.t(:active),+ params.to_unsafe_h.deep_merge({page: nil, q: {active: true, expired: false}}),+ class: "dropdown-item #{'active' if params[:q][:active]}" %>+ </div>+</div>diff --git a/admin/app/views/spree/admin/promotions/_usage_limit.html.erb b/admin/app/views/spree/admin/promotions/_usage_limit.html.erbnew file mode 100644index 0000000000..95bfff47f3--- /dev/null+++ b/admin/app/views/spree/admin/promotions/_usage_limit.html.erb@@ -0,0 +1,13 @@+<% if promotion.multi_codes? %>+ <span class="badge badge-light">+ <%= promotion.coupon_codes.used.count %>+ /+ <%= promotion.coupon_codes.count %>+ </span>+<% else %>+ <span class="badge badge-light">+ <%= promotion.credits_count %>+ /+ <%= promotion.usage_limit || '∞' %>+ </span>+<% end %>diff --git a/admin/app/views/spree/admin/promotions/edit.html.erb b/admin/app/views/spree/admin/promotions/edit.html.erbnew file mode 100644index 0000000000..4331ee940e--- /dev/null+++ b/admin/app/views/spree/admin/promotions/edit.html.erb@@ -0,0 +1,53 @@+<% content_for :page_title do %>+ <%= page_header_back_button spree.admin_promotions_path, @promotion %>+ <%= @promotion.name %>+<% end %>++<%= turbo_frame_tag :promotion_edit_details do %>+ <%= form_for @promotion, url: object_url, method: :put, data: { turbo_frame: '_top' } do |f| %>+ <div class="card mb-4">+ <div class="card-header d-flex justify-content-between">+ <h5 class="card-title">+ <%= Spree.t(:details) %>+ </h5>+ </div>+ <div class="card-body">+ <div class="form-group">+ <%= f.label :name %>+ <%= f.text_field :name, class: 'form-control', required: true, autofocus: true %>+ <%= f.error_message_on :name %>+ <span class="form-text text-muted mt-2">+ Customers will see this in their cart and at checkout.+ </span>+ </div>+ </div>+ <div class="card-footer d-flex justify-content-between">+ <%= turbo_save_button_tag Spree.t('actions.update') %>+ <%= link_to spree.admin_promotion_path(@promotion), class: 'btn btn-light' do %>+ <%= Spree.t('actions.discard') %>+ <% end %>+ </div>+ </div>+ <% end %>+<% end %>++<%= turbo_frame_tag :promotion_edit_settings do %>+ <%= form_for @promotion, url: object_url, method: :put do |f| %>+ <div class="card">+ <div class="card-header">+ <h5 class="card-title">+ <%= Spree.t(:settings) %>+ </h5>+ </div>+ <div class="card-body">+ <%= render 'spree/admin/promotions/form/settings', f: f %>+ </div>+ <div class="card-footer d-flex justify-content-between">+ <%= turbo_save_button_tag Spree.t('actions.update') %>+ <%= link_to spree.admin_promotion_path(@promotion), class: 'btn btn-light' do %>+ <%= Spree.t('actions.discard') %>+ <% end %>+ </div>+ </div>+ <% end %>+<% end %>diff --git a/admin/app/views/spree/admin/promotions/form/_kind.html.erb b/admin/app/views/spree/admin/promotions/form/_kind.html.erbnew file mode 100644index 0000000000..dc57c285df--- /dev/null+++ b/admin/app/views/spree/admin/promotions/form/_kind.html.erb@@ -0,0 +1,57 @@+<div class="custom-control custom-radio">+ <%= f.radio_button :kind, :coupon_code, data: { toggle: :collapse, target: '#coupon-code' }, class: 'custom-control-input' %>+ <%= f.label :kind_coupon_code, Spree.t(:coupon_code), class: 'custom-control-label' %>++ <div id="coupon-code" class="rounded p-3 bg-gray-25 mt-3 collapse <% unless @promotion.automatic? %>show<% end %>">+ <div class="d-flex align-items-start custom-control custom-radio">+ <%= f.radio_button :multi_codes, false, data: { toggle: :collapse, target: '#single-code' }, class: 'custom-control-input' %>+ <%= f.label :multi_codes_false, class: 'custom-control-label' do %>+ One code for all customers+ <span class="form-text text-muted font-weight-normal">+ You can limit the number of times this code can be used.+ </span>+ <% end %>+ </div>+ <div id="single-code" class="mb-4 mt-2 ml-4 collapse <% unless @promotion.multi_codes? %>show<% end %>" data-parent="#coupon-code">+ <%= f.text_field :code, class: 'form-control text-uppercase', placeholder: 'Your coupon code' %>+ </div>++ <div class="mt-2 d-flex align-items-start custom-control custom-radio">+ <%= f.radio_button :multi_codes, true, data: { toggle: :collapse, target: '#multi-codes' }, class: 'custom-control-input' %>+ <%= f.label :multi_codes_true, class: 'custom-control-label' do %>+ Generate unique codes+ <span class="form-text text-muted font-weight-normal">+ These codes are generated automatically and can be downloaded as a CSV file. Codes are unique and can only be used once.+ </span>+ <% end %>+ </div>+ <div id="multi-codes" class="ml-3 mt-2 row collapse <% if @promotion.multi_codes? %>show<% end %>" data-parent="#coupon-code">+ <div class="col-6">+ <%= f.text_field :code_prefix, class: 'form-control text-uppercase', placeholder: 'Coupon Prefix (optional)' %>+ <span class="form-text text-muted">+ eg. <strong>ABC</strong>+ </span>+ </div>+ <div class="col-6">+ <% minimum_number_of_codes = @promotion.persisted? && @promotion.coupon_codes.count.positive? ? @promotion.coupon_codes.count : 1 %>+ <% maximum_number_of_codes = ENV.fetch('PROMOTION_MAX_NUMBER_OF_CODES', 5000) %>+ <%= f.number_field :number_of_codes, class: 'form-control', placeholder: 'Number of codes', min: minimum_number_of_codes, max: maximum_number_of_codes, step: 1 %>+ <span class="form-text text-muted">+ How many codes you want to generate.+ <% if @promotion.persisted? %>+ To add more codes just increase this number+ <% end %>+ </span>+ </div>+ </div>+ </div>+</div>++<div class="mt-4 custom-control custom-radio">+ <%= f.radio_button :kind, :automatic, data: { toggle: :collapse, target: '#coupon-code' }, class: 'custom-control-input' %>+ <%= f.label :kind_automatic, Spree.t(:automatic), class: 'custom-control-label' %>++ <p class="form-text text-muted mt-2 mb-0">+ This promotion will be automatically applied to all eligible orders.+ </p>+</div>\ No newline at end of filediff --git a/admin/app/views/spree/admin/promotions/form/_settings.html.erb b/admin/app/views/spree/admin/promotions/form/_settings.html.erbnew file mode 100644index 0000000000..702ea2f2b4--- /dev/null+++ b/admin/app/views/spree/admin/promotions/form/_settings.html.erb@@ -0,0 +1,29 @@+<% unless @promotion.multi_codes? %>+ <div class="form-group">+ <%= f.label :usage_limit, Spree.t('limit_usage_to') %>+ <%= f.number_field :usage_limit, min: 0, step: 1, class: 'form-control' %>+ <span class="form-text text-muted mt-2">+ Leave this field blank for unlimited usage.+ </span>+ </div>+ <% if @promotion.persisted? %>+ <span class="form-text text-muted">+ <%= Spree.t(:current_promotion_usage, count: @promotion.credits_count) %>+ </span>+ <% end %>+<% end %>++<div class="form-group">+ <%= f.label :starts_at %>+ <%= f.datetime_field :starts_at, class: 'form-control' %>+ <%= f.error_message_on :starts_at %>+</div>++<div class="form-group">+ <%= f.label :expires_at %>+ <%= f.datetime_field :expires_at, class: 'form-control' %>+ <%= f.error_message_on :expires_at %>+ <span class="form-text text-muted mt-2">+ Leave this field blank for no expiration.+ </span>+</div>diff --git a/admin/app/views/spree/admin/promotions/index.html.erb b/admin/app/views/spree/admin/promotions/index.html.erbnew file mode 100644index 0000000000..82e36e62b5--- /dev/null+++ b/admin/app/views/spree/admin/promotions/index.html.erb@@ -0,0 +1,62 @@+<% content_for :page_title do %>+ <%= Spree.t(:promotions) %>+<% end %>++<% content_for :page_actions do %>+ <%= button_link_to Spree.t(:new_promotion), new_object_url, class: "btn-primary", icon: "plus" %>+<% end if can?(:create, Spree::Promotion) %>++<div class="card-lg p-0">+ <%= search_form_for [:admin, @search], class: "filter-wrap border-bottom", data: {controller: "filters reveal", reveal_hidden_class: "d-none"} do |f| %>+ <div class="d-flex flex-column flex-lg-row gap-2">+ <%= render 'spree/admin/shared/filters_search_bar', param: :name_cont, label: Spree.t(:name) %>++ <div class="d-flex align-items-center justify-content-between">+ <%= render "spree/admin/promotions/table_filter_dropdown" %>++ <%= render 'spree/admin/shared/filters_button' %>+ </div>+ </div>+ <div data-reveal-target="item" class="d-none mt-4" id="table-filter">+ <div class="row">+ <div class="col-12 col-lg-6">+ <div class="form-group">+ <%= label_tag :q_code_or_coupon_codes_code_eq, Spree.t(:code) %>+ <%= f.search_field :code_or_coupon_codes_code_eq, class: "form-control", data: { filters_target: :input } %>+ </div>+ </div>+ </div>++ <div class="form-actions">+ <%= button Spree.t(:filter_results), "search" %>+ </div>+ </div>++ <%= render "spree/admin/shared/filter_badge_template" %>++ <div data-filters-target="badgesContainer" class="filter-badges-container"></div>+ <% end %>++ <% if @promotions.any? %>+ <div class="table-responsive">+ <table class="table">+ <thead class="text-muted">+ <tr>+ <th><%= Spree.t(:name) %></th>+ <th><%= Spree.t(:code) %></th>+ <th><%= Spree.t(:kind) %></th>+ <th><%= Spree.t(:usage_limit) %></th>+ <th><%= Spree.t(:status) %></th>+ <th class="actions"></th>+ </tr>+ </thead>+ <tbody>+ <%= render collection: @promotions, partial: "spree/admin/promotions/promotion", cached: spree_base_cache_scope %>+ </tbody>+ </table>+ </div>+ <%= render "spree/admin/shared/index_table_options", collection: @promotions, simple: true %>+ <% else %>+ <%= render "spree/admin/shared/no_resource_found" %>+ <% end %>+</div>diff --git a/admin/app/views/spree/admin/promotions/new.html.erb b/admin/app/views/spree/admin/promotions/new.html.erbnew file mode 100644index 0000000000..314455a986--- /dev/null+++ b/admin/app/views/spree/admin/promotions/new.html.erb@@ -0,0 +1,11 @@+<% content_for :page_title do %>+ <%= page_header_back_button spree.admin_promotions_path, @promotion %>+ <%= Spree.t(:new_promotion) %>+<% end %>+<%= form_for :promotion, url: collection_url do |f| %>+ <%= render 'form', f: f %>+ <p class="alert alert-info text-center mt-3">+ In the next step you will be able to add actions and rules to your promotion+ </p>+ <%= render 'spree/admin/shared/new_resource_links' %>+<% end %>diff --git a/admin/app/views/spree/admin/promotions/show.html.erb b/admin/app/views/spree/admin/promotions/show.html.erbnew file mode 100644index 0000000000..22fe2db458--- /dev/null+++ b/admin/app/views/spree/admin/promotions/show.html.erb@@ -0,0 +1,127 @@+<% content_for :page_title do %>+<%= page_header_back_button spree.admin_promotions_path, @promotion %>+<%= @promotion.name %>+<div class="ml-3">+ <%= render 'spree/admin/promotions/status', promotion: @promotion %>+</div>+<% end %>++<div class="row">+ <div class="col-12 col-lg-8">+ <% if @promotion.multi_codes? %>+ <%= turbo_frame_tag :coupon_codes, src: spree.admin_promotion_coupon_codes_path(@promotion) %>+ <% end %>+ </div>++ <div class="col-12 col-lg-4">+ <% if @promotion.multi_codes? %>+ <% coupon_codes_count = @promotion.coupon_codes.count %>+ <% if coupon_codes_count.positive? %>+ <% used_coupon_codes_count = @promotion.coupon_codes.used.count %>+ <% remaining_coupon_codes_count = coupon_codes_count - used_coupon_codes_count %>++ <div class="card mb-4">+ <div class="card-body">+ <progress max="<%= coupon_codes_count %>" value="<%= used_coupon_codes_count %>" class="w-100"></progress>+ </div>+ <div class="card-footer d-flex justify-content-between">+ <div>+ Used: <%= used_coupon_codes_count %> / <%= coupon_codes_count %>+ </div>+ <div>+ Remaining: <%= coupon_codes_count - used_coupon_codes_count %>+ </div>+ </div>+ </div>+ <% end %>+ <% end %>++ <%= turbo_frame_tag :promotion_edit_details do %>+ <div class="card mb-4">+ <div class="card-header d-flex justify-content-between">+ <h5 class="card-title">+ <%= Spree.t(:details) %>+ </h5>+ <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_promotion_path(@promotion), icon: 'pencil', class: 'btn btn-sm btn-light' %>+ </div>+ <div class="card-body">+ <ul class="list-group">+ <li class="list-group-item d-flex justify-content-between">+ <span class="text-muted">+ <%= Spree.t(:name) %>+ </span>+ <span>+ <%= @promotion.name %>+ </span>+ </li>++ <li class="list-group-item d-flex justify-content-between">+ <span class="text-muted">+ <%= Spree.t(:kind) %>+ </span>+ <span class="badge badge-light">+ <%= @promotion.kind.titleize %>+ </span>+ </li>++ <% if @promotion.code.present? %>+ <li class="list-group-item d-flex justify-content-between" data-controller="clipboard" data-clipboard-success-content="Copied!">+ <%= Spree.t(:coupon_code) %>+ <span>+ <span class="p-2 bg-light rounded mr-2 h-100">+ <span data-clipboard-target="source"><%= @promotion.code.upcase %></span>+ </span>++ <button type="button" class="btn btn-light btn-sm with-tip p-1" data-action="clipboard#copy" title="<%= Spree.t(:copy) %>">+ <%= icon 'copy', class: 'mr-0' %>+ </button>+ </span>+ </li>+ <% end %>+ </ul>+ </div>+ </div>+ <% end%>++ <%= turbo_frame_tag :promotion_edit_settings do %>+ <div class="card">+ <div class="card-header d-flex justify-content-between">+ <h5 class="card-title">+ <%= Spree.t(:settings) %>+ </h5>+ <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_promotion_path(@promotion), icon: 'pencil', class: 'btn btn-sm btn-light' %>+ </div>+ <div class="card-body">+ <ul class="list-group">+ <% unless @promotion.multi_codes? %>+ <li class="list-group-item d-flex justify-content-between">+ <%= Spree.t(:usage_limit) %>+ <%= render 'spree/admin/promotions/usage_limit', promotion: @promotion %>+ </li>+ <% end %>+ <li class="list-group-item d-flex justify-content-between">+ <span class="text-muted">+ <%= I18n.t('activerecord.attributes.spree/promotion.starts_at') %>+ </span>+ <% if @promotion.starts_at %>+ <span><%= local_time(@promotion.starts_at) %></span>+ <% else %>+ <span class="text-muted"><%= Spree.t(:no_start_date) %></span>+ <% end %>+ </li>+ <li class="list-group-item d-flex justify-content-between">+ <span class="text-muted">+ <%= I18n.t('activerecord.attributes.spree/promotion.expires_at') %>+ </span>+ <% if @promotion.expires_at %>+ <span><%= local_time(@promotion.expires_at) %></span>+ <% else %>+ <span class="text-muted"><%= Spree.t(:no_expiration) %></span>+ <% end %>+ </li>+ </ul>+ </div>+ </div>+ <% end %>+ </div>+</div>\ No newline at end of filediff --git a/admin/app/views/spree/admin/reports/new.html.erb b/admin/app/views/spree/admin/reports/new.html.erbindex 7ea3a4f4d6..9a04b73a11 100644--- a/admin/app/views/spree/admin/reports/new.html.erb+++ b/admin/app/views/spree/admin/reports/new.html.erb@@ -9,9 +9,9 @@<%= f.hidden_field :date_from %><%= f.hidden_field :date_to %><%= f.hidden_field :currency %>- <button class="btn btn-light with-tip" title="Export report in a CSV format">- <%= icon('table-export') %>- <%= Spree.t(:export) %>+ <button class="btn btn-light with-tip" title="Download report as CSV file">+ <%= icon('download') %>+ <%= Spree.t(:download) %></button><% end %><% end %>diff --git a/admin/app/views/spree/admin/shared/_content_header.html.erb b/admin/app/views/spree/admin/shared/_content_header.html.erbindex ec20db0c3d..9ac2a5b1f4 100644--- a/admin/app/views/spree/admin/shared/_content_header.html.erb+++ b/admin/app/views/spree/admin/shared/_content_header.html.erb@@ -14,9 +14,9 @@<div id="page_actions" class="ml-auto page-actions d-flex align-items-center gap-2"><% if action_name == 'index' && defined?(model_class) && model_class && Spree::Export.available_models.include?(model_class) %><span data-toggle="modal" data-target="#modal">- <%= link_to spree.new_admin_export_path(export: { search_params: params[:q]&.to_json, type: Spree::Export.type_for_model(model_class) }), class: 'btn btn-light bg-transparent', data: { turbo_frame: :dialog_modal } do %>- <%= icon 'table-export', class: 'mr-0 mr-lg-2' %>- <span class="d-none d-lg-inline"><%= Spree.t(:export) %></span>+ <%= link_to spree.new_admin_export_path(export: { search_params: params[:q]&.to_json, type: Spree::Export.type_for_model(model_class) }), class: 'btn btn-light bg-transparent with-tip', title: 'Download records as CSV file', data: { turbo_frame: :dialog_modal } do %>+ <%= icon 'download', class: 'mr-0 mr-lg-2' %>+ <span class="d-none d-lg-inline"><%= Spree.t(:download) %></span><% end %></span><% end %>diff --git a/admin/app/views/spree/admin/themes/index.html.erb b/admin/app/views/spree/admin/themes/index.html.erbindex f839410716..f381808f98 100644--- a/admin/app/views/spree/admin/themes/index.html.erb+++ b/admin/app/views/spree/admin/themes/index.html.erb@@ -48,13 +48,13 @@<div class="card-header"><h5 class="card-title">Add a new theme</h5></div>- <div class="card-body">+ <div class="card-body pb-0"><p>Pick a theme from the list of available themes</p><div class="row row-cols-1 row-cols-md-2 row-cols-lg-3"><% available_themes.each do |theme| %><div class="col mb-4">- <div class="card">+ <div class="card hover-light"><% if theme.preview_image_url.present? %><%= image_tag theme.preview_image_url, class: 'card-img-top' %><% end %>diff --git a/core/app/models/spree/promotion.rb b/core/app/models/spree/promotion.rbindex 29d0f96e2c..f80cc8f24b 100644--- a/core/app/models/spree/promotion.rb+++ b/core/app/models/spree/promotion.rb@@ -112,8 +112,16 @@ module Spreeendend+ def active?+ starts_at.present? && starts_at < Time.current && (expires_at.blank? || !expired?)+ end++ def inactive?+ !active?+ end+def expired?- !!(starts_at && Time.current < starts_at || expires_at && Time.current > expires_at)+ expires_at.present? && expires_at < Time.currentenddef activate(payload)diff --git a/core/config/locales/en.yml b/core/config/locales/en.ymlindex f9e07a17d2..3328a2cf8e 100644--- a/core/config/locales/en.yml+++ b/core/config/locales/en.yml@@ -760,7 +760,8 @@ en:continue_as_guest: Continue as a guestcontinue_selling_when_out_of_stock: Continue selling when out of stockcontinue_shopping: Continue shopping- copy_id: Copy+ copy: Copy+ copy_id: Copy IDcopy_link: Copy linkcopy_payment_link: Copy payment linkcopy_to_clipboard: Copy to clipboard@@ -782,6 +783,7 @@ en:label: Choose must be shipped to this countrycoupon: Couponcoupon_code: Coupon code+ coupon_codes: Coupon codescoupon_code_already_applied: The coupon code has already been applied to this ordercoupon_code_applied: The coupon code was successfully applied to your order.coupon_code_apply: Apply