diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index d484b6d1236a..06794d370b54 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -295,14 +295,8 @@ def validate_variant_attrs # eg clone product. Will raise error if clonning a product with no variant return if variants.first&.valid? - unless Spree::Taxon.find_by(id: primary_taxon_id) - errors.add(:primary_taxon_id, - I18n.t('activerecord.errors.models.spree/product.must_exist')) - end - return if Enterprise.find_by(id: supplier_id) - - errors.add(:supplier_id, - I18n.t('activerecord.errors.models.spree/product.must_exist')) + errors.add(:primary_taxon_id, :blank) unless Spree::Taxon.find_by(id: primary_taxon_id) + errors.add(:supplier_id, :blank) unless Enterprise.find_by(id: supplier_id) end def update_units diff --git a/app/services/permitted_attributes/product.rb b/app/services/permitted_attributes/product.rb index f080f2b730f6..716549724d35 100644 --- a/app/services/permitted_attributes/product.rb +++ b/app/services/permitted_attributes/product.rb @@ -9,7 +9,7 @@ def self.attributes :unit_description, :variant_unit_name, :display_as, :sku, :group_buy, :group_buy_unit_size, :taxon_ids, :primary_taxon_id, :tax_category_id, :supplier_id, - :meta_keywords, :notes, :inherits_properties, + :meta_keywords, :notes, :inherits_properties, :shipping_category_id, { product_properties_attributes: [:id, :property_name, :value], variants_attributes: [PermittedAttributes::Variant.attributes], image_attributes: [:attachment] } diff --git a/app/views/spree/admin/products/_primary_taxon_form.html.haml b/app/views/spree/admin/products/_primary_taxon_form.html.haml index fa4b0b197660..1c4cf18c0216 100644 --- a/app/views/spree/admin/products/_primary_taxon_form.html.haml +++ b/app/views/spree/admin/products/_primary_taxon_form.html.haml @@ -1,6 +1,6 @@ -= f.field_container :primary_taxon do += f.field_container :primary_taxon_id do = f.label :primary_taxon_id, t('.product_category') %span.required * %br - = f.collection_select(:primary_taxon_id, Spree::Taxon.order(:name), :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"}) + = f.select :primary_taxon_id, options_from_collection_for_select(Spree::Taxon.order(:name), :id, :name, @product.primary_taxon_id), { include_blank: true }, { "data-controller": "tom-select", class: "primary" } = f.error_message_on :primary_taxon_id diff --git a/app/views/spree/admin/products/_shipping_category_form.html.haml b/app/views/spree/admin/products/_shipping_category_form.html.haml index 0f3635d698e7..d7157023ad19 100644 --- a/app/views/spree/admin/products/_shipping_category_form.html.haml +++ b/app/views/spree/admin/products/_shipping_category_form.html.haml @@ -1,4 +1,4 @@ -= f.field_container :shipping_categories do += f.field_container :shipping_category_id do = f.label :shipping_category_id, t(:shipping_category) = f.collection_select(:shipping_category_id, Spree::ShippingCategory.all, :id, :name, {:include_blank => false}, {:class => 'select2 fullwidth'}) = f.error_message_on :shipping_category_id diff --git a/app/views/spree/admin/products/new.html.haml b/app/views/spree/admin/products/new.html.haml index 70d620ef7994..d2a559181143 100644 --- a/app/views/spree/admin/products/new.html.haml +++ b/app/views/spree/admin/products/new.html.haml @@ -8,10 +8,10 @@ %legend{align: "center"}= t(".new_product") .sixteen.columns.alpha .eight.columns.alpha - = f.field_container :supplier do - = f.label :supplier, t(".supplier") + = f.field_container :supplier_id do + = f.label :supplier_id, t(".supplier") %span.required * - = f.select :supplier_id, options_from_collection_for_select(@producers, :id, :name, @product.supplier_id), { include_blank: t("spree.admin.products.new.supplier_select_placeholder") }, { "data-controller": "tom-select", class: "primary" } + = f.select :supplier_id, options_from_collection_for_select(@producers, :id, :name, @product.supplier_id), { include_blank: true }, { "data-controller": "tom-select", class: "primary" } = f.error_message_on :supplier_id .eight.columns.omega = f.field_container :name do @@ -25,8 +25,16 @@ = f.field_container :variant_unit do = f.label :variant_unit, t(".units") %span.required * - %select{id: 'product_variant_unit_with_scale', 'ng-model' => 'product.variant_unit_with_scale', 'ng-options' => 'unit[1] as unit[0] for unit in variant_unit_options', "data-controller": "tom-select","data-tom-select-options-value": '{"allowEmptyOption":false}', class: "primary"} - %option{'value' => '', 'ng-hide' => "hasUnit(product)"} + = f.select 'variant_unit', [], + { include_blank: true }, + { id: 'product_variant_unit_with_scale', + name: 'product_variant_unit_with_scale', + 'ng-model' => 'product.variant_unit_with_scale', + 'ng-options' => 'unit[1] as unit[0] for unit in variant_unit_options', + "data-controller": "tom-select", + "data-tom-select-options-value": '{"allowEmptyOption":false}', + class: "primary", + } %input{ type: 'hidden', 'ng-value': 'product.variant_unit', "ng-init": "product.variant_unit='#{@product.variant_unit}'", name: 'product[variant_unit]' } %input{ type: 'hidden', 'ng-value': 'product.variant_unit_scale', "ng-init": "product.variant_unit_scale='#{@product.variant_unit_scale}'", name: 'product[variant_unit_scale]' } = f.error_message_on :variant_unit @@ -34,16 +42,17 @@ = f.field_container :unit_value do = f.label :unit_value, t(".value"), 'ng-disabled' => "!hasUnit(product)" %span.required * - %input.fullwidth{ id: 'product_unit_value', 'ng-model' => 'product.master.unit_value_with_description', :type => 'text', placeholder: "eg. 2", 'ng-disabled' => "!hasUnit(product)" } + = f.text_field :unit_value, placeholder: "eg. 2", 'ng-model' => 'product.master.unit_value_with_description', class: 'fullwidth', 'ng-disabled' => "!hasUnit(product)" %input{ type: 'hidden', 'ng-value': 'product.master.unit_value', "ng-init": "product.master.unit_value='#{@product.unit_value}'", name: 'product[unit_value]' } %input{ type: 'hidden', 'ng-value': 'product.master.unit_description', "ng-init": "product.master.unit_description='#{@product.unit_description}'", name: 'product[unit_description]' } = f.error_message_on :unit_value = render 'display_as', f: f .six.columns.omega{ 'ng-show' => "product.variant_unit_with_scale == 'items'" } - = f.field_container :unit_name do - = f.label :product_variant_unit_name, t(".unit_name") + = f.field_container :variant_unit_name do + = f.label :variant_unit_name, t(".unit_name") %span.required * - %input.fullwidth{ id: 'product_variant_unit_name','ng-model' => 'product.variant_unit_name', :name => 'product[variant_unit_name]', :placeholder => t('admin.products.unit_name_placeholder'), :type => 'text' } + = f.text_field :variant_unit_name, :placeholder => t('admin.products.unit_name_placeholder'), 'ng-model' => 'product.variant_unit_name', class: 'fullwidth', 'ng-init': "product.variant_unit_name='#{@product.variant_unit_name}'" + = f.error_message_on :variant_unit_name .sixteen.columns.alpha .eight.columns.alpha = render 'spree/admin/products/primary_taxon_form', f: f diff --git a/config/locales/en.yml b/config/locales/en.yml index 74e5b24b684e..ca392ff25f9a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -120,8 +120,6 @@ en: attributes: base: card_expired: "has expired" - spree/product: - must_exist: 'must exist' order_cycle: attributes: orders_close_at: diff --git a/spec/system/admin/products_spec.rb b/spec/system/admin/products_spec.rb index 9fad202f7932..177558f41c40 100644 --- a/spec/system/admin/products_spec.rb +++ b/spec/system/admin/products_spec.rb @@ -184,7 +184,7 @@ click_button 'Create' expect(current_path).to eq spree.admin_products_path - expect(page).to have_content "Product Category must exist" + expect(page).to have_content "Product Category can't be blank" end it "creating product with empty product supplier fails" do @@ -201,7 +201,7 @@ click_button 'Create' expect(current_path).to eq spree.admin_products_path - expect(page).to have_content "Supplier must exist" + expect(page).to have_content "Supplier can't be blank" end describe "localization settings" do