-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add #discounted_amount by adjustments
#6379
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
Open
mamhoff
wants to merge
11
commits into
solidusio:main
Choose a base branch
from
mamhoff:add-discounts-by-lane
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+313
−12
Open
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
112f46e
Add Promotion.within_lane
mamhoff 1e896f8
Add Promotion.lanes_before(lane) and .lanes_before_current_lane
mamhoff 6ed7ec8
Implement discountable#discounts_by_lanes
mamhoff 9537fa2
Add LineItem#previous_lane_discounts
mamhoff e1319c5
Add Discountable module to shipments
mamhoff 485af58
Add Discountable module to shipping rates
mamhoff c682f62
Add new method `discounted_amount` to discountable classes
mamhoff 536b0ce
DiscountedAmount: Exclude discounts marked for destruction
mamhoff 2ddd81a
Use PromotionLane.current over Promotion.current_lane
mamhoff ac0f616
Make #discounts_by_lanes private
mamhoff 87223f1
Make previous_lane_discounts private
mamhoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
promotions/app/models/concerns/solidus_promotions/adjustment_discounts.rb
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module SolidusPromotions | ||
| module AdjustmentDiscounts | ||
| def discounts_by_lanes(lanes) | ||
| adjustments.select do |adjustment| | ||
| !adjustment.marked_for_destruction? && | ||
| adjustment.source_type == "SolidusPromotions::Benefit" && | ||
| adjustment.source.promotion.lane.to_sym.in?(lanes.map(&:to_sym)) | ||
| end | ||
| end | ||
| end | ||
| end | ||
19 changes: 19 additions & 0 deletions
19
promotions/app/models/concerns/solidus_promotions/discounted_amount.rb
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module SolidusPromotions | ||
| module DiscountedAmount | ||
| def discounted_amount | ||
| amount + previous_lane_discounts.sum(&:amount) | ||
| end | ||
|
|
||
| def current_lane_discounts | ||
| raise NotCalculatingPromotions unless Promotion.current_lane | ||
|
|
||
| discounts_by_lanes([Promotion.current_lane]) | ||
| end | ||
|
|
||
| def previous_lane_discounts | ||
| discounts_by_lanes(Promotion.lanes_before_current_lane) | ||
| end | ||
| end | ||
| end |
5 changes: 5 additions & 0 deletions
5
promotions/app/models/solidus_promotions/not_calculating_promotions.rb
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module SolidusPromotions | ||
| class NotCalculatingPromotions < StandardError; end | ||
| end |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.