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 Promotions: fixed translations, UI, only allow to create action/rule not used before
Damian Legawiec89841fb40323
diff --git a/admin/app/helpers/spree/admin/promotion_actions_helper.rb b/admin/app/helpers/spree/admin/promotion_actions_helper.rbnew file mode 100644index 0000000000..5e18cba0dc--- /dev/null+++ b/admin/app/helpers/spree/admin/promotion_actions_helper.rb@@ -0,0 +1,10 @@+module Spree+ module Admin+ module PromotionActionsHelper+ def options_for_promotion_action_types(promotion)+ existing = promotion.actions.map { |action| action.class.name }+ Rails.application.config.spree.promotions.actions.map(&:name).reject { |r| existing.include? r }+ end+ end+ end+enddiff --git a/admin/app/helpers/spree/admin/promotions_helper.rb b/admin/app/helpers/spree/admin/promotions_helper.rbindex 28fbdb476d..df85e4eccf 100644--- a/admin/app/helpers/spree/admin/promotions_helper.rb+++ b/admin/app/helpers/spree/admin/promotions_helper.rb@@ -7,7 +7,7 @@ module Spreeelsif params.dig(:q, :active)Spree.t(:active)else- Spree.t(:all_promotions)+ Spree.t(:all)endenddiff --git a/admin/app/views/spree/admin/coupon_codes/index.html.erb b/admin/app/views/spree/admin/coupon_codes/index.html.erbindex 0ac9607c24..83bf9920d1 100644--- a/admin/app/views/spree/admin/coupon_codes/index.html.erb+++ b/admin/app/views/spree/admin/coupon_codes/index.html.erb@@ -18,7 +18,7 @@<%= Spree.t('admin.coupon_codes.unused') if params.dig(:q, :state_eq) == 'unused' %></button><div class="dropdown-menu w-100 font-size-sm" style="min-width: 200px">- <%= active_link_to Spree.t('admin.orders.all'),+ <%= active_link_to Spree.t(:all),spree.admin_promotion_coupon_codes_path,class: 'dropdown-item',active: (params[:q] || {}).values_at(:state_eq).all?(&:blank?) %>diff --git a/admin/app/views/spree/admin/promotion_actions/new.html.erb b/admin/app/views/spree/admin/promotion_actions/new.html.erbindex 7426bc9d23..4119940184 100644--- a/admin/app/views/spree/admin/promotion_actions/new.html.erb+++ b/admin/app/views/spree/admin/promotion_actions/new.html.erb@@ -15,10 +15,10 @@<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @promotion_action } %><% if @promotion_action.type.nil? %><ul class="list-group">- <% allowed_action_types.each do |action_type| %>+ <% options_for_promotion_action_types(@promotion).each do |action_type| %><% key = action_type.to_s.demodulize.underscore %>- <li class="list-group-item p-0">- <%= link_to spree.new_admin_promotion_action_path(@promotion, promotion_action: { type: action_type }), class: 'd-flex align-items-top w-100 p-3 hover-light', data: { turbo_prefetch: false } do %>+ <li class="list-group-item p-0 overflow-hidden">+ <%= link_to spree.new_admin_promotion_action_path(@promotion, promotion_action: { type: action_type }), class: 'd-flex align-items-top w-100 py-2 px-3 hover-light', data: { turbo_prefetch: false } do %><%= radio_button_tag :type, action_type, checked: @promotion_action.type == action_type %><div class="ml-3"><h6><%= Spree.t("promotion_action_types.#{key}.name") %></h6>diff --git a/admin/app/views/spree/admin/promotion_rules/new.html.erb b/admin/app/views/spree/admin/promotion_rules/new.html.erbindex 3dc64cb5d3..8ceee9bb7f 100644--- a/admin/app/views/spree/admin/promotion_rules/new.html.erb+++ b/admin/app/views/spree/admin/promotion_rules/new.html.erb@@ -17,8 +17,8 @@<ul class="list-group"><% options_for_promotion_rule_types(@promotion).each do |rule_type| %><% key = rule_type.demodulize.underscore %>- <li class="list-group-item p-0">- <%= link_to spree.new_admin_promotion_rule_path(@promotion, promotion_rule: { type: rule_type }), class: 'd-flex align-items-top w-100 p-3 hover-light', data: { turbo_prefetch: false } do %>+ <li class="list-group-item p-0 overflow-hidden">+ <%= link_to spree.new_admin_promotion_rule_path(@promotion, promotion_rule: { type: rule_type }), class: 'd-flex align-items-top w-100 py-2 px-3 hover-light', data: { turbo_prefetch: false } do %><%= radio_button_tag :type, rule_type %><div class="ml-3"><h6><%= Spree.t("promotion_rule_types.#{key}.name") %></h6>diff --git a/admin/app/views/spree/admin/promotions/_actions.html.erb b/admin/app/views/spree/admin/promotions/_actions.html.erbindex 2bf4daab81..de99b549d5 100644--- a/admin/app/views/spree/admin/promotions/_actions.html.erb+++ b/admin/app/views/spree/admin/promotions/_actions.html.erb@@ -11,7 +11,7 @@<div class="card-body pb-0"><% if @promotion.promotion_actions.empty? %><div class="text-muted p-5 d-flex align-items-center w-100 justify-content-center">- <%= Spree.t(:no_resource_found, resource: Spree.t(:promotion_actions)) %>+ <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::PromotionAction)) %><span data-toggle="modal" data-target="#modal"><%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_action_path(@promotion), class: 'btn btn-light btn-sm ml-3', data: { turbo_frame: 'dialog_modal' } %></span>diff --git a/admin/app/views/spree/admin/promotions/_form.html.erb b/admin/app/views/spree/admin/promotions/_form.html.erbindex 8618b679df..bed1b7067b 100644--- a/admin/app/views/spree/admin/promotions/_form.html.erb+++ b/admin/app/views/spree/admin/promotions/_form.html.erb@@ -23,7 +23,7 @@<div class="card"><div class="card-header"><h5 class="card-title">- <%= Spree.t(:promotion_kind) %>+ <%= Spree.t(:kind) %></h5></div><div class="card-body">diff --git a/admin/app/views/spree/admin/promotions/_promotion.html.erb b/admin/app/views/spree/admin/promotions/_promotion.html.erbindex 6a9b87eb7b..16b375a3e5 100644--- a/admin/app/views/spree/admin/promotions/_promotion.html.erb+++ b/admin/app/views/spree/admin/promotions/_promotion.html.erb@@ -4,12 +4,23 @@</td><td class="w-20 cursor-pointer" data-action="click->row-link#openLink"><% if promotion.coupon_code? && promotion.code.present? %>- <code><%= promotion.code %></code>+ <code><%= promotion.code.upcase %></code>+ <% elsif promotion.multi_codes? && promotion.code_prefix.present? %>+ <code><%= promotion.code_prefix %>-<%= '*' * 6 %></code>+ <% else %>+ <span class="text-muted small"><%= Spree.t(:not_available) %></span><% end %></td></td><td class="w-10 cursor-pointer" data-action="click->row-link#openLink">- <%= promotion.kind.humanize %>+ <span class="badge badge-<% if promotion.automatic? %>info<% else %>light<% end %>">+ <% if promotion.automatic? %>+ <%= icon('automation', class: 'mr-1') %>+ <% else %>+ <%= icon('ticket', class: 'mr-1') %>+ <% end %>+ <%= promotion.kind.humanize %>+ </span></td><td class="w-10 cursor-pointer" data-action="click->row-link#openLink"><%= render 'spree/admin/promotions/usage_limit', promotion: promotion %>diff --git a/admin/app/views/spree/admin/promotions/_rules.html.erb b/admin/app/views/spree/admin/promotions/_rules.html.erbindex bdbdd72b24..e37a7686a7 100644--- a/admin/app/views/spree/admin/promotions/_rules.html.erb+++ b/admin/app/views/spree/admin/promotions/_rules.html.erb@@ -25,8 +25,10 @@<div class="card-body py-0"><% if @promotion.promotion_rules.empty? %><div class="text-muted p-5 d-flex align-items-center w-100 justify-content-center">- <%= Spree.t(:no_resource_found, resource: Spree.t(:promotion_rules)) %>- <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_rule_path(@promotion), class: 'btn btn-light btn-sm', data: { turbo_frame: 'dialog_modal' } %>+ <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::PromotionRule)) %>+ <span data-toggle="modal" data-target="#modal">+ <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_rule_path(@promotion), class: 'btn btn-light btn-sm ml-3', data: { turbo_frame: 'dialog_modal' } %>+ </span></div><% else %><%= render collection: @promotion.promotion_rules, partial: 'spree/admin/promotion_rules/promotion_rule', as: :promotion_rule %>diff --git a/admin/app/views/spree/admin/promotions/_sidebar.html.erb b/admin/app/views/spree/admin/promotions/_sidebar.html.erbindex 1ef5038be4..22f61cc34d 100644--- a/admin/app/views/spree/admin/promotions/_sidebar.html.erb+++ b/admin/app/views/spree/admin/promotions/_sidebar.html.erb@@ -9,6 +9,7 @@<h5 class="card-title"><%= Spree.t(:coupon_codes) %></h5>+ <%= link_to_with_icon 'eye', Spree.t(:view), spree.admin_promotion_coupon_codes_path(@promotion), class: 'btn btn-sm btn-light' %></div><div class="card-body"><div class="progress">@@ -97,7 +98,7 @@<% if @promotion.starts_at %><span><%= local_time(@promotion.starts_at) %></span><% else %>- <span class="text-muted"><%= Spree.t(:no_start_date) %></span>+ <span class="text-muted"><%= Spree.t(:not_available) %></span><% end %></li><li class="list-group-item d-flex justify-content-between align-items-center">diff --git a/admin/app/views/spree/admin/promotions/_status.html.erb b/admin/app/views/spree/admin/promotions/_status.html.erbindex 9d42e43a50..dd463acd46 100644--- a/admin/app/views/spree/admin/promotions/_status.html.erb+++ b/admin/app/views/spree/admin/promotions/_status.html.erb@@ -1,13 +1,16 @@<% if promotion.active? %><span class="badge badge-success">+ <%= icon('check', class: 'mr-1') %><%= Spree.t(:active) %></span>-<% elsif promotion.inactive? %>- <span class="badge badge-light">- <%= Spree.t(:inactive) %>- </span>-<% else %>+<% elsif promotion.expired? %><span class="badge badge-danger">+ <%= icon('clock-x', class: 'mr-1') %><%= Spree.t(:expired) %></span>+<% else %>+ <span class="badge badge-light">+ <%= icon('clock-pause', class: 'mr-1') %>+ <%= Spree.t(:inactive) %>+ </span><% end %>\ No newline at end of filediff --git a/admin/app/views/spree/admin/shared/_head.html.erb b/admin/app/views/spree/admin/shared/_head.html.erbindex cd33bf3470..eaf7544928 100644--- a/admin/app/views/spree/admin/shared/_head.html.erb+++ b/admin/app/views/spree/admin/shared/_head.html.erb@@ -36,7 +36,10 @@<%= stylesheet_link_tag 'spree/admin/actiontext', media: :all, data: { turbo_track: "reload" } %><%= action_cable_meta_tag %>-<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@latest/tabler-icons.min.css">+<link+ rel="stylesheet"+ href="https://cdn.jsdelivr.net/npm/@tabler/[email protected]/dist/tabler-icons.min.css"+/><%= tag.meta name: "direct-upload-url", content: main_app.rails_direct_uploads_path %>