diff --git a/app/controllers/admin/product_import_controller.rb b/app/controllers/admin/product_import_controller.rb index 181870f3b2..c71e3ad015 100644 --- a/app/controllers/admin/product_import_controller.rb +++ b/app/controllers/admin/product_import_controller.rb @@ -10,6 +10,8 @@ module Admin @product_categories = Spree::Taxon.order('name ASC').pluck(:name).uniq @tax_categories = Spree::TaxCategory.order('name ASC').pluck(:name) @shipping_categories = Spree::ShippingCategory.order('name ASC').pluck(:name) + @producers = OpenFoodNetwork::Permissions.new(spree_current_user). + managed_product_enterprises.is_primary_producer.by_name.to_a end def import diff --git a/app/views/admin/product_import/_dfc_import_form.html.haml b/app/views/admin/product_import/_dfc_import_form.html.haml index 5339a9a862..3416a943e5 100644 --- a/app/views/admin/product_import/_dfc_import_form.html.haml +++ b/app/views/admin/product_import/_dfc_import_form.html.haml @@ -1,11 +1,16 @@ -%h3 Import from DFC catalog +%h3= t(".title") %br = form_with url: main_app.admin_dfc_product_imports_path, method: :get do |form| - = form.label :enterprise_id - = form.text_field :enterprise_id + = form.label :enterprise_id, t(".enterprise") + %span.required * %br - = form.label :catalog_url - = form.text_field :catalog_url + = form.select :enterprise_id, options_from_collection_for_select(@producers, :id, :name, @producers.first&.id), { "data-controller": "tom-select", class: "primary" } %br - = form.submit "Import" + %br + = form.label :catalog_url, t(".catalog_url") + %br + = form.text_field :catalog_url, size: 60 + %br + %br + = form.submit t(".import") diff --git a/config/locales/en.yml b/config/locales/en.yml index 5843a86b07..96b6ee7de5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -929,6 +929,11 @@ en: product_categories: Product Categories tax_categories: Tax Categories shipping_categories: Shipping Categories + dfc_import_form: + title: "Import from DFC catalog" + enterprise: "Enterprise" + catalog_url: "DFC catalog URL" + import: "Import" import: review: Review import: Import diff --git a/spec/system/admin/dfc_product_import_spec.rb b/spec/system/admin/dfc_product_import_spec.rb index d3aea24884..195c8370c5 100644 --- a/spec/system/admin/dfc_product_import_spec.rb +++ b/spec/system/admin/dfc_product_import_spec.rb @@ -7,7 +7,7 @@ describe "DFC Product Import" do include AuthorizationHelper let(:user) { create(:oidc_user, owned_enterprises: [enterprise]) } - let(:enterprise) { create(:enterprise) } + let(:enterprise) { create(:supplier_enterprise) } let(:source_product) { create(:product, supplier: enterprise) } before do @@ -20,7 +20,7 @@ describe "DFC Product Import" do it "imports from given catalog" do visit admin_product_import_path - fill_in "enterprise_id", with: enterprise.id + select enterprise.name, from: "Enterprise" # We are testing against our own catalog for now but we want to replace # this with the URL of another app when available.