-
-
Notifications
You must be signed in to change notification settings - Fork 725
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
[Spree Upgrade] Scope variants in line items availability validator #3232
[Spree Upgrade] Scope variants in line items availability validator #3232
Conversation
…with quantity zero Stock::Quantifier.can_supply? returns false for an input of zero when stock level is negative
a42b89e
to
62e7277
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope we can stop this variant override madness soon.
def validate_quantity(line_item, quantity) | ||
quantifier = Spree::Stock::Quantifier.new(line_item.variant_id) | ||
return if quantifier.can_supply? quantity | ||
line_item.scoper.scope(line_item.variant) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of exposing the scoper, you could offer line_item.scope_variant
.
I still have a concern about the performance of the scoper used in this way, but that can probably be solved later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I also think performance is best solved later when things are correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkllnk I think that would just be more lines of code, I'd need to create a new method in lineitem.
We all do 🙈. We need to all be aware of it when discussing priorities. |
…y expect statements
62e7277
to
16dbe39
Compare
…_item.scoper and moving Spree::Stock::Quantifier.can_supply? to VariantStock so that it becomes overridable
…pend on Spree::Stock::Quantifier
16dbe39
to
6c70998
Compare
This PR includes all 5 commits from #3210, this PRs commits are the last 5.
What? Why?
Closes #3118
When validating line_item.variant stock levels in stock/availability_validator we need to scope variants so that variant overrides stock levels are used instead. Here we re-use the the line_item.scoper so that the variant_overrides are not loaded several times in the handling fo line_items in the same request.
Additional problems solved:
What should we test?
This is one of the final steps in making cart and checkout handle stock levels correctly in v2!
the spec in 3118 (spec/features/consumer/shopping/variant_overrides_spec.rb:152) should be green.
Dependencies
This PR goes after #3210