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
[NUT-201] Refactor used_by? method for one_use_per_user rule #10554
Merged
damianlegawiec
merged 5 commits into
spree:master
from
spark-solutions:one_use_per_user_promotion_issue
Oct 29, 2020
Merged
[NUT-201] Refactor used_by? method for one_use_per_user rule #10554
damianlegawiec
merged 5 commits into
spree:master
from
spark-solutions:one_use_per_user_promotion_issue
Oct 29, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Manage this branch in SquashTest this branch here: https://spark-solutionsone-use-per-use-tm48z.squash.io |
@przemosk Happy to hear Your thoughts about that! |
przemosk
reviewed
Oct 26, 2020
przemosk
approved these changes
Oct 26, 2020
… arent blaclisted
KacperMekarski
changed the title
Refactor used_by? method for one_use_per_user rule
[NUT-200] Refactor used_by? method for one_use_per_user rule
Oct 27, 2020
KacperMekarski
changed the title
[NUT-200] Refactor used_by? method for one_use_per_user rule
[NUT-201] Refactor used_by? method for one_use_per_user rule
Oct 27, 2020
szymoniwacz
approved these changes
Oct 28, 2020
nnande
reviewed
Oct 28, 2020
nnande
reviewed
Oct 28, 2020
nnande
approved these changes
Oct 29, 2020
damianlegawiec
approved these changes
Oct 29, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This branch is created because of https://spark-solutions.atlassian.net/browse/NUT-201 task.
User can use one_use_per_user promotion many times.
This was tested, but in production user somehow can use the promotion many times.
Actual Behavior
So far condition was checked by looking for same PromotionAction through adjustments:
spree/core/app/models/spree/promotion.rb
Line 196 in 849f985
Although in tests PromotionActions are associated with adjustments as source, in production it occurs that it does not always happen:
irb(main):004:0> user.orders.complete.first.all_adjustments.where(source_type: "Spree::PromotionAction").pluck(:source_id) => [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil] irb(main):005:0> user.orders.complete.second.all_adjustments.where(source_type: "Spree::PromotionAction").pluck(:source_id) => [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil] irb(main):006:0> user.orders.complete.third.all_adjustments.where(source_type: "Spree::PromotionAction").pluck(:source_id) => []
However, order is always associated:
irb(main):009:0> user.orders.complete.first.promotions.pluck(:id) => [33, 33, 33, 33, 33, 33, 33] irb(main):010:0> user.orders.complete.second.promotions.pluck(:id) => [33] irb(main):011:0> user.orders.complete.third.promotions.pluck(:id) => [33, 33, 33, 33]
Expected behavior
User can use promo code only once
Possible fix
Use promotion to check if it was already used (simpler and based on production data it works).