Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Better handling of Store/Taxon URLs in Admin Panel

Damian Legawiec01c4ef73eee0
diff --git a/backend/app/controllers/spree/admin/taxons_controller.rb b/backend/app/controllers/spree/admin/taxons_controller.rb
index 7c92f47351..4085d6973c 100644
--- a/backend/app/controllers/spree/admin/taxons_controller.rb
+++ b/backend/app/controllers/spree/admin/taxons_controller.rb
@@ -76,6 +76,8 @@ module Spree
def set_permalink_part
@permalink_part = @taxon.permalink.split('/').last
+ @parent_permalink = @taxon.permalink.split('/')[0...-1].join('/')
+ @parent_permalink += '/' unless @parent_permalink.blank?
end
def taxon_params
@@ -105,9 +107,7 @@ module Spree
def set_permalink_params
if params.key? 'permalink_part'
- parent_permalink = @taxon.permalink.split('/')[0...-1].join('/')
- parent_permalink += '/' unless parent_permalink.blank?
- params[:taxon][:permalink] = parent_permalink + params[:permalink_part]
+ params[:taxon][:permalink] = @parent_permalink + params[:permalink_part]
end
end
diff --git a/backend/app/views/spree/admin/stores/index.html.erb b/backend/app/views/spree/admin/stores/index.html.erb
index e84a3966ed..e4ddc7b579 100644
--- a/backend/app/views/spree/admin/stores/index.html.erb
+++ b/backend/app/views/spree/admin/stores/index.html.erb
@@ -20,7 +20,7 @@
<% @stores.each do |store| %>
<tr>
<td><%= store.unique_name %></td>
- <td><%= link_to store.url, 'https://' + store.url, target: :blank %></td>
+ <td><%= link_to store.url, store.formatted_url, target: :blank %></td>
<td><%= store.default_currency %></td>
<td><%= active_badge(store.default) %></td>
<td class="actions actions-2 text-right" data-hook="admin_stores_index_row_actions">
@@ -39,7 +39,7 @@
<% end %>
</tbody>
</table>
-</div>
+</div>
<% else %>
<div class="alert alert-info no-objects-found">
<%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::StoreCredit)) %>
diff --git a/backend/app/views/spree/admin/taxons/_form.html.erb b/backend/app/views/spree/admin/taxons/_form.html.erb
index 3c35d687c7..acb51f21ab 100644
--- a/backend/app/views/spree/admin/taxons/_form.html.erb
+++ b/backend/app/views/spree/admin/taxons/_form.html.erb
@@ -9,7 +9,9 @@
<%= label_tag :permalink_part, raw(Spree.t(:permalink) + required_span_tag) %>
<div class="input-group mb-3">
<div class="input-group-prepend">
- <span class="input-group-text" id="basic-addon3">https://<%= current_store.url %>/t/</span>
+ <span class="input-group-text" id="basic-addon3">
+ <%= [current_store.formatted_url, 't', @parent_permalink].join('/') %>
+ </span>
</div>
<%= text_field_tag :permalink_part, @permalink_part, class: 'form-control', required: true %>
</div>
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index a1287a3261..6f265a3080 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -51,6 +51,16 @@ module Spree
"#{name} (#{code})"
end
+ def formatted_url
+ return if url.blank?
+
+ if url.match(/http:\/\/|https:\/\//)
+ url
+ else
+ "https://#{url}"
+ end
+ end
+
def countries_available_for_checkout
checkout_zone_or_default.try(:country_list) || Spree::Country.all
end