Skip to content

Commit

Permalink
Fix TaxCategory default not showing up in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
vl3 committed Sep 24, 2020
1 parent f36e61f commit fbc2d16
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions backend/app/controllers/spree/admin/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def location_after_save

def load_data
@tax_categories = Spree::TaxCategory.order(:name)
@default_tax_category = @tax_categories.detect(&:is_default)
@shipping_categories = Spree::ShippingCategory.order(:name)
end

Expand Down
4 changes: 2 additions & 2 deletions backend/app/views/spree/admin/products/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@
<div data-hook="admin_product_form_tax_category">
<%= f.field_container :tax_category do %>
<%= f.label :tax_category_id, Spree::TaxCategory.model_name.human %>
<%= f.field_hint :tax_category %>
<%= f.collection_select(:tax_category_id, @tax_categories, :id, :name, { include_blank: t('spree.match_choices.none') }, { class: 'custom-select' }) %>
<%= f.field_hint :tax_category, default_tax_category: @default_tax_category&.name %>
<%= f.collection_select(:tax_category_id, @tax_categories, :id, :name, { include_blank: t('spree.match_choices.none'), selected: @default_tax_category&.id }, { class: 'custom-select' }) %>
<%= f.error_message_on :tax_category %>
<% end %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions backend/config/initializers/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def error_message_on(method, options = {})
end

def field_hint(method, options = {})
title = options[:title] || @object.class.human_attribute_name(method)
text = options[:text] || I18n.t(method, scope: [:spree, :hints, @object.class.model_name.i18n_key])
title = options.delete(:title) || @object.class.human_attribute_name(method)
text = options.delete(:text) || I18n.t(method, scope: [:spree, :hints, @object.class.model_name.i18n_key], **options)
@template.admin_hint(title, text)
end
end
Expand Down
5 changes: 5 additions & 0 deletions backend/spec/features/admin/products/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def build_option_type_with_values(name, values)
context "creating a new product" do
before(:each) do
@shipping_category = create(:shipping_category)
@tax_category = create(:tax_category, name: 'Alcohol taxes', is_default: true)
click_nav "Products"
click_on "New Product"
end
Expand Down Expand Up @@ -239,6 +240,10 @@ def build_option_type_with_values(name, values)
click_button "Update"
expect(page).to have_content("successfully updated!")
end

it "should show default tax category" do
expect(page).to have_select('product_tax_category_id', selected: 'Alcohol taxes')
end
end

context "cloning a product", js: true do
Expand Down
2 changes: 1 addition & 1 deletion core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ en:
shipping_category: 'This determines what kind of shipping this product requires.<br/>
Default: Default'
tax_category: 'This determines what kind of taxation is applied to this product.<br/>
Default: None'
Default: %{default_tax_category}'
spree/promotion:
expires_at: This determines when the promotion expires. <br/> If no value
is specified, the promotion will never expire.
Expand Down

0 comments on commit fbc2d16

Please sign in to comment.