spree_admin 5.1.5 → 5.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a44b861bdad4ce0d03b3225344461ced14b8dea71fec7a839beca7d19bac3c9
4
- data.tar.gz: 7efaca5c31054109ea94d9f867ba0ce820db0fded92e1cc7ddfa5a52763ba645
3
+ metadata.gz: ced4e88139c2415b6773c33a5a61745fd66c3785038bd2bedbf393e2123eaed6
4
+ data.tar.gz: 9e3017a0cb8ded68fe31d44f0031fae27ae11eee6a85e299467434086a449f47
5
5
  SHA512:
6
- metadata.gz: 5022e147047a7c8e1bdb0484420a4d7f9a461763974b0d1a4b517e676201fdc801bba89a65bb1b244688bccf2d0e404f04e1cbef517a0366c10b7dde5d417561
7
- data.tar.gz: 8291066c622ef1d32385470823dd9b343e58cda7534e3547d3c26ad32c815d922a21225c700f1c23f920a6b2bfd2c7c5a42bda4f5e1c57a0b74eab2467dfdaa0
6
+ metadata.gz: 031ac7b75b3e3ae2d1772d1a85f09f6ad0de3fedb198199e49799868cb8d037b44a6c0267448eba5dbc920b944680ccff9f685fb3afe8b4307dae2b5ca3849aa
7
+ data.tar.gz: 2836282801798b9f0a493002735342e31f387af928158566bf8c7773776ebf36de0a579bb5898ce86873fa257752b7dc9df0043991fead981ac7a3bee142b0e5
@@ -6,7 +6,7 @@ module Spree
6
6
  layout 'turbo_rails/frame'
7
7
 
8
8
  def create
9
- @variant = Spree::Variant.accessible_by(current_ability, :manage).find(params[:line_item][:variant_id])
9
+ @variant = variant_scope.find(params.dig(:line_item, :variant_id))
10
10
 
11
11
  @order.transaction do
12
12
  line_item_result = create_service.call(order: @order, line_item_attributes: permitted_resource_params)
@@ -120,6 +120,10 @@ module Spree
120
120
  def permitted_resource_params
121
121
  params.require(:line_item).permit(permitted_line_item_attributes)
122
122
  end
123
+
124
+ def variant_scope
125
+ Spree::Variant.accessible_by(current_ability, :manage)
126
+ end
123
127
  end
124
128
  end
125
129
  end
@@ -173,7 +173,7 @@ module Spree
173
173
  joins(option_type: :product_option_types).
174
174
  includes(option_type: :option_values).
175
175
  merge(@product.product_option_types).
176
- reorder("#{Spree::ProductOptionType.table_name}.position").
176
+ reorder("#{Spree::ProductOptionType.table_name}.position", "#{Spree::Variant.table_name}.position").
177
177
  uniq.group_by(&:option_type).each_with_index do |option, index|
178
178
  option_type, option_values = option
179
179
 
@@ -145,7 +145,7 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
145
145
  # call authorize! a third time (called twice already in Admin::BaseController)
146
146
  # this time we pass the actual instance so fine-grained abilities can control
147
147
  # access to individual records, not just entire models.
148
- authorize! action, @object
148
+ authorize! action, @object if @object.present?
149
149
 
150
150
  instance_variable_set("@#{resource.object_name}", @object)
151
151
  else
@@ -52,6 +52,10 @@ module Spree
52
52
  spree.edit_admin_taxonomy_taxon_path(@taxon.taxonomy_id, @taxon.id)
53
53
  end
54
54
 
55
+ def update_turbo_stream_enabled?
56
+ true
57
+ end
58
+
55
59
  def destroy_turbo_stream_enabled?
56
60
  true && !params[:force_redirect].to_b
57
61
  end
@@ -4,7 +4,7 @@ module Spree
4
4
  include Spree::ImagesHelper
5
5
 
6
6
  def available_stores
7
- @available_stores ||= Spree::Store.accessible_by(current_ability).includes(:logo_attachment, :favicon_image_attachment, :default_custom_domain)
7
+ @available_stores ||= Spree::Store.accessible_by(current_ability, :manage).includes(:logo_attachment, :favicon_image_attachment, :default_custom_domain)
8
8
  end
9
9
 
10
10
  DEFAULT_ICON_SIZE = 40
@@ -128,25 +128,29 @@ export default class extends CheckboxSelectAll {
128
128
 
129
129
  const nestingLevel = internalName.split('/').length
130
130
  if (nestingLevel === 1) {
131
- const firstOptionKey = Object.keys(this.optionsValue)[0]
132
- const newOptionValues = this.optionsValue[firstOptionKey].values.filter((value) => value.text !== internalName)
133
- if (newOptionValues.length === 0) {
134
- const newOptionsValue = this.optionsValue
135
- delete newOptionsValue[firstOptionKey]
136
- this.optionsValue = newOptionsValue
137
- this.optionsContainerTarget.querySelector(`#option-${firstOptionKey}`).remove()
138
- } else {
139
- this.optionsValue = {
140
- ...this.optionsValue,
141
- [firstOptionKey]: {
142
- ...this.optionsValue[firstOptionKey],
143
- values: newOptionValues
131
+ const sortedOptions = Object.entries(this.optionsValue).sort((a, b) => a[1].position - b[1].position)
132
+ const firstOptionKey = sortedOptions[0]?.[0]
133
+
134
+ if (firstOptionKey !== undefined) {
135
+ const newOptionValues = this.optionsValue[firstOptionKey].values.filter((value) => value.text !== internalName)
136
+ if (newOptionValues.length === 0) {
137
+ const newOptionsValue = this.optionsValue
138
+ delete newOptionsValue[firstOptionKey]
139
+ this.optionsValue = newOptionsValue
140
+ this.removeOption(firstOptionKey)
141
+ } else {
142
+ this.optionsValue = {
143
+ ...this.optionsValue,
144
+ [firstOptionKey]: {
145
+ ...this.optionsValue[firstOptionKey],
146
+ values: newOptionValues
147
+ }
144
148
  }
145
- }
146
149
 
147
- this.optionsContainerTarget.querySelector(`#option-${firstOptionKey} [data-name="${internalName}"]`).remove()
150
+ this.optionsContainerTarget.querySelector(`#option-${firstOptionKey} [data-name="${internalName}"]`).remove()
151
+ }
152
+ checkbox.checked = false
148
153
  }
149
- checkbox.checked = false
150
154
  }
151
155
 
152
156
  delete newStockValue[internalName]
@@ -463,25 +467,42 @@ export default class extends CheckboxSelectAll {
463
467
  this.variantsTableTarget.classList.remove('d-none')
464
468
 
465
469
  const nestingLevel = Math.min(keys.length, 2)
466
- let idx = 0
470
+
471
+ // This is the index for the product variant attributes
472
+ // We only want to count nested options if we have more than one option type
473
+ let idx
474
+ if (nestingLevel > 1) {
475
+ idx = this.variantsContainerTarget.querySelectorAll('.nested').length
476
+ } else {
477
+ idx = this.variantsContainerTarget.querySelectorAll('[data-variants-form-target="variant"]').length
478
+ }
467
479
 
468
480
  for (let i = 0; i < nestingLevel; i++) {
469
481
  this.variantsValue.forEach((variant) => {
470
482
  const { name, internalName } = this.calculateVariantName(variant, keys, i)
471
483
  if (currentVariants.has(internalName) || this.ignoredVariants.has(internalName)) {
472
- idx++
473
484
  return
474
485
  }
475
486
  currentVariants.add(internalName)
476
487
 
477
488
  const existingVariant = this.variantsContainerTarget.querySelector(`[data-variant-name="${internalName}"]`)
478
489
  if (existingVariant) {
479
- if (i === 0 && nestingLevel > 1) {
480
- existingVariant.querySelectorAll("input[type='hidden']").forEach((input) => input.remove())
481
-
482
- this.prepareParentVariant(existingVariant, internalName)
490
+ if (i === 0) {
491
+ if (nestingLevel > 1) {
492
+ existingVariant.querySelectorAll("input[type='hidden']").forEach((input) => input.remove())
493
+
494
+ this.prepareParentVariant(existingVariant, internalName)
495
+ } else if (nestingLevel === 1) {
496
+ // We need to generate hidden inputs when we only have a single option left
497
+ // And there are no inputs already
498
+ if (existingVariant.querySelectorAll("input[type='hidden']").length === 0) {
499
+ const inputs = this.createInputsForVariant(keys, variant, idx)
500
+ inputs.forEach((input) => existingVariant.appendChild(input))
501
+ idx++
502
+ }
503
+ }
483
504
  }
484
- idx++
505
+
485
506
  return
486
507
  }
487
508
 
@@ -537,10 +558,10 @@ export default class extends CheckboxSelectAll {
537
558
  }
538
559
 
539
560
  this.preparePriceInputs(variantTarget, internalName, idx)
540
-
541
561
  this.prepareStockInputs(variantTarget, internalName, idx)
562
+
563
+ idx++
542
564
  }
543
- idx++
544
565
 
545
566
  variantNameContainer.textContent = name
546
567
  if (previousVariant) {
@@ -570,7 +591,9 @@ export default class extends CheckboxSelectAll {
570
591
  }
571
592
 
572
593
  refreshParentInputs() {
573
- const firstOption = Object.values(this.optionsValue)[0]
594
+ const sortedOptions = Object.entries(this.optionsValue).sort((a, b) => a[1].position - b[1].position)
595
+ const firstOption = sortedOptions[0]?.[1]
596
+
574
597
  if (firstOption) {
575
598
  firstOption.values.forEach((option) => {
576
599
  this.currenciesValue.forEach((currency) => {
@@ -899,12 +922,25 @@ export default class extends CheckboxSelectAll {
899
922
  let { optionId } = event.params
900
923
  optionId = String(optionId)
901
924
 
902
- const option = this.optionsContainerTarget.querySelector(`#option-${optionId}`)
903
- option.remove()
904
- this.optionsValue = { ...this.optionsValue, [optionId]: null }
925
+ this.removeOption(optionId)
926
+
927
+ const newOptionsValue = {}
928
+ Object.entries(this.optionsValue).filter((option) => option[0] !== optionId).forEach((option) => {
929
+ newOptionsValue[option[0]] = option[1]
930
+ })
931
+
932
+ this.optionsValue = newOptionsValue
905
933
  this.refreshParentInputs()
906
934
  }
907
935
 
936
+ removeOption(optionId) {
937
+ const option = this.optionsContainerTarget.querySelector(`#option-${optionId}`)
938
+ if (option) option.remove()
939
+
940
+ const optionTypeInput = this.optionsContainerTarget.querySelector(`#product_option_type_ids_${optionId}`)
941
+ if (optionTypeInput) optionTypeInput.remove()
942
+ }
943
+
908
944
  optionFormTemplate(optionName, optionValues, id, availableOptions) {
909
945
  const template = this.optionFormTemplateTarget.content.cloneNode(true)
910
946
 
@@ -1045,14 +1081,24 @@ export default class extends CheckboxSelectAll {
1045
1081
 
1046
1082
  priceForVariant(variantName, currency) {
1047
1083
  const existingPrice = this.pricesValue[variantName]?.[currency.toLowerCase()]
1084
+
1048
1085
  if (existingPrice) {
1049
1086
  return {
1050
1087
  ...existingPrice,
1051
1088
  amount: existingPrice.amount ? parseFloat(existingPrice.amount) : existingPrice.amount
1052
1089
  }
1053
- }
1090
+ } else {
1091
+ const parentName = variantName.split('/')[0]
1092
+ const parentPrices = Object.entries(this.pricesValue)
1093
+ .filter(([internalName, prices]) => internalName.startsWith(parentName) && prices[currency.toLowerCase()] !== undefined)
1094
+ .map(([_key, prices]) => parseFloat(prices[currency.toLowerCase()].amount))
1095
+ .sort((priceAmountA, priceAmountB) => priceAmountA - priceAmountB)
1054
1096
 
1055
- return { amount: null, id: null }
1097
+ return {
1098
+ amount: parentPrices[0] ?? null,
1099
+ id: null
1100
+ }
1101
+ }
1056
1102
  }
1057
1103
 
1058
1104
  updatePriceForVariant(variantName, newPrice, currency) {
@@ -1,6 +1,7 @@
1
1
  <% content_for :page_title do %>
2
2
  <% if controller_name == 'orders' %>
3
- <%= page_header_back_button spree.admin_orders_path, @order %>
3
+ <% back_url = @order.present? && !@order.completed? ? spree.admin_checkouts_path : spree.admin_orders_path %>
4
+ <%= page_header_back_button back_url, @order %>
4
5
  <% else %>
5
6
  <%= page_header_back_button spree.edit_admin_order_path(@order) %>
6
7
  <% end %>
@@ -8,7 +8,7 @@
8
8
  </button>
9
9
  <div class="dropdown-menu" style="min-width: 300px">
10
10
  <% @theme.pages.standard.order(name: :asc).find_all(&:customizable?).each do |page| %>
11
- <%= active_link_to spree.edit_admin_theme_path(@theme, theme_preview_id: @theme_preview.id, page_id: page.id), class: 'dropdown-item', active: @page == page do %>
11
+ <%= active_link_to spree.edit_admin_theme_path(@theme, theme_preview_id: @theme_preview.id, page_id: page.id), class: 'dropdown-item', active: @page == page, data: { turbo_prefetch: false } do %>
12
12
  <%= icon page.icon_name, class: 'mr-2' %>
13
13
  <%= page.display_name %>
14
14
  <% end %>
@@ -31,6 +31,6 @@
31
31
  <% add_url = spree.admin_page_section_block_links_path(parent.section, parent) %>
32
32
  <% end %>
33
33
 
34
- <%= link_to_with_icon 'plus', 'Add link', add_url, class: 'btn btn-primary w-100', data: { turbo_method: :post } if add_url && can?(:create, Spree::PageLink.new(parent: parent)) %>
34
+ <%= link_to_with_icon 'plus', Spree.t(:add_link), add_url, class: 'btn btn-primary w-100', data: { turbo_method: :post } if add_url && can?(:create, Spree::PageLink.new(parent: parent)) %>
35
35
  <% end %>
36
36
  </div>
@@ -27,7 +27,6 @@
27
27
  <div data-variants-form-target="optionsContainer" class="options-creator__options_container">
28
28
  <% @product.product_option_types.includes(:option_type).reorder('spree_product_option_types.position').each do |product_option_type| %>
29
29
  <% option_type = product_option_type.option_type %>
30
- <%= hidden_field_tag "product[option_type_ids][]", option_type.id %>
31
30
  <div class="options-creator__option" data-variants-form-target="option" id="option-<%= option_type.id %>">
32
31
  <% if can?(:manage_option_types, @product) %>
33
32
  <button class="draggable" type="button">
@@ -161,7 +160,7 @@
161
160
  </div>
162
161
  </div>
163
162
  <%= render 'spree/admin/products/form/variants/variant_template', default_stock_location: default_stock_location_for_product(@product) %>
164
- <div class="variants-table__body" data-variants-form-target="variantsContainer">
163
+ <div class="variants-table__body" data-variants-form-target="variantsContainer" data-test-id="product-variants-table">
165
164
  </div>
166
165
  <div class="variants-table__footer">
167
166
  <%= Spree.t('admin.variants_form.total_inventory_html', stock_location: current_store.default_stock_location.name, count: raw("<span data-variants-form-target='stockItemsCount'>#{@product.total_on_hand}</span>") )%>
@@ -37,6 +37,8 @@
37
37
  <%= tinymce_assets %>
38
38
  <link rel="stylesheet" type="text/css" href="https://unpkg.com/trix@2.1.12/dist/trix.css">
39
39
 
40
+ <script async src="https://ga.jspm.io/npm:es-module-shims@1.8.2/dist/es-module-shims.js" data-turbo-track="reload"></script>
41
+
40
42
  <%= javascript_importmap_tags 'application-spree-admin', importmap: Rails.application.config.spree_admin.importmap %>
41
43
 
42
44
  <%= yield :head %>
@@ -66,13 +66,15 @@
66
66
  </ul>
67
67
  <% else %>
68
68
  <ul class="nav flex-column">
69
- <% unless current_store.setup_completed? %>
70
- <%= nav_item(nil, spree.admin_getting_started_path, icon: 'map') do %>
71
- <%= icon 'map' %>
72
- <%= Spree.t('admin.getting_started') %>
73
- <span class="badge ml-auto badge-info">
74
- <%= current_store.setup_tasks_done %><span class="opacity-50">/<%= current_store.setup_tasks_total %></span>
75
- </span>
69
+ <% if can?(:manage, current_store) %>
70
+ <% unless current_store.setup_completed? %>
71
+ <%= nav_item(nil, spree.admin_getting_started_path, icon: 'map') do %>
72
+ <%= icon 'map' %>
73
+ <%= Spree.t('admin.getting_started') %>
74
+ <span class="badge ml-auto badge-info">
75
+ <%= current_store.setup_tasks_done %><span class="opacity-50">/<%= current_store.setup_tasks_total %></span>
76
+ </span>
77
+ <% end %>
76
78
  <% end %>
77
79
  <% end %>
78
80
 
@@ -80,7 +80,7 @@
80
80
  <div class="card-body border-bottom">
81
81
  <div class="d-flex align-items-center">
82
82
  <%= f.label :sort_order, class: 'text-nowrap mr-2 mb-0' %>
83
- <%= f.select :sort_order, taxon_sort_options_for_select, {}, { class: 'custom-select custom-select-sm w-auto', data: { action: 'change->auto-submit#submit' } } %>
83
+ <%= f.select :sort_order, taxon_sort_options_for_select, {}, { class: 'custom-select custom-select-sm w-auto', data: { action: 'change->auto-submit#submit' } } %>n sort order dropdown in admin (#13030))
84
84
  </div>
85
85
  </div>
86
86
 
@@ -0,0 +1,7 @@
1
+ <%= turbo_render_alerts %>
2
+
3
+ <%= turbo_stream.replace :classifications do %>
4
+ <%= turbo_frame_tag :classifications, src: spree.admin_taxon_classifications_path(@taxon.id) do %>
5
+ <%= render 'spree/admin/shared/spinner' %>
6
+ <% end %>
7
+ <% end %>
data/config/importmap.rb CHANGED
@@ -23,7 +23,6 @@ pin '@stimulus-components/rails-nested-form', to: '@stimulus-components--rails-n
23
23
  pin 'stimulus-notification', preload: ['application-spree-admin'] # @2.2.0
24
24
  pin 'stimulus-password-visibility', preload: ['application-spree-admin'] # @2.1.1
25
25
  pin 'stimulus-sortable', preload: ['application-spree-admin'] # @4.1.1
26
- pin 'stimulus-textarea-autogrow', preload: ['application-spree-admin'] # @4.1.0
27
26
  pin 'hotkeys-js', preload: ['application-spree-admin'] # @3.13.9
28
27
  pin 'stimulus-use', preload: ['application-spree-admin'] # @0.51.3
29
28
  pin 'stimulus-checkbox-select-all', preload: ['application-spree-admin'] # @5.3.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.5
4
+ version: 5.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vendo Connect Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-06 00:00:00.000000000 Z
11
+ date: 2025-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.1.5
19
+ version: 5.1.6
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.1.5
26
+ version: 5.1.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: spree_api
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 5.1.5
33
+ version: 5.1.6
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 5.1.5
40
+ version: 5.1.6
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: active_link_to
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -1029,6 +1029,7 @@ files:
1029
1029
  - app/views/spree/admin/taxons/rule_forms/_available_on.html.erb
1030
1030
  - app/views/spree/admin/taxons/rule_forms/_sale.html.erb
1031
1031
  - app/views/spree/admin/taxons/rule_forms/_tag.html.erb
1032
+ - app/views/spree/admin/taxons/update.turbo_stream.erb
1032
1033
  - app/views/spree/admin/themes/_theme.html.erb
1033
1034
  - app/views/spree/admin/themes/_theme_preview_image.html.erb
1034
1035
  - app/views/spree/admin/themes/edit.html.erb
@@ -1132,7 +1133,6 @@ files:
1132
1133
  - vendor/javascript/stimulus-password-visibility.js
1133
1134
  - vendor/javascript/stimulus-reveal-controller.js
1134
1135
  - vendor/javascript/stimulus-sortable.js
1135
- - vendor/javascript/stimulus-textarea-autogrow.js
1136
1136
  - vendor/javascript/stimulus-use.js
1137
1137
  - vendor/javascript/tom-select--dist--esm--tom-select.complete.js.js
1138
1138
  - vendor/javascript/trix@2.1.12.js
@@ -1141,9 +1141,9 @@ licenses:
1141
1141
  - AGPL-3.0-or-later
1142
1142
  metadata:
1143
1143
  bug_tracker_uri: https://github.com/spree/spree/issues
1144
- changelog_uri: https://github.com/spree/spree/releases/tag/v5.1.5
1144
+ changelog_uri: https://github.com/spree/spree/releases/tag/v5.1.6
1145
1145
  documentation_uri: https://docs.spreecommerce.org/
1146
- source_code_uri: https://github.com/spree/spree/tree/v5.1.5
1146
+ source_code_uri: https://github.com/spree/spree/tree/v5.1.6
1147
1147
  post_install_message:
1148
1148
  rdoc_options: []
1149
1149
  require_paths:
@@ -1,4 +0,0 @@
1
- // stimulus-textarea-autogrow@4.1.0 downloaded from https://ga.jspm.io/npm:stimulus-textarea-autogrow@4.1.0/dist/stimulus-textarea-autogrow.mjs
2
-
3
- import{Controller as e}from"@hotwired/stimulus";function r(e,t){let i;return(...s)=>{const o=this;clearTimeout(i),i=setTimeout((()=>e.apply(o,s)),t)}}class l extends e{initialize(){this.autogrow=this.autogrow.bind(this)}connect(){this.element.style.overflow="hidden";const e=this.resizeDebounceDelayValue;this.onResize=e>0?r(this.autogrow,e):this.autogrow,this.autogrow(),this.element.addEventListener("input",this.autogrow),window.addEventListener("resize",this.onResize)}disconnect(){window.removeEventListener("resize",this.onResize)}autogrow(){this.element.style.height="auto",this.element.style.height=`${this.element.scrollHeight}px`}}l.values={resizeDebounceDelay:{type:Number,default:100}};export{l as default};
4
-