Fixed the logic and moved the code to a helper file

This commit is contained in:
Manuel Gonçalves
2024-12-01 20:43:31 +00:00
parent 7d5bb4a6fa
commit d95bb7736a
3 changed files with 10 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ module Spree
include OrderCyclesHelper
include EnterprisesHelper
helper ::Admin::ProductsHelper
helper Spree::Admin::TaxCategoriesHelper
before_action :load_data
before_action :load_producers, only: [:index, :new]

View File

@@ -0,0 +1,8 @@
module Spree::Admin::TaxCategoriesHelper
def tax_category_dropdown_options(require_tax_category)
{
:include_blank => Spree::Config.products_require_tax_category ? false : t(:none),
selected: Spree::Config.products_require_tax_category ? Spree::TaxCategory.find_by(is_default: true)&.id : nil
}
end
end

View File

@@ -1,5 +1,5 @@
= f.field_container :tax_category_id do
= f.label :tax_category_id, t(:tax_category)
%br
= f.collection_select(:tax_category_id, Spree::TaxCategory.all, :id, :name, {:include_blank => Spree::Config.products_require_tax_category ? false : t(:none), selected: Spree::TaxCategory.find_by(is_default: true)&.id}, {:class => "select2 fullwidth"})
= f.collection_select(:tax_category_id, Spree::TaxCategory.all, :id, :name, tax_category_dropdown_options(Spree::Config.products_require_tax_category), {:class => "select2 fullwidth"})
= f.error_message_on :tax_category_id