add available units to instance prefs page

This commit is contained in:
Andy Brett
2020-10-06 13:35:19 -07:00
parent a43737af8b
commit cb3ea133e9
4 changed files with 21 additions and 0 deletions

View File

@@ -10,6 +10,13 @@ module Spree
end
def update
available_units = []
params.each do |name, value|
if value == "1" && unit = name.match(/available_units_(.*)/)&.captures&.first
available_units << unit
end
end
Spree::Config[:available_units] = available_units.join(",")
params.each do |name, value|
next unless Spree::Config.has_preference? name

View File

@@ -144,5 +144,8 @@ module Spree
# Enable cache
preference :enable_products_cache?, :boolean,
default: (Rails.env.production? || Rails.env.staging?)
# Available units
preference :available_units, :string, default: "g,kg,T,mL,L,kL"
end
end

View File

@@ -87,6 +87,15 @@
.field
= preference_field_tag(:enable_localized_number?, Spree::Config[:enable_localized_number?], type: Spree::Config.preference_type(:enable_localized_number?))
= label_tag(:enable_localized_number?, t('admin.number_localization.enable_localized_number')) + tag(:br)
%fieldset.available_units.no-border-bottom
%legend{:align => "center"}= t('admin.available_units')
.field
- all_units = ["g", "oz", "lb", "kg", "T", "mL", "L", "kL"]
- selected_units = Spree::Config[:available_units].split(",")
- all_units.each do |unit|
- selected = selected_units.include?(unit)
= preference_field_tag("available_units_#{unit}", selected, { type: :boolean, selected: selected })
= label_tag(unit, unit.downcase) + tag(:br)
.form-buttons.filter-actions.actions{"data-hook" => "buttons"}
= button Spree.t('actions.update'), 'icon-refresh'

View File

@@ -394,6 +394,8 @@ en:
unsaved_confirm_leave: "There are unsaved changed on this page. Continue without saving?"
unsaved_changes: "You have unsaved changes"
available_units: "Available Units"
shopfront_settings:
embedded_shopfront_settings: "Embedded Shopfront Settings"
enable_embedded_shopfronts: "Enable Embedded Shopfronts"