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

Fixing product discard and classifications issue #3439

Merged
merged 1 commit into from
Dec 12, 2019

Conversation

softr8
Copy link
Contributor

@softr8 softr8 commented Nov 26, 2019

When removing a product via discard, it was destroying all
classifications via delete_all, acts as list callbacks were
not called leaving gaps in position.

Created this one instead of #3172

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)

When removing a product via discard, it was destroying all
classifications via delete_all, acts as list callbacks were
not called leaving gaps in position.
@@ -25,7 +25,7 @@ class Product < Spree::Base
variants_including_master.discard_all
self.product_option_types = []
self.product_properties = []
self.classifications = []
self.classifications.destroy_all

Choose a reason for hiding this comment

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

Style/RedundantSelf: Redundant self detected.

Copy link
Member

Choose a reason for hiding this comment

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

Great catch, I think we should use discard_all instead. Also, in another PR I think it's a good idea to do the same with the rest of the associations in that block, if they are soft-deletable, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Classifications is not discard'able, that's why I used destroy_all so act_as_list callbacks are executed.

I also had a look at the other relationships and the only one with callbacks is product properties but position is only used for sorting, it does not affect like in classifications

Copy link
Member

Choose a reason for hiding this comment

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

You are right @softr8, the rest of associations should be handled in a different context, if needed. Thanks!

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

👍

@@ -25,7 +25,7 @@ class Product < Spree::Base
variants_including_master.discard_all
self.product_option_types = []
self.product_properties = []
self.classifications = []
self.classifications.destroy_all
Copy link
Member

Choose a reason for hiding this comment

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

You are right @softr8, the rest of associations should be handled in a different context, if needed. Thanks!

Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

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

@softr8 thanks for the fix 👍

@kennyadsl kennyadsl merged commit e331eec into solidusio:master Dec 12, 2019
@kennyadsl kennyadsl mentioned this pull request Dec 12, 2019
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants