From d86ef2c397cf30aae1f54792bbca107b453247fe Mon Sep 17 00:00:00 2001 From: Aleksandar Petrushev Date: Mon, 10 Jan 2022 17:05:29 +0100 Subject: [PATCH] Show Special Instructions on Orders page for Admin --- .../spree/admin/orders_controller.rb | 4 +- .../orders/special_instructions.html.erb | 16 ++++++++ .../spree/admin/shared/_order_tabs.html.erb | 9 +++++ config/locales/en.yml | 2 + config/routes.rb | 1 + .../admin/orders/special_instructions_spec.rb | 40 +++++++++++++++++++ 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 app/views/spree/admin/orders/special_instructions.html.erb create mode 100644 spec/features/admin/orders/special_instructions_spec.rb diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb index 682aedddcb..2570f0897c 100644 --- a/app/controllers/spree/admin/orders_controller.rb +++ b/app/controllers/spree/admin/orders_controller.rb @@ -6,7 +6,7 @@ class OrdersController < Spree::Admin::BaseController before_action :initialize_order_events before_action :load_order, only: %i[ edit update cancel resume approve resend open_adjustments - close_adjustments cart channel set_channel + close_adjustments cart channel set_channel special_instructions ] respond_to :html @@ -153,6 +153,8 @@ def set_channel redirect_to channel_admin_order_url(@order) end + def special_instructions; end + private def scope diff --git a/app/views/spree/admin/orders/special_instructions.html.erb b/app/views/spree/admin/orders/special_instructions.html.erb new file mode 100644 index 0000000000..d2b79bca86 --- /dev/null +++ b/app/views/spree/admin/orders/special_instructions.html.erb @@ -0,0 +1,16 @@ +<%= render 'spree/admin/shared/order_tabs', current: :special_instructions %> + +<% if @order.special_instructions.present? %> +
+
+ <%= spree_icon 'info-circle-fill.svg' %> <%= Spree.t('admin.order.special_instructions_provided') %> +
+
+

<%= @order.special_instructions %>

+
+
+<% else %> +

<%= Spree.t('admin.order.no_special_instructions') %>

+<% end %> + +<%= render 'spree/admin/shared/order_summary' %> diff --git a/app/views/spree/admin/shared/_order_tabs.html.erb b/app/views/spree/admin/shared/_order_tabs.html.erb index 1931b4aa57..afd6ccac8f 100644 --- a/app/views/spree/admin/shared/_order_tabs.html.erb +++ b/app/views/spree/admin/shared/_order_tabs.html.erb @@ -89,5 +89,14 @@ class: "#{'active' if current == :state_changes} nav-link" %> <% end %> + + <% if @order.special_instructions.present? %> +
  • + <%= link_to_with_icon 'info-circle.svg', + Spree.t(:special_instructions), + spree.special_instructions_admin_order_url(@order), + class: "#{'active' if current == :special_instructions} nav-link" %> +
  • + <% end %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index e7ca3a9699..301680f906 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -148,6 +148,8 @@ en: cancel: cancel resume: resume resend: Resend + special_instructions_provided: 'Special instructions provided by the customer' + no_special_instructions: 'There are no special instructions provided by the customer.' orders: cart: Cart oauth_applications: diff --git a/config/routes.rb b/config/routes.rb index 88d232232e..d3acbfe623 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -86,6 +86,7 @@ get :channel put :set_channel get :reset_digitals + get :special_instructions end resources :state_changes, only: [:index] diff --git a/spec/features/admin/orders/special_instructions_spec.rb b/spec/features/admin/orders/special_instructions_spec.rb new file mode 100644 index 0000000000..043bfce595 --- /dev/null +++ b/spec/features/admin/orders/special_instructions_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'Order - Special Instructions', type: :feature do + stub_authorization! + + let(:store) { Spree::Store.default } + let!(:order) { create(:order, store: store, special_instructions: 'Some special instructions') } + + context 'when there are special instructions' do + before do + visit spree.edit_admin_order_path(order) + end + + it 'shows the Special Instructions tab' do + expect(page).to have_link(Spree.t(:special_instructions)) + end + + it 'shows the special instructions' do + click_link 'Special Instructions' + expect(page).to have_content(order.special_instructions) + end + end + + context 'when there are no special instructions' do + before do + order.update(special_instructions: nil) + end + + it 'does not show the special instructions tab' do + visit spree.edit_admin_order_path(order) + expect(page).not_to have_link(Spree.t(:special_instructions)) + end + + it 'shows a notification that there are no special instructions' do + visit spree.special_instructions_admin_order_path(order) + expect(page).to have_content(Spree.t('admin.order.no_special_instructions')) + end + end +end +