From 7e8b3694be2cdcaba4d915158991fa864ce0f78e Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 10 Mar 2026 15:32:34 +1100 Subject: [PATCH] Move class instance variable to helper --- app/controllers/admin/products_v3_controller.rb | 6 ------ app/helpers/admin/products_helper.rb | 5 +++++ app/views/admin/products_v3/_variant_row.html.haml | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/products_v3_controller.rb b/app/controllers/admin/products_v3_controller.rb index 073107c15e..e201643511 100644 --- a/app/controllers/admin/products_v3_controller.rb +++ b/app/controllers/admin/products_v3_controller.rb @@ -8,7 +8,6 @@ module Admin before_action :init_filters_params before_action :init_pagination_params before_action :init_none_tag - before_action :fetch_data, include: [:index, :bulk_update] def index fetch_products @@ -204,11 +203,6 @@ module Admin ).distinct.order(:name).pluck(:name) end - def fetch_data - @allowed_source_producers = OpenFoodNetwork::Permissions.new(spree_current_user) - .enterprises_granting_sourced_variants - end - def fetch_products product_query = OpenFoodNetwork::Permissions.new(spree_current_user) .editable_products.merge(product_scope_with_includes).ransack(ransack_query).result diff --git a/app/helpers/admin/products_helper.rb b/app/helpers/admin/products_helper.rb index 90480e371f..18b2f2dda7 100644 --- a/app/helpers/admin/products_helper.rb +++ b/app/helpers/admin/products_helper.rb @@ -47,5 +47,10 @@ module Admin def variant_tag_enabled?(user) feature?(:variant_tag, user) || feature?(:variant_tag, *user.enterprises) end + + def allowed_source_producers + @allowed_source_producers ||= OpenFoodNetwork::Permissions.new(spree_current_user) + .enterprises_granting_sourced_variants + end end end diff --git a/app/views/admin/products_v3/_variant_row.html.haml b/app/views/admin/products_v3/_variant_row.html.haml index 1aa5f0649b..fbd272f2cf 100644 --- a/app/views/admin/products_v3/_variant_row.html.haml +++ b/app/views/admin/products_v3/_variant_row.html.haml @@ -92,7 +92,7 @@ - if variant.persisted? = link_to t('admin.products_page.actions.edit'), edit_admin_product_variant_path(variant.product, variant) - - if @allowed_source_producers.include?(variant.supplier) + - if allowed_source_producers.include?(variant.supplier) = link_to t('admin.products_page.actions.create_sourced_variant'), admin_create_sourced_variant_path(variant_id: variant.id, product_index:), 'data-turbo-method': :post - if variant.product.variants.size > 1