diff --git a/app/helpers/spree/products_helper.rb b/app/helpers/spree/products_helper.rb deleted file mode 100644 index 9e367fb010..0000000000 --- a/app/helpers/spree/products_helper.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Spree - module ProductsHelper - def product_has_variant_unit_option_type?(product) - product.option_types.any? { |option_type| variant_unit_option_type? option_type } - end - - def variant_unit_option_type?(option_type) - Spree::Product.all_variant_unit_option_types.include? option_type - end - end -end diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index e08012beea..20b4fa05d8 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -362,10 +362,6 @@ module Spree presentation: option_type_presentation) end - def self.all_variant_unit_option_types - Spree::OptionType.where('name LIKE ?', 'unit_%%') - end - def destroy transaction do touch_distributors diff --git a/app/views/spree/admin/variants/_form.html.haml b/app/views/spree/admin/variants/_form.html.haml index 4990c64e4b..3e8b6a30f1 100644 --- a/app/views/spree/admin/variants/_form.html.haml +++ b/app/views/spree/admin/variants/_form.html.haml @@ -6,17 +6,16 @@ = f.label :display_as, t('.display_as') = f.text_field :display_as, class: "fullwidth", placeholder: t('.display_as_placeholder') - - if product_has_variant_unit_option_type?(@product) - - if @product.variant_unit != 'items' - .field - = label_tag :unit_value_human, "#{t('admin.'+@product.variant_unit)} ({{unitName(#{@product.variant_unit_scale}, '#{@product.variant_unit}')}})" - = hidden_field_tag 'product_variant_unit_scale', @product.variant_unit_scale - = number_field_tag :unit_value_human, nil, {class: "fullwidth", step: 0.01, 'ng-model' => 'unit_value_human', 'ng-change' => 'updateValue()'} - = f.number_field :unit_value, {hidden: true, 'ng-value' => 'unit_value'} - + - if @product.variant_unit != 'items' .field - = f.label :unit_description, t(:spree_admin_unit_description) - = f.text_field :unit_description, class: "fullwidth", placeholder: t('admin.products.unit_name_placeholder') + = label_tag :unit_value_human, "#{t('admin.'+@product.variant_unit)} ({{unitName(#{@product.variant_unit_scale}, '#{@product.variant_unit}')}})" + = hidden_field_tag 'product_variant_unit_scale', @product.variant_unit_scale + = number_field_tag :unit_value_human, nil, {class: "fullwidth", step: 0.01, 'ng-model' => 'unit_value_human', 'ng-change' => 'updateValue()'} + = f.number_field :unit_value, {hidden: true, 'ng-value' => 'unit_value'} + + .field + = f.label :unit_description, t(:spree_admin_unit_description) + = f.text_field :unit_description, class: "fullwidth", placeholder: t('admin.products.unit_name_placeholder') %div - @product.option_types.each do |option_type| diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 63f8e1b9a0..8713348446 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -931,15 +931,6 @@ module Spree expect(p.master.option_values.map(&:name).include?("1g")).to eq(false) end end - - it "finds all variant unit option types" do - ot1 = create(:option_type, name: 'unit_weight', presentation: 'Weight') - ot2 = create(:option_type, name: 'unit_volume', presentation: 'Volume') - ot3 = create(:option_type, name: 'unit_items', presentation: 'Items') - ot4 = create(:option_type, name: 'foo_unit_bar', presentation: 'Foo') - - expect(Spree::Product.all_variant_unit_option_types).to match_array [ot1, ot2, ot3] - end end describe "option types" do