solidus_backend 2.7.4 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_backend might be problematic. Click here for more details.

Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -8
  3. data/app/assets/images/favicon.ico +0 -0
  4. data/app/assets/javascripts/spree/backend.js +0 -2
  5. data/app/assets/javascripts/spree/backend/adjustments.js +1 -1
  6. data/app/assets/javascripts/spree/backend/components/tooltips.js +21 -17
  7. data/app/assets/javascripts/spree/backend/option_type_autocomplete.js +1 -1
  8. data/app/assets/javascripts/spree/backend/product_picker.js +1 -1
  9. data/app/assets/javascripts/spree/backend/shipments.js +6 -1
  10. data/app/assets/javascripts/spree/backend/stock_management.js +9 -0
  11. data/app/assets/javascripts/spree/backend/store_credits.js +18 -2
  12. data/app/assets/javascripts/spree/backend/taxons.js +1 -1
  13. data/app/assets/javascripts/spree/backend/templates/stock_items/stock_location_stock_item.hbs +24 -25
  14. data/app/assets/javascripts/spree/backend/user_picker.js +1 -1
  15. data/app/assets/javascripts/spree/backend/variant_autocomplete.js +1 -1
  16. data/app/assets/javascripts/spree/backend/views/order/customer_select.js +1 -1
  17. data/app/assets/javascripts/spree/backend/views/order/summary.js +2 -2
  18. data/app/assets/javascripts/spree/backend/views/stock/add_stock_item.js +15 -4
  19. data/app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js +30 -10
  20. data/app/assets/stylesheets/spree/backend/globals/_functions.scss +1 -2
  21. data/app/assets/stylesheets/spree/backend/sections/_orders.scss +8 -0
  22. data/app/assets/stylesheets/spree/backend/sections/_stock_management.scss +77 -2
  23. data/app/assets/stylesheets/spree/backend/spree_admin.scss +0 -1
  24. data/app/controllers/spree/admin/cancellations_controller.rb +2 -2
  25. data/app/controllers/spree/admin/locale_controller.rb +1 -1
  26. data/app/controllers/spree/admin/orders/customer_details_controller.rb +8 -1
  27. data/app/controllers/spree/admin/orders_controller.rb +1 -11
  28. data/app/controllers/spree/admin/products_controller.rb +10 -6
  29. data/app/controllers/spree/admin/promotion_codes_controller.rb +19 -1
  30. data/app/controllers/spree/admin/promotions_controller.rb +1 -1
  31. data/app/controllers/spree/admin/reimbursements_controller.rb +7 -2
  32. data/app/controllers/spree/admin/resource_controller.rb +1 -0
  33. data/app/controllers/spree/admin/store_credit_reasons_controller.rb +8 -0
  34. data/app/controllers/spree/admin/store_credits_controller.rb +11 -11
  35. data/app/helpers/spree/admin/navigation_helper.rb +1 -1
  36. data/app/models/spree/backend_configuration.rb +38 -21
  37. data/app/views/spree/admin/cancellations/index.html.erb +3 -1
  38. data/app/views/spree/admin/images/_image_row.html.erb +1 -1
  39. data/app/views/spree/admin/images/edit.html.erb +3 -3
  40. data/app/views/spree/admin/images/index.html.erb +2 -2
  41. data/app/views/spree/admin/log_entries/index.html.erb +2 -2
  42. data/app/views/spree/admin/orders/_carton_manifest.html.erb +3 -1
  43. data/app/views/spree/admin/orders/_shipment_manifest.html.erb +3 -1
  44. data/app/views/spree/admin/orders/confirm/_line_items.html.erb +3 -2
  45. data/app/views/spree/admin/orders/confirm/_shipment_manifest.html.erb +3 -1
  46. data/app/views/spree/admin/orders/index.html.erb +1 -1
  47. data/app/views/spree/admin/products/_form.html.erb +7 -7
  48. data/app/views/spree/admin/products/edit.html.erb +5 -0
  49. data/app/views/spree/admin/products/index.html.erb +3 -1
  50. data/app/views/spree/admin/promotion_categories/index.html.erb +1 -1
  51. data/app/views/spree/admin/promotion_code_batches/index.html.erb +1 -1
  52. data/app/views/spree/admin/promotion_codes/index.html.erb +5 -1
  53. data/app/views/spree/admin/promotion_codes/new.html.erb +31 -0
  54. data/app/views/spree/admin/promotions/_actions.html.erb +1 -1
  55. data/app/views/spree/admin/promotions/_activations_edit.html.erb +1 -1
  56. data/app/views/spree/admin/promotions/_form.html.erb +4 -3
  57. data/app/views/spree/admin/promotions/_rules.html.erb +1 -1
  58. data/app/views/spree/admin/promotions/edit.html.erb +3 -1
  59. data/app/views/spree/admin/refunds/new.html.erb +1 -1
  60. data/app/views/spree/admin/shared/_address_form.html.erb +10 -3
  61. data/app/views/spree/admin/shared/_edit_resource_links.html.erb +1 -1
  62. data/app/views/spree/admin/shared/_head.html.erb +1 -0
  63. data/app/views/spree/admin/shared/_image.html.erb +2 -2
  64. data/app/views/spree/admin/shared/_product_sub_menu.html.erb +1 -1
  65. data/app/views/spree/admin/shared/_settings_checkout_tabs.html.erb +4 -0
  66. data/app/views/spree/admin/shared/_settings_sub_menu.html.erb +3 -3
  67. data/app/views/spree/admin/shared/_tabs.html.erb +3 -2
  68. data/app/views/spree/admin/shared/_variant_search.html.erb +1 -1
  69. data/app/views/spree/admin/stock_items/_stock_management.html.erb +56 -38
  70. data/app/views/spree/admin/stock_locations/_form.html.erb +133 -121
  71. data/app/views/spree/admin/stock_locations/edit.html.erb +4 -2
  72. data/app/views/spree/admin/store_credit_reasons/edit.html.erb +15 -0
  73. data/app/views/spree/admin/store_credit_reasons/index.html.erb +56 -0
  74. data/app/views/spree/admin/store_credit_reasons/new.html.erb +18 -0
  75. data/app/views/spree/admin/store_credit_reasons/shared/_form.html.erb +15 -0
  76. data/app/views/spree/admin/store_credits/_store_credit_reason_field.html.erb +7 -0
  77. data/app/views/spree/admin/store_credits/edit_amount.html.erb +1 -1
  78. data/app/views/spree/admin/store_credits/edit_validity.html.erb +1 -1
  79. data/app/views/spree/admin/store_credits/show.html.erb +2 -2
  80. data/app/views/spree/admin/users/items.html.erb +3 -1
  81. data/app/views/spree/admin/users/orders.html.erb +1 -1
  82. data/config/routes.rb +2 -8
  83. data/lib/spree/backend.rb +1 -1
  84. data/solidus_backend.gemspec +3 -4
  85. data/spec/controllers/spree/admin/base_controller_spec.rb +1 -1
  86. data/spec/controllers/spree/admin/cancellations_controller_spec.rb +7 -3
  87. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +50 -2
  88. data/spec/controllers/spree/admin/orders_controller_spec.rb +23 -11
  89. data/spec/controllers/spree/admin/payments_controller_spec.rb +1 -1
  90. data/spec/controllers/spree/admin/products_controller_spec.rb +72 -0
  91. data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +13 -1
  92. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +11 -0
  93. data/spec/controllers/spree/admin/resource_controller_spec.rb +22 -0
  94. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +1 -1
  95. data/spec/controllers/spree/admin/store_credits_controller_spec.rb +7 -7
  96. data/spec/features/admin/configuration/payment_methods_spec.rb +2 -2
  97. data/spec/features/admin/configuration/shipping_methods_spec.rb +2 -2
  98. data/spec/features/admin/homepage_spec.rb +1 -6
  99. data/spec/features/admin/orders/listing_spec.rb +1 -1
  100. data/spec/features/admin/orders/new_order_spec.rb +117 -0
  101. data/spec/features/admin/orders/new_refund_spec.rb +35 -0
  102. data/spec/features/admin/orders/order_details_spec.rb +2 -2
  103. data/spec/features/admin/orders/payments_spec.rb +2 -2
  104. data/spec/features/admin/orders/return_payment_state_spec.rb +3 -0
  105. data/spec/features/admin/orders/shipments_spec.rb +28 -0
  106. data/spec/features/admin/products/products_spec.rb +1 -1
  107. data/spec/features/admin/products/stock_management_spec.rb +10 -13
  108. data/spec/features/admin/promotion_adjustments_spec.rb +12 -12
  109. data/spec/features/admin/promotions/option_value_rule_spec.rb +2 -2
  110. data/spec/features/admin/promotions/product_rule_spec.rb +1 -1
  111. data/spec/features/admin/promotions/tiered_calculator_spec.rb +1 -1
  112. data/spec/features/admin/promotions/user_rule_spec.rb +2 -2
  113. data/spec/features/admin/reimbursements_spec.rb +1 -1
  114. data/spec/features/admin/store_credits_spec.rb +51 -2
  115. data/spec/features/admin/taxons_spec.rb +35 -0
  116. data/spec/features/admin/users_spec.rb +22 -11
  117. data/spec/helpers/admin/navigation_helper_spec.rb +4 -2
  118. data/spec/helpers/admin/store_credit_events_helper_spec.rb +2 -2
  119. data/spec/javascripts/spec_helper.js +2 -0
  120. data/spec/models/spree/backend_configuration/menu_item_spec.rb +17 -0
  121. data/spec/models/spree/backend_configuration_spec.rb +22 -0
  122. data/spec/spec_helper.rb +1 -0
  123. data/spec/support/feature/order_feature_helper.rb +1 -1
  124. data/spec/views/spree/admin/shared/navigation_footer_spec.rb +1 -1
  125. data/vendor/assets/javascripts/solidus_admin/select2_locales/select2_locale_en-US.js +10 -0
  126. metadata +26 -34
  127. data/app/controllers/spree/admin/reports_controller.rb +0 -82
  128. data/app/views/spree/admin/reports/index.html.erb +0 -19
  129. data/app/views/spree/admin/reports/sales_total.html.erb +0 -35
  130. data/app/views/spree/admin/shared/_report_order_criteria.html.erb +0 -19
  131. data/app/views/spree/admin/store_credits/_update_reason_field.html.erb +0 -7
  132. data/spec/controllers/spree/admin/reports_controller_spec.rb +0 -133
  133. data/spec/features/admin/reports_spec.rb +0 -63
@@ -1,5 +1,5 @@
1
1
  // Make color very close to white
2
- @function very-light($color, $adjust: 3){
2
+ @function very-light($color, $adjust: 3){
3
3
  @if type-of($adjust) == 'number' and $adjust > 0 {
4
4
  @for $i from 0 through 100 {
5
5
  @if lighten($color, $i) == white and ($i - $adjust) > $adjust {
@@ -10,7 +10,6 @@
10
10
  @else {
11
11
  @debug "Please correct $adjust value. It should be number and larger then 0. Currently it is '#{type-of($adjust)}' with value '#{$adjust}'"
12
12
  }
13
- @return $color;
14
13
  };
15
14
 
16
15
  // Quick fix for dynamic variables missing in SASS
@@ -49,6 +49,14 @@
49
49
  margin-bottom: 18px;
50
50
  }
51
51
 
52
+ [data-hook="complete-order-button"] {
53
+ margin-bottom: 15px;
54
+ }
55
+
56
+ label[for="order_bill_address_attributes_firstname"] {
57
+ margin-top: 45px;
58
+ }
59
+
52
60
  #risk_analysis legend {
53
61
  background-color: #c00;
54
62
  color: #FFF;
@@ -1,11 +1,33 @@
1
- #listing_product_stock {
1
+ .stock-table {
2
2
 
3
3
  tbody + tbody {
4
4
  border-top-width: 1px;
5
5
  }
6
6
 
7
+ .stock-item-edit-row {
8
+ &.changed {
9
+ .submit, .cancel {
10
+ display: inline-block;
11
+ }
12
+ }
13
+
14
+ td {
15
+ vertical-align: middle;
16
+
17
+ &:not(.actions) {
18
+ padding: 0.5rem 0.75rem;
19
+ }
20
+ }
21
+ }
22
+
23
+ .actions {
24
+ .submit, .cancel {
25
+ display: none;
26
+ }
27
+ }
28
+
7
29
  td {
8
- input.error {
30
+ .error {
9
31
  border-color: theme-color("danger");
10
32
  }
11
33
 
@@ -14,4 +36,57 @@
14
36
  border: 1px solid theme-color("danger");
15
37
  }
16
38
  }
39
+
40
+ .variant-stock-items {
41
+ border: 0 none;
42
+ }
43
+
44
+ table {
45
+ td {
46
+ padding: 4px 0;
47
+ border: none;
48
+ }
49
+
50
+ &.stock-variant-field-table {
51
+ margin-bottom: 0;
52
+
53
+ td {
54
+ text-align: left;
55
+
56
+ &:first-child {
57
+ font-weight: bold;
58
+ text-align: left;
59
+ padding-right: 0.5rem;
60
+ width: 15%;
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ > tbody {
67
+ .variant-image {
68
+ width: 31%;
69
+ padding: 0 2%;
70
+ img { width: 100%; }
71
+ }
72
+ .variant-details {
73
+ width: 65%;
74
+ padding: 0px 5px;
75
+ }
76
+ .variant-image,
77
+ .variant-details {
78
+ float: left;
79
+ }
80
+ .variant-container {
81
+ overflow: hidden;
82
+ }
83
+ }
84
+ }
85
+
86
+ .stock-location-items-cell {
87
+ padding: 0;
88
+ }
89
+
90
+ .stock-location-items-table {
91
+ margin-bottom: 0;
17
92
  }
@@ -29,7 +29,6 @@
29
29
  @import 'spree/backend/components/table-filter';
30
30
  @import 'spree/backend/components/navigation';
31
31
  @import 'spree/backend/components/sidebar';
32
- @import 'spree/backend/components/stock_table';
33
32
  @import 'spree/backend/components/editable_table';
34
33
  @import 'spree/backend/components/pills';
35
34
  @import 'spree/backend/components/tabs';
@@ -20,7 +20,7 @@ module Spree
20
20
  flash[:error] = t('spree.no_inventory_selected')
21
21
  redirect_to admin_order_cancellations_path(@order)
22
22
  else
23
- @order.cancellations.short_ship(inventory_units, whodunnit: whodunnit)
23
+ @order.cancellations.short_ship(inventory_units, created_by: created_by)
24
24
 
25
25
  flash[:success] = t('spree.inventory_canceled')
26
26
  redirect_to edit_admin_order_url(@order)
@@ -29,7 +29,7 @@ module Spree
29
29
 
30
30
  private
31
31
 
32
- def whodunnit
32
+ def created_by
33
33
  try_spree_current_user.try(:email)
34
34
  end
35
35
 
@@ -8,7 +8,7 @@ module Spree
8
8
 
9
9
  if locale && I18n.available_locales.include?(locale.to_sym)
10
10
  I18n.locale = locale
11
- session[:locale] = locale
11
+ session[set_user_language_locale_key] = locale
12
12
 
13
13
  respond_to do |format|
14
14
  format.json { render json: { locale: locale, location: spree.admin_url } }
@@ -13,7 +13,8 @@ module Spree
13
13
  end
14
14
 
15
15
  def edit
16
- country_id = Spree::Country.default.id
16
+ country_id = default_country_id
17
+
17
18
  @order.build_bill_address(country_id: country_id) if @order.bill_address.nil?
18
19
  @order.build_ship_address(country_id: country_id) if @order.ship_address.nil?
19
20
 
@@ -43,6 +44,12 @@ module Spree
43
44
 
44
45
  private
45
46
 
47
+ def default_country_id
48
+ country_id = Spree::Country.default.id
49
+
50
+ country_id if Spree::Country.available.pluck(:id).include?(country_id)
51
+ end
52
+
46
53
  def order_params
47
54
  params.require(:order).permit(
48
55
  :email,
@@ -51,17 +51,7 @@ module Spree
51
51
  end
52
52
 
53
53
  @search = Spree::Order.accessible_by(current_ability, :index).ransack(params[:q])
54
-
55
- # lazy loading other models here (via includes) may result in an invalid query
56
- # e.g. SELECT DISTINCT DISTINCT "spree_orders".id, "spree_orders"."created_at" AS alias_0 FROM "spree_orders"
57
- # see https://github.com/spree/spree/pull/3919
58
- @orders = if query_present
59
- @search.result(distinct: true)
60
- else
61
- @search.result
62
- end
63
-
64
- @orders = @orders.
54
+ @orders = @search.result.includes([:user]).
65
55
  page(params[:page]).
66
56
  per(params[:per_page] || Spree::Config[:orders_per_page])
67
57
 
@@ -8,6 +8,7 @@ module Spree
8
8
  before_action :load_data, except: [:index]
9
9
  update.before :update_before
10
10
  helper_method :clone_object_url
11
+ before_action :split_params, only: [:create, :update]
11
12
 
12
13
  def show
13
14
  redirect_to action: :edit
@@ -19,12 +20,6 @@ module Spree
19
20
  end
20
21
 
21
22
  def update
22
- if params[:product][:taxon_ids].present?
23
- params[:product][:taxon_ids] = params[:product][:taxon_ids].split(',')
24
- end
25
- if params[:product][:option_type_ids].present?
26
- params[:product][:option_type_ids] = params[:product][:option_type_ids].split(',')
27
- end
28
23
  if updating_variant_property_rules?
29
24
  params[:product][:variant_property_rules_attributes].each do |_index, param_attrs|
30
25
  param_attrs[:option_value_ids] = param_attrs[:option_value_ids].split(',')
@@ -73,6 +68,15 @@ module Spree
73
68
 
74
69
  private
75
70
 
71
+ def split_params
72
+ if params[:product][:taxon_ids].present?
73
+ params[:product][:taxon_ids] = params[:product][:taxon_ids].split(',')
74
+ end
75
+ if params[:product][:option_type_ids].present?
76
+ params[:product][:option_type_ids] = params[:product][:option_type_ids].split(',')
77
+ end
78
+ end
79
+
76
80
  def find_resource
77
81
  Spree::Product.with_deleted.friendly.find(params[:id])
78
82
  end
@@ -7,7 +7,7 @@ module Spree
7
7
  class PromotionCodesController < Spree::Admin::ResourceController
8
8
  def index
9
9
  @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id])
10
- @promotion_codes = @promotion.promotion_codes
10
+ @promotion_codes = @promotion.promotion_codes.order(:value)
11
11
 
12
12
  respond_to do |format|
13
13
  format.html do
@@ -20,6 +20,24 @@ module Spree
20
20
  end
21
21
  end
22
22
  end
23
+
24
+ def new
25
+ @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id])
26
+ @promotion_code = @promotion.promotion_codes.build
27
+ end
28
+
29
+ def create
30
+ @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id])
31
+ @promotion_code = @promotion.promotion_codes.build(value: params[:promotion_code][:value])
32
+
33
+ if @promotion_code.save
34
+ flash[:success] = flash_message_for(@promotion_code, :successfully_created)
35
+ redirect_to admin_promotion_promotion_codes_url(@promotion)
36
+ else
37
+ flash.now[:error] = @promotion_code.errors.full_messages.to_sentence
38
+ render_after_create_error
39
+ end
40
+ end
23
41
  end
24
42
  end
25
43
  end
@@ -24,7 +24,7 @@ module Spree
24
24
  flash[:success] = t('spree.promotion_successfully_created')
25
25
  redirect_to location_after_save
26
26
  else
27
- flash[:error] = @promotion.errors.full_messages.join(", ")
27
+ flash[:error] = @promotion.errors.full_messages.to_sentence
28
28
  render action: 'new'
29
29
  end
30
30
  end
@@ -9,16 +9,21 @@ module Spree
9
9
 
10
10
  before_action :load_stock_locations, only: :edit
11
11
  before_action :load_simulated_refunds, only: :edit
12
+ create.after :recalculate_order
12
13
 
13
14
  rescue_from Spree::Core::GatewayError, with: :spree_core_gateway_error
14
15
 
15
16
  def perform
16
- @reimbursement.perform!
17
+ @reimbursement.perform!(created_by: try_spree_current_user)
17
18
  redirect_to location_after_save
18
19
  end
19
20
 
20
21
  private
21
22
 
23
+ def recalculate_order
24
+ @reimbursement.order.recalculate
25
+ end
26
+
22
27
  def build_resource
23
28
  if params[:build_from_customer_return_id].present?
24
29
  customer_return = Spree::CustomerReturn.find(params[:build_from_customer_return_id])
@@ -57,7 +62,7 @@ module Spree
57
62
  end
58
63
 
59
64
  def load_simulated_refunds
60
- @reimbursement_objects = @reimbursement.simulate
65
+ @reimbursement_objects = @reimbursement.simulate(created_by: try_spree_current_user)
61
66
  end
62
67
 
63
68
  def spree_core_gateway_error(error)
@@ -108,6 +108,7 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
108
108
  invoke_callbacks(:destroy, :fails)
109
109
  respond_with(@object) do |format|
110
110
  format.html { redirect_to location_after_destroy }
111
+ format.js { render status: :unprocessable_entity, plain: @object.errors.full_messages.join(', ') }
111
112
  end
112
113
  end
113
114
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Admin
5
+ class StoreCreditReasonsController < ResourceController
6
+ end
7
+ end
8
+ end
@@ -5,8 +5,8 @@ module Spree
5
5
  class StoreCreditsController < ResourceController
6
6
  belongs_to 'spree/user', model_class: Spree.user_class
7
7
  before_action :load_categories, only: [:new]
8
- before_action :load_update_reasons, only: [:edit_amount, :edit_validity]
9
- before_action :ensure_update_reason, only: [:update_amount, :invalidate]
8
+ before_action :load_reasons, only: [:edit_amount, :edit_validity]
9
+ before_action :ensure_store_credit_reason, only: [:update_amount, :invalidate]
10
10
 
11
11
  helper Spree::Admin::StoreCreditEventsHelper
12
12
 
@@ -50,7 +50,7 @@ module Spree
50
50
  def update_amount
51
51
  @store_credit = @user.store_credits.find(params[:id])
52
52
  amount = params.require(:store_credit).require(:amount)
53
- if @store_credit.update_amount(amount, @update_reason, try_spree_current_user)
53
+ if @store_credit.update_amount(amount, @store_credit_reason, try_spree_current_user)
54
54
  flash[:success] = flash_message_for(@store_credit, :successfully_updated)
55
55
  redirect_to admin_user_store_credit_path(@user, @store_credit)
56
56
  else
@@ -60,7 +60,7 @@ module Spree
60
60
 
61
61
  def invalidate
62
62
  @store_credit = @user.store_credits.find(params[:id])
63
- if @store_credit.invalidate(@update_reason, try_spree_current_user)
63
+ if @store_credit.invalidate(@store_credit_reason, try_spree_current_user)
64
64
  redirect_to admin_user_store_credit_path(@user, @store_credit)
65
65
  else
66
66
  render_edit_page
@@ -78,18 +78,18 @@ module Spree
78
78
  @collection = super.reverse_order
79
79
  end
80
80
 
81
- def load_update_reasons
82
- @update_reasons = Spree::StoreCreditUpdateReason.all.order(:name)
81
+ def load_reasons
82
+ @store_credit_reasons = Spree::StoreCreditReason.active.order(:name)
83
83
  end
84
84
 
85
85
  def load_categories
86
86
  @credit_categories = Spree::StoreCreditCategory.all.order(:name)
87
87
  end
88
88
 
89
- def ensure_update_reason
90
- @update_reason = Spree::StoreCreditUpdateReason.find_by(id: params[:update_reason_id])
91
- unless @update_reason
92
- @store_credit.errors.add(:base, t('spree.admin.store_credits.errors.update_reason_required'))
89
+ def ensure_store_credit_reason
90
+ @store_credit_reason = Spree::StoreCreditReason.find_by(id: params[:store_credit_reason_id])
91
+ unless @store_credit_reason
92
+ @store_credit.errors.add(:base, t('spree.admin.store_credits.errors.store_credit_reason_required'))
93
93
  render_edit_page
94
94
  end
95
95
  end
@@ -103,7 +103,7 @@ module Spree
103
103
  translation_key = 'invalidate'
104
104
  end
105
105
 
106
- load_update_reasons
106
+ load_reasons
107
107
  flash[:error] = "#{t("spree.admin.store_credits.unable_to_#{translation_key}")}: #{@store_credit.errors.full_messages.join(', ')}"
108
108
  render(template) && return
109
109
  end
@@ -39,7 +39,7 @@ module Spree
39
39
  end
40
40
  end
41
41
 
42
- # Make an admin tab that coveres one or more resources supplied by symbols
42
+ # Make an admin tab that covers one or more resources supplied by symbols
43
43
  # Option hash may follow. Valid options are
44
44
  # * :label to override link text, otherwise based on the first resource name (translated)
45
45
  # * :route to override automatically determining the default route
@@ -10,19 +10,21 @@ module Spree
10
10
  PRODUCT_TABS ||= [:products, :option_types, :properties,
11
11
  :variants, :product_properties, :taxonomies,
12
12
  :taxons]
13
- REPORT_TABS ||= [:reports]
14
13
  CONFIGURATION_TABS ||= [:stores, :tax_categories,
15
14
  :tax_rates, :zones,
16
15
  :payment_methods, :shipping_methods,
17
16
  :shipping_categories, :stock_locations,
18
- :refund_reasons, :reimbursement_types, :return_authorization_reasons]
17
+ :refund_reasons, :reimbursement_types,
18
+ :return_reasons, :adjustment_reasons]
19
19
  PROMOTION_TABS ||= [:promotions, :promotion_categories]
20
20
  STOCK_TABS ||= [:stock_items]
21
21
  USER_TABS ||= [:users, :store_credits]
22
22
 
23
23
  # An item which should be drawn in the admin menu
24
24
  class MenuItem
25
- attr_reader :icon, :label, :partial, :condition, :sections, :url
25
+ attr_reader :icon, :label, :partial, :condition, :sections, :url, :match_path
26
+
27
+ attr_accessor :position
26
28
 
27
29
  # @param sections [Array<Symbol>] The sections which are contained within
28
30
  # this admin menu section.
@@ -35,13 +37,19 @@ module Spree
35
37
  # @param partial [String] A partial to draw within this menu item for use
36
38
  # in declaring a submenu
37
39
  # @param url [String] A url where this link should send the user to
40
+ # @param position [Integer] The position in which the menu item should render
41
+ # nil will cause the item to render last
42
+ # @param match_path [String, Regexp] (nil) If the {url} to determine the active tab is ambigous
43
+ # you can pass a String or Regexp to identify this menu item
38
44
  def initialize(
39
45
  sections,
40
46
  icon,
41
47
  condition: nil,
42
48
  label: nil,
43
49
  partial: nil,
44
- url: nil
50
+ url: nil,
51
+ position: nil,
52
+ match_path: nil
45
53
  )
46
54
 
47
55
  @condition = condition || -> { true }
@@ -50,6 +58,8 @@ module Spree
50
58
  @label = label || sections.first
51
59
  @partial = partial
52
60
  @url = url
61
+ @position = position
62
+ @match_path = match_path
53
63
  end
54
64
  end
55
65
 
@@ -65,6 +75,11 @@ module Spree
65
75
  #
66
76
  # @!attribute menu_items
67
77
  # @return [Array<Spree::BackendConfiguration::MenuItem>]
78
+ #
79
+ # Positioning can be determined by setting the position attribute to
80
+ # an Integer or nil. Menu Items will be rendered with smaller lower values
81
+ # first and higher values last. A position value of nil will cause the menu
82
+ # item to be rendered at the end of the list.
68
83
  attr_writer :menu_items
69
84
 
70
85
  # Return the menu items which should be drawn in the menu
@@ -77,45 +92,47 @@ module Spree
77
92
  ORDER_TABS,
78
93
  'shopping-cart',
79
94
  condition: -> { can?(:admin, Spree::Order) },
95
+ position: 0
80
96
  ),
81
97
  MenuItem.new(
82
98
  PRODUCT_TABS,
83
99
  'th-large',
84
100
  condition: -> { can?(:admin, Spree::Product) },
85
- partial: 'spree/admin/shared/product_sub_menu'
86
- ),
87
- MenuItem.new(
88
- REPORT_TABS,
89
- 'file',
90
- condition: -> { can?(:admin, :reports) },
91
- ),
92
- MenuItem.new(
93
- CONFIGURATION_TABS,
94
- 'wrench',
95
- condition: -> { can?(:admin, Spree::Store) },
96
- label: :settings,
97
- partial: 'spree/admin/shared/settings_sub_menu',
98
- url: :admin_stores_path
101
+ partial: 'spree/admin/shared/product_sub_menu',
102
+ position: 1
99
103
  ),
100
104
  MenuItem.new(
101
105
  PROMOTION_TABS,
102
106
  'bullhorn',
103
107
  partial: 'spree/admin/shared/promotion_sub_menu',
104
108
  condition: -> { can?(:admin, Spree::Promotion) },
105
- url: :admin_promotions_path
109
+ url: :admin_promotions_path,
110
+ position: 2
106
111
  ),
107
112
  MenuItem.new(
108
113
  STOCK_TABS,
109
114
  'cubes',
110
115
  condition: -> { can?(:admin, Spree::StockItem) },
111
116
  label: :stock,
112
- url: :admin_stock_items_path
117
+ url: :admin_stock_items_path,
118
+ match_path: '/stock_items',
119
+ position: 3
113
120
  ),
114
121
  MenuItem.new(
115
122
  USER_TABS,
116
123
  'user',
117
124
  condition: -> { Spree.user_class && can?(:admin, Spree.user_class) },
118
- url: :admin_users_path
125
+ url: :admin_users_path,
126
+ position: 4
127
+ ),
128
+ MenuItem.new(
129
+ CONFIGURATION_TABS,
130
+ 'wrench',
131
+ condition: -> { can?(:admin, Spree::Store) },
132
+ label: :settings,
133
+ partial: 'spree/admin/shared/settings_sub_menu',
134
+ url: :admin_stores_path,
135
+ position: 5
119
136
  )
120
137
  ]
121
138
  end