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
added new admin base files (#12177)
Damian Legawiec5f5b301b7a8c
diff --git a/admin/app/controllers/spree/admin/base_controller.rb b/admin/app/controllers/spree/admin/base_controller.rbnew file mode 100644index 0000000000..441a452985--- /dev/null+++ b/admin/app/controllers/spree/admin/base_controller.rb@@ -0,0 +1,77 @@+module Spree+ module Admin+ class BaseController < ApplicationController+ include Spree::Core::ControllerHelpers::Auth+ include Spree::Core::ControllerHelpers::Store+ include Spree::Core::ControllerHelpers::StrongParameters+ include Spree::Core::ControllerHelpers::Locale+ include Spree::Core::ControllerHelpers::Currency++ respond_to :html++ layout 'spree/admin'++ helper 'spree/base'+ helper 'spree/admin/navigation'+ helper 'spree/locale'+ helper 'spree/currency'++ before_action :authorize_admin++ protected++ def action+ params[:action].to_sym+ end++ def authorize_admin+ record = if respond_to?(:model_class, true) && model_class+ model_class+ else+ controller_name.to_sym+ end+ authorize! :admin, record+ authorize! action, record+ end++ def redirect_unauthorized_access+ if try_spree_current_user+ flash[:error] = Spree.t(:authorization_failure)+ redirect_to spree.admin_forbidden_path+ else+ store_location+ if defined?(spree.admin_login_path)+ redirect_to spree.admin_login_path+ elsif respond_to?(:spree_login_path)+ redirect_to spree_login_path+ elsif spree.respond_to?(:root_path)+ redirect_to spree.root_path+ else+ redirect_to main_app.respond_to?(:root_path) ? main_app.root_path : '/'+ end+ end+ end++ def flash_message_for(object, event_sym)+ if object.is_a?(ActiveRecord::Relation)+ resource_desc = object.model.model_name.human.pluralize+ else+ resource_desc = object.class.model_name.human+ if (object.persisted? || object.destroyed?) && object.respond_to?(:name) && object.name.present? && !object.is_a?(Spree::Order)+ resource_desc += " \"#{object.name}\""+ end+ end++ Spree.t(event_sym, resource: resource_desc)+ end++ def config_locale+ I18n.locale+ end++ def current_timezone+ @current_timezone ||= current_store.timezone+ end+ end+ end+enddiff --git a/admin/app/controllers/spree/admin/resource_controller.rb b/admin/app/controllers/spree/admin/resource_controller.rbnew file mode 100644index 0000000000..5fe3ff946c--- /dev/null+++ b/admin/app/controllers/spree/admin/resource_controller.rb@@ -0,0 +1,325 @@+class Spree::Admin::ResourceController < Spree::Admin::BaseController+ include Spree::Admin::Callbacks++ helper_method :new_object_url, :edit_object_url, :object_url, :collection_url+ before_action :load_resource+ before_action :set_currency, :set_current_store, only: [:new, :create]++ rescue_from ActiveRecord::RecordNotFound, with: :resource_not_found++ respond_to :html++ def new+ invoke_callbacks(:new_action, :before)+ end++ def edit+ invoke_callbacks(:edit_action, :before)+ end++ def update+ invoke_callbacks(:update, :before)+ if @object.update(permitted_resource_params)+ set_current_store+ %w[asset image square_image].each do |attachment_type|+ remove_param = "remove_#{attachment_type}"+ if params[remove_param] == '1'+ object = attachment_type == 'asset' ? @page_section : @object+ attachment = object.public_send(attachment_type)+ if attachment.attached?+ attachment.detach+ attachment.purge_later+ end+ end+ end++ invoke_callbacks(:update, :after)+ respond_with(@object) do |format|+ if update_turbo_stream_enabled?+ format.turbo_stream do+ flash.now[:success] = flash_message_for(@object, :successfully_updated)+ end+ end+ format.html do+ flash[:success] = flash_message_for(@object, :successfully_updated)+ redirect_to location_after_save, status: :see_other+ end+ end+ else+ invoke_callbacks(:update, :fails)+ respond_with(@object) do |format|+ if update_turbo_stream_enabled?+ format.turbo_stream do+ flash.now[:error] = @object.errors.full_messages.join(', ')+ end+ end+ format.html { render action: :edit, status: :unprocessable_entity }+ end+ end+ end++ def create+ invoke_callbacks(:create, :before)+ @object.attributes = permitted_resource_params+ if @object.save+ invoke_callbacks(:create, :after)+ respond_with(@object) do |format|+ if create_turbo_stream_enabled?+ format.turbo_stream do+ flash.now[:success] = flash_message_for(@object, :successfully_created)+ end+ end+ format.html do+ flash[:success] = flash_message_for(@object, :successfully_created)+ redirect_to location_after_save, status: :see_other+ end+ end+ else+ invoke_callbacks(:create, :fails)+ respond_with(@object) do |format|+ if create_turbo_stream_enabled?+ format.turbo_stream do+ flash.now[:error] = @object.errors.full_messages.join(', ')+ end+ end+ format.html { render action: :new, status: :unprocessable_entity }+ end+ end+ end++ def destroy+ invoke_callbacks(:destroy, :before)+ if @object.destroy+ invoke_callbacks(:destroy, :after)++ respond_to do |format|+ if destroy_turbo_stream_enabled?+ format.turbo_stream do+ flash.now[:success] = flash_message_for(@object, :successfully_removed)+ end+ end+ format.html do+ flash[:success] = flash_message_for(@object, :successfully_removed)+ redirect_to location_after_destroy, status: :see_other+ end+ end+ else+ invoke_callbacks(:destroy, :fails)++ respond_to do |format|+ if destroy_turbo_stream_enabled?+ format.turbo_stream do+ flash.now[:error] = @object.errors.full_messages.to_sentence+ end+ end+ format.html do+ flash[:error] = @object.errors.full_messages.to_sentence+ end+ end+ end+ end++ protected++ class << self+ attr_accessor :parent_data++ def belongs_to(model_name, options = {})+ @parent_data ||= {}+ @parent_data[:model_name] = model_name+ @parent_data[:model_class] = model_name.to_s.classify.constantize+ @parent_data[:find_by] = options[:find_by] || :id+ end+ end++ def model_class+ @model_class ||= resource.model_class+ end++ def resource_not_found+ flash[:error] = flash_message_for(model_class.new, :not_found)+ redirect_to collection_url, status: :see_other+ end++ def resource+ return @resource if @resource++ parent_model_name = parent_data[:model_name] if parent_data+ @resource = Spree::Admin::Resource.new controller_path, controller_name, parent_model_name, object_name+ end++ def load_resource+ if member_action?+ @object ||= load_resource_instance++ # call authorize! a third time (called twice already in Admin::BaseController)+ # this time we pass the actual instance so fine-grained abilities can control+ # access to individual records, not just entire models.+ authorize! action, @object++ instance_variable_set("@#{resource.object_name}", @object)+ else+ @collection ||= collection++ # note: we don't call authorize here as the collection method should use+ # CanCan's accessible_by method to restrict the actual records returned++ instance_variable_set("@#{controller_name}", @collection)+ end+ end++ def load_resource_instance+ if new_actions.include?(action)+ build_resource+ elsif params[:id]+ find_resource+ end+ end++ def parent_data+ self.class.parent_data+ end++ def parent+ if parent_data.present?+ base_scope = parent_data[:model_class].try(:for_store, current_store) || parent_data[:model_class]++ @parent ||= base_scope.+ # Don't use `find_by_attribute_name` to workaround globalize/globalize#423 bug+ send(:find_by, parent_data[:find_by].to_s => params["#{resource.model_name}_id"])+ instance_variable_set("@#{resource.model_name}", @parent)++ raise ActiveRecord::RecordNotFound if @parent.nil?++ @parent+ end+ end++ def find_resource+ if parent_data.present?+ parent.send(controller_name).find(params[:id])+ else+ base_scope = model_class.try(:for_store, current_store) || model_class+ if model_class.try(:friendly)+ base_scope.friendly.find(params[:id])+ else+ base_scope.find(params[:id])+ end+ end+ end++ def build_resource+ if parent_data.present?+ parent.send(controller_name).build+ else+ model_class.new+ end+ end++ def collection+ return parent.send(controller_name) if parent_data.present?++ base_scope = model_class.try(:for_store, current_store) || model_class+ if defined?(current_vendor) && current_vendor.present? && model_class.respond_to?(:with_vendor)+ base_scope = base_scope.with_vendor(current_vendor)+ end++ if model_class.respond_to?(:accessible_by) &&+ !current_ability.has_block?(params[:action], model_class)+ base_scope.accessible_by(current_ability, action)+ else+ base_scope+ end+ end++ def location_after_destroy+ collection_url+ end++ def location_after_save+ edit_object_url(@object)+ end++ def set_current_store+ return if @object.nil?++ ensure_current_store(@object)+ end++ def set_currency+ return if @object.nil?++ @object.currency = current_currency if model_class.method_defined?(:currency=)+ @object.cost_currency = current_currency if model_class.method_defined?(:cost_currency=)+ end++ # URL helpers++ def new_object_url(options = {})+ if parent_data.present?+ spree.new_polymorphic_url([:admin, parent, model_class], options)+ else+ spree.new_polymorphic_url([:admin, model_class], options)+ end+ end++ def edit_object_url(object, options = {})+ if parent_data.present?+ spree.send "edit_admin_#{resource.model_name}_#{resource.object_name}_url",+ parent, object, options+ else+ spree.send "edit_admin_#{resource.object_name}_url", object, options+ end+ end++ def object_url(object = nil, options = {})+ target = object || @object+ if parent_data.present?+ spree.send "admin_#{resource.model_name}_#{resource.object_name}_url", parent, target, options+ else+ spree.send "admin_#{resource.object_name}_url", target, options+ end+ end++ def collection_url(options = {})+ if parent_data.present?+ spree.polymorphic_url([:admin, parent, model_class], options)+ else+ spree.polymorphic_url([:admin, model_class], options)+ end+ end++ # This method should be overridden when object_name does not match the controller name+ def object_name; end++ # Allow all attributes to be updatable.+ #+ # Other controllers can, should, override it to set custom logic+ def permitted_resource_params+ params[resource.object_name].present? ? params.require(resource.object_name).permit! : ActionController::Parameters.new+ end++ def collection_actions+ [:index]+ end++ def member_action?+ !collection_actions.include? action+ end++ def new_actions+ [:new, :create]+ end++ def create_turbo_stream_enabled?+ false+ end++ def update_turbo_stream_enabled?+ false+ end++ def destroy_turbo_stream_enabled?+ false+ end+enddiff --git a/admin/app/helpers/spree/admin/base_helper.rb b/admin/app/helpers/spree/admin/base_helper.rbnew file mode 100644index 0000000000..e02879b5dc--- /dev/null+++ b/admin/app/helpers/spree/admin/base_helper.rb@@ -0,0 +1,212 @@+module Spree+ module Admin+ module BaseHelper+ def available_countries_iso+ @available_countries_iso ||= current_store.countries_available_for_checkout.pluck(:iso)+ end++ def display_on_options+ Spree::DisplayOn::DISPLAY.map do |display_on|+ [Spree.t("display_on_options.#{display_on}"), display_on]+ end+ end++ def error_message_on(object, method, _options = {})+ object = convert_to_model(object)+ obj = object.respond_to?(:errors) ? object : instance_variable_get("@#{object}")++ if obj && obj.errors[method].present?+ errors = safe_join(obj.errors[method], '<br />'.html_safe)+ content_tag(:span, errors, class: 'formError')+ else+ ''+ end+ end++ def icon(icon_name, options = {})+ if icon_name.ends_with?('.svg')+ icon_name = File.basename(icon_name, File.extname(icon_name))+ end++ # translations for legacy icon names+ icon_name = 'device-floppy' if icon_name == 'save'+ icon_name = 'pencil' if icon_name == 'edit'+ icon_name = 'trash' if icon_name == 'delete'+ icon_name = 'plus' if icon_name == 'add'+ icon_name = 'x' if icon_name == 'cancel'++ styles = options[:style]+ styles ||= ''+ styles += ";font-size: #{options[:height]}px !important;line-height:#{options[:height]}px !important" if options[:height]++ content_tag :i, nil, class: "ti ti-#{icon_name} #{options[:class]}", style: styles+ end++ def preference_field_tag(name, value, options)+ if options[:key] == :currency+ return select_tag(+ name,+ currency_options_for_select(+ value,+ current_store.supported_currencies.split(',')+ ),+ class: 'custom-select',+ disabled: current_store.supported_currencies.split(',').count == 1+ )+ end++ case options[:type]+ when :integer+ number_field_tag(name, value, preference_field_options(options))+ when :decimal+ number_field_tag(name, value, preference_field_options(options))+ when :boolean+ hidden_field_tag(name, 0, id: "#{name}_hidden") ++ check_box_tag(name, 1, value, preference_field_options(options))+ when :string+ text_field_tag(name, value, preference_field_options(options))+ when :password+ password_field_tag(name, value, preference_field_options(options))+ when :text+ text_area_tag(name, value, preference_field_options(options))+ else+ text_field_tag(name, value, preference_field_options(options))+ end+ end++ def preference_field_for(form, field, options)+ case options[:type]+ when :integer+ form.number_field(field, preference_field_options(options))+ when :decimal+ form.number_field(field, preference_field_options(options))+ when :boolean+ form.check_box(field, preference_field_options(options))+ when :string+ form.text_field(field, preference_field_options(options))+ when :password+ form.password_field(field, preference_field_options(options))+ when :text+ form.text_area(field, preference_field_options(options))+ else+ form.text_field(field, preference_field_options(options))+ end+ end++ def preference_field_options(options)+ field_options = case options[:type]+ when :integer+ {+ size: 10,+ class: 'input_integer form-control'+ }+ when :decimal+ {+ size: 10,+ class: 'input_decimal form-control',+ step: options[:step] || 0.01+ }+ when :boolean+ {+ class: 'custom-control custom-checkbox'+ }+ when :string+ {+ size: 10,+ class: 'input_string form-control'+ }+ when :password+ {+ size: 10,+ class: 'password_string form-control'+ }+ when :text+ {+ rows: 15,+ cols: 85,+ class: 'form-control'+ }+ else+ {+ size: 10,+ class: 'input_string form-control'+ }+ end++ field_options.merge!(readonly: options[:readonly],+ disabled: options[:disabled],+ size: options[:size])+ end++ def preference_fields(object, form)+ return unless object.respond_to?(:preferences)++ fields = object.preferences.keys.map do |key|+ if object.has_preference?(key)+ case key+ when :currency+ content_tag(:div, form.label("preferred_#{key}", Spree.t(key)) ++ form.currency_select("preferred_#{key}", current_store.supported_currencies.split(','), {}, { class: 'custom-select', disabled: current_store.supported_currencies.split(',').count == 1 }),+ class: 'form-group', id: [object.class.to_s.parameterize, 'preference', key].join('-'))+ else+ if object.preference_type(key).to_sym == :boolean+ content_tag(:div, class: 'custom-control custom-checkbox') do+ preference_field_for(form, "preferred_#{key}", type: object.preference_type(key)) ++ form.label(+ "preferred_#{key}",+ Spree.t(key),+ class: 'custom-control custom-checkbox',+ id: [object.class.to_s.parameterize, 'preference', key].join('-')+ )+ end+ else+ content_tag(:div, form.label("preferred_#{key}", Spree.t(key)) ++ preference_field_for(form, "preferred_#{key}", type: object.preference_type(key)),+ class: 'form-group', id: [object.class.to_s.parameterize, 'preference', key].join('-'))+ end+ end+ end+ end+ safe_join(fields)+ end++ def spree_dom_id(record)+ dom_id(record, 'spree')+ end++ I18N_PLURAL_MANY_COUNT = 2.1+ def plural_resource_name(resource_class)+ resource_class.model_name.human(count: I18N_PLURAL_MANY_COUNT)+ end++ def required_span_tag+ content_tag(:span, ' *', class: 'required font-weight-bold text-danger')+ end++ def external_page_preview_link(resource, options = {})+ resource_name = options[:name] || resource.class.name.demodulize++ url = if [Spree::Product, Spree::Post].include?(resource.class)+ spree_storefront_resource_url(resource, preview_id: resource.id)+ else+ spree_storefront_resource_url(resource)+ end++ link_to_with_icon(+ 'eye',+ Spree.t('admin.utilities.preview', name: resource_name),+ url,+ class: 'text-left dropdown-item', id: "adminPreview#{resource_name}", target: :blank, data: { turbo: false }+ )+ end++ def current_currency_money+ @current_currency_money ||= ::Money::Currency.find(current_currency)+ end++ def path_from_url(url)+ url.to_s.gsub('https://', '').gsub('http://', '')+ end+ end+ end+enddiff --git a/admin/app/helpers/spree/admin/navigation_helper.rb b/admin/app/helpers/spree/admin/navigation_helper.rbnew file mode 100644index 0000000000..ec55c51010--- /dev/null+++ b/admin/app/helpers/spree/admin/navigation_helper.rb@@ -0,0 +1,201 @@+module Spree+ module Admin+ module NavigationHelper+ # the per_page_dropdown is used on index pages like orders, products, promotions etc.+ # this method generates the select_tag+ def per_page_dropdown+ # there is a config setting for admin_products_per_page, only for the orders page+ if @products && per_page_default = ENV.fetch('ADMIN_PRODUCTS_PER_PAGE', 25)+ per_page_options = []+ 5.times do |amount|+ per_page_options << (amount + 1) * ENV.fetch('ADMIN_PRODUCTS_PER_PAGE', 25)+ end+ per_page_options << 250+ else+ per_page_default = ENV.fetch('ADMIN_PRODUCTS_PER_PAGE', 25)+ per_page_options = %w{25 50 75 100 125 250}+ end++ selected_option = (params[:per_page].try(:to_i) || per_page_default).to_s++ selected_option += icon('chevron-down', class: 'ml-1 mr-0 arrow')++ content_tag :div, id: 'per-page-dropdown' do+ button_tag(raw(selected_option), class: 'btn btn-light btn-sm', data: { toggle: 'dropdown', expanded: false }) ++ content_tag(:div, class: 'dropdown-menu') do+ per_page_options.map do |option|+ link_to option, per_page_dropdown_params(option), class: "dropdown-item #{'active' if option == selected_option}"+ end.join.html_safe+ end+ end+ end++ # helper method to create proper url to apply per page ing+ # fixes https://github.com/spree/spree/issues/6888+ def per_page_dropdown_params(per_page)+ args = params.permit!.to_h.clone+ args.delete(:page)+ args.delete(:per_page)+ args.merge!(per_page: per_page)+ args+ end++ def link_to_edit(resource, options = {})+ url = options[:url] || edit_object_url(resource)+ options[:data] ||= {}+ options[:data][:action] ||= 'edit'+ options[:class] ||= 'btn btn-light btn-sm'+ link_to_with_icon('pencil', Spree.t(:edit), url, options)+ end++ def link_to_edit_url(url, options = {})+ options[:data] ||= { action: 'edit' }+ options[:class] ||= 'btn btn-light btn-sm'+ link_to_with_icon('pencil', Spree.t(:edit), url, options)+ end++ def link_to_delete(resource, options = {})+ url = options[:url] || object_url(resource)+ name = options[:name] || Spree.t('actions.destroy')+ options[:class] ||= 'btn btn-danger btn-sm'+ options[:data] ||= { turbo_confirm: Spree.t(:are_you_sure), turbo_method: :delete }++ if options[:no_text]+ link_to_with_icon 'trash', name, url, options+ elsif options[:icon]+ link_to_with_icon options[:icon], name, url, options+ else+ link_to name, url, options+ end+ end++ def link_to_delete_url(url, options = {})+ options[:data] = { turbo_confirm: Spree.t(:are_you_sure), turbo_method: :delete }+ options[:class] = 'btn btn-danger btn-sm'+ link_to_with_icon('trash', Spree.t('actions.destroy'), url, options)+ end++ def link_to_with_icon(icon_name, text, url, options = {})+ options[:class] ||= (options[:class].to_s + " with-tip").strip+ options[:title] ||= text if options[:no_text]+ no_text = options[:no_text]+ label = options[:no_text] ? '' : content_tag(:span, text)+ options.delete(:no_text)++ if icon_name+ icon = icon(icon_name, class: "icon icon-#{icon_name} #{text.blank? || no_text ? 'mr-0' : ''}")+ text = "#{icon} #{label}"+ end+ link_to(text.html_safe, url, options)+ end++ def active_link_to_with_icon(icon_name, text, url, options = {})+ options[:class] = (options[:class].to_s + " with-tip").strip+ options[:title] = text if options[:no_text]+ no_text = options[:no_text]+ label = options[:no_text] ? '' : content_tag(:span, text)+ options.delete(:no_text)++ if icon_name+ icon = icon(icon_name, class: "icon icon-#{icon_name}")+ text = "#{icon} #{label}"+ end+ active_link_to(text.html_safe, url, options)+ end++ # Override: Add disable_with option to prevent multiple request on consecutive clicks+ def button(text, icon_name = nil, button_type = 'submit', options = {})+ if icon_name+ text = "#{icon(icon_name, class: "icon icon-#{icon_name}")} #{text}"+ end++ css_classes = options[:class] || 'btn-primary'++ button_tag(+ text.html_safe,+ options.merge(+ type: button_type,+ class: "btn #{css_classes}",+ 'data-turbo-submits-with' => content_tag(:span, '', class: 'spinner-border spinner-border-sm', role: 'status')+ )+ )+ end++ def button_link_to(text, url, html_options = {})+ if html_options[:method] &&+ !html_options[:method].to_s.casecmp('get').zero? &&+ !html_options[:remote]++ html_options[:class] = html_options[:class] ? "btn #{html_options[:class]}" : 'btn btn-primary'++ form_tag(url, method: html_options.delete(:method)) do+ button(text, html_options.delete(:icon), nil, html_options)+ end+ else+ html_options[:class] = html_options[:class] ? "btn #{html_options[:class]}" : 'btn btn-light'++ if html_options[:icon]+ icon = icon(html_options[:icon], class: "icon icon-#{html_options[:icon]}")+ text = "#{icon} #{text}"+ end++ link_to(text.html_safe, url, html_options.except(:icon))+ end+ end++ def turbo_link_to(text, url, **options)+ icon = options[:icon]++ text_components = []+ text_components << icon(icon) if icon.present?+ text_components << text++ link_text = text_components.compact.join++ options[:data] ||= {}+ options[:data][:turbo_method] = options[:method] || :get+ options[:data][:turbo_confirm] = Spree.t(:are_you_sure) if options[:confirm].present?++ html_options = options.except(:icon, :method, :confirm)++ link_to(link_text.html_safe, url, html_options)+ end++ def active_badge(condition, options = {})+ label = options[:label]+ label ||= condition ? Spree.t(:say_yes) : Spree.t(:say_no)+ label = icon('check') + label if condition++ css_class = condition ? 'badge-active' : 'badge-inactive'++ content_tag(:small, class: "badge #{css_class}") do+ label+ end+ end++ def page_header_back_button(default_url, object = nil, label = nil)+ url = default_url++ if object.present?+ session_key = "#{object.class.to_s.demodulize.pluralize.downcase}_return_to".to_sym+ url = session[session_key] if session[session_key].present?+ end++ link_to url, class: 'd-flex align-items-center' do+ content_tag(:span, inline_svg('icons/chevron-left.svg', height: '1rem'), class: 'btn hover-gray px-1 mr-2 d-flex align-items-center') ++ content_tag(:span, label, class: 'font-size-base text-black')+ end+ end++ def nav_pill_list_item(resource, url: nil, label: Spree.t(resource), active: nil, link_class: 'nav-link')+ url = spree.send("admin_#{resource.to_s.pluralize}_path") if url.nil?+ active = request.url.starts_with?(url) || request.fullpath.starts_with?(url) || controller_name == resource.to_s if active.nil?+ link_class = "#{link_class} active" if active++ content_tag :li, class: 'nav-item', role: 'presentation' do+ link_to label, url, role: 'tab', 'aria-controls': 'pills-general', class: link_class, 'aria-selected': active+ end+ end+ end+ end+enddiff --git a/admin/app/models/spree/admin/resource.rb b/admin/app/models/spree/admin/resource.rbnew file mode 100644index 0000000000..e31a0c528f--- /dev/null+++ b/admin/app/models/spree/admin/resource.rb@@ -0,0 +1,36 @@+module Spree+ module Admin+ class Resource+ def initialize(controller_path, controller_name, parent_model, object_name = nil)+ @controller_path = controller_path+ @controller_name = controller_name+ @parent_model = parent_model+ @object_name = object_name+ end++ def sub_namespace_parts+ @controller_path.split('/')[2..-2]+ end++ def model_class+ sub_namespace = sub_namespace_parts.map(&:capitalize).join('::')+ sub_namespace = "#{sub_namespace}::" unless sub_namespace.empty?+ "Spree::#{sub_namespace}#{@controller_name.classify}".constantize+ end++ def model_name+ sub_namespace = sub_namespace_parts.join('/')+ sub_namespace = "#{sub_namespace}/" unless sub_namespace.empty?+ @parent_model.gsub("spree/#{sub_namespace}", '')+ end++ def object_name+ return @object_name if @object_name++ sub_namespace = sub_namespace_parts.join('_')+ sub_namespace = "#{sub_namespace}_" unless sub_namespace.empty?+ "#{sub_namespace}#{@controller_name.singularize}"+ end+ end+ end+enddiff --git a/bin/sandbox.sh b/bin/sandbox.shindex 71581690bd..3ec9444c44 100755--- a/bin/sandbox.sh+++ b/bin/sandbox.sh@@ -76,7 +76,7 @@ bin/rails db:drop || truebin/rails db:createbin/rails g spree:install --auto-accept --user_class=Spree::User --sample=truebin/rails g spree:emails:install-# bin/rails g spree:admin:install+bin/rails g spree:admin:installbin/rails g spree:auth:installbin/rails g spree_gateway:installbin/rake acts_as_taggable_on_engine:install:migrationsdiff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rbindex c6ce9df84d..810f46f899 100644--- a/core/app/models/spree/store.rb+++ b/core/app/models/spree/store.rb@@ -26,6 +26,11 @@ module Sprees.integer :digital_asset_authorized_clicks, default: 5, null: false # number of times a customer can download a digital file.s.integer :digital_asset_authorized_days, default: 7, null: false # number of days after initial purchase the customer can download a file.s.integer :digital_asset_link_expire_time, default: 300, null: false # 5 minutes in seconds++ # store configuration+ s.string :timezone, default: -> { Time.zone.name }, null: false+ s.string :weight_unit, default: 'kg', null: false+ s.string :unit_system, default: 'metric', null: falseendattr_accessor :skip_validate_not_last