Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-select current tax category on product form #3936

Conversation

spaghetticode
Copy link
Member

@spaghetticode spaghetticode commented Feb 15, 2021

The tax_category select on the product form page should pre-select the default category only when the product does not have a tax category yet. If it does, then the current product tax category should be pre-selected, instead of the default one.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

@spaghetticode spaghetticode added the type:bug Error, flaw or fault label Feb 15, 2021
@@ -158,7 +158,7 @@
<%= f.field_container :tax_category do %>
<%= f.label :tax_category_id, Spree::TaxCategory.model_name.human %>
<%= 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.collection_select(:tax_category_id, @tax_categories, :id, :name, { include_blank: t('spree.match_choices.none'), selected: f.object.tax_category_id || @default_tax_category&.id }, { class: 'custom-select' }) %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about setting the default on @product.tax_category at the controller level?

Copy link
Member Author

@spaghetticode spaghetticode Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, that's an option. Both solutions look rather equivalent to me. While the view gets simpler (we can entirely remove the selected specification here) the controller gains a before_action for both edit and new.

I've updated the code, let me know what you think!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this way! Let see if others have opinions as well.

The `tax_category` select on the product form page should pre-select
the default category only when the product does not have a tax
category yet. If it does, then the current product tax category
should be pre-selected, instead of the default one.
@spaghetticode spaghetticode force-pushed the spaghetticode/fix-product-tax-category-select branch from 28eb286 to b30c04b Compare February 15, 2021 15:29
@kennyadsl kennyadsl added Needs Backport changelog:solidus_backend Changes to the solidus_backend gem labels Feb 16, 2021
@kennyadsl kennyadsl added this to the 2.11 milestone Feb 16, 2021
@kennyadsl kennyadsl merged commit 68c5365 into solidusio:master Feb 16, 2021
@kennyadsl kennyadsl deleted the spaghetticode/fix-product-tax-category-select branch February 16, 2021 08:11
@MohammadAli1992
Copy link

MohammadAli1992 commented Feb 16, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_backend Changes to the solidus_backend gem type:bug Error, flaw or fault
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants