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

OptionTypes loaded from DB instead of off product #43

Merged
merged 3 commits into from
Nov 13, 2020

Conversation

derrickp
Copy link
Contributor

@derrickp derrickp commented Nov 7, 2020

While I was importing some products into a store I was working on I noticed that I seemed to be getting duplicate Spree::OptionType values in the database, and I believe it was coming from the OptionType import here. I was able to replicate the issue by first saving the option type in the specs to the database and ensure they weren't on the product.

I think this is a use case that could happen to other people too, where the OptionType already exists in the DB without it being on the product. I think this covers the existing behaviour fairly well, and ensures we don't get any duplicate records.

If there's a quicker way to link the record created by the initialize on the product from the original code to the DB let me know.

@derrickp derrickp force-pushed the option-types-saving branch 4 times, most recently from bcf38eb to 82f8a94 Compare November 9, 2020 20:47
Copy link
Contributor

@MinasMazar MinasMazar left a comment

Choose a reason for hiding this comment

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

Great work here! 👍 I've left some comments, tell me what do you think.

spec/lib/solidus_importer/processors/option_types_spec.rb Outdated Show resolved Hide resolved
lib/solidus_importer/processors/option_types.rb Outdated Show resolved Hide resolved
Derrick Plotsky added 3 commits November 13, 2020 09:45
We force the name to be downcase when we make the option type inside of
the code, so I think it makes sense to make these match up with what
we're doing in the code.
This covers the case where the option types already exist inside of the
DB, but do not exist on the product that is being imported.

In this scenario, we should not be saving new option types, but with
the current code it does. I'm marking the spec as pending because it
will fail, but will be passing in the next commit.
In the case where the option types already exist in the DB, but not
in the product, we should look for them there first, so that we can
use the ones we've already got instead of making more.

This also adds some code so we're not overriding any information already
present on the option type, specifically the presentation field, as we
cannot really assume that the presentation should be equal to the name.
@derrickp
Copy link
Contributor Author

@MinasMazar I think I've addressed your comments. Thanks for the input!

Copy link
Contributor

@MinasMazar MinasMazar left a comment

Choose a reason for hiding this comment

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

Thank you for contributing here! 🎩

@MinasMazar MinasMazar merged commit 7d88772 into solidusio-contrib:master Nov 13, 2020
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.

2 participants