-
Notifications
You must be signed in to change notification settings - Fork 79
Display time promotion on order page #409
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| module Pricing | ||
| class ApplyTimePromotion | ||
| def call(event) | ||
| discount = PromotionsCalendar.new(event_store).current_time_promotions_discount | ||
|
|
||
| if discount.exists? | ||
| command_bus.(SetTimePromotionDiscount.new(order_id: event.data.fetch(:order_id), amount: discount.value)) | ||
| else | ||
| command_bus.(ResetTimePromotionDiscount.new(order_id: event.data.fetch(:order_id))) | ||
| end | ||
|
|
||
| rescue NotPossibleToAssignDiscountTwice, NotPossibleToResetWithoutDiscount | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def command_bus | ||
| Pricing.command_bus | ||
| end | ||
|
|
||
| def event_store | ||
| Pricing.event_store | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ def initialize(event_store) | |
|
|
||
| def call(cmd) | ||
| @repository.with_aggregate(Offer, cmd.aggregate_id) do |order| | ||
| order.apply_discount(Discounts::PercentageDiscount.new(cmd.amount)) | ||
| order.apply_discount(Discounts::GENERAL_DISCOUNT, Discounts::PercentageDiscount.new(cmd.amount)) | ||
| end | ||
| end | ||
| end | ||
|
|
@@ -33,7 +33,7 @@ def initialize(event_store) | |
|
|
||
| def call(cmd) | ||
| @repository.with_aggregate(Offer, cmd.aggregate_id) do |order| | ||
| order.reset_discount | ||
| order.reset_discount(Discounts::GENERAL_DISCOUNT) | ||
| end | ||
| end | ||
| end | ||
|
|
@@ -45,7 +45,31 @@ def initialize(event_store) | |
|
|
||
| def call(cmd) | ||
| @repository.with_aggregate(Offer, cmd.aggregate_id) do |order| | ||
| order.change_discount(Discounts::PercentageDiscount.new(cmd.amount)) | ||
| order.change_discount(Discounts::GENERAL_DISCOUNT, Discounts::PercentageDiscount.new(cmd.amount)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to verbalise my thoughts: I wonder if the information about the type of the discount is needed here. I don't know for now, but I think I would transfer this information through the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my first thought as well. The main problem is that once we add it to This also leads to problems like what type should we use if we want to add two discounts? Or what type should be used for the initial accumulator in the inject here:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The type would still be a type. If only one discount of specifiic type can be assigned to an order this is just a rule that can be exectued within the order class. But I wouldn't say that extending I assume that would still be true: PercentageDiscount.new(type: GENERAL, amount: 100).eql? PercentageDiscount.new(type: GENERAL, amount: 100)I'll refer to the second part of your reply later :)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I can give it another shot 👍 I will merge this PR and fix it in another one. |
||
| end | ||
| end | ||
| end | ||
|
|
||
| class SetTimePromotionDiscountHandler | ||
| def initialize(event_store) | ||
| @repository = Infra::AggregateRootRepository.new(event_store) | ||
| end | ||
|
|
||
| def call(cmd) | ||
| @repository.with_aggregate(Offer, cmd.aggregate_id) do |order| | ||
| order.apply_discount(Discounts::TIME_PROMOTION_DISCOUNT, Discounts::PercentageDiscount.new(cmd.amount)) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| class ResetTimePromotionDiscountHandler | ||
| def initialize(event_store) | ||
| @repository = Infra::AggregateRootRepository.new(event_store) | ||
| end | ||
|
|
||
| def call(cmd) | ||
| @repository.with_aggregate(Offer, cmd.aggregate_id) do |order| | ||
| order.reset_discount(Discounts::TIME_PROMOTION_DISCOUNT) | ||
lukaszreszke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
| end | ||
| end | ||
|
|
@@ -124,27 +148,18 @@ def initialize(event_store) | |
| def call(command) | ||
| with_retry do | ||
| @repository.with_aggregate(Offer, command.aggregate_id) do |order| | ||
| order.calculate_total_value(PricingCatalog.new(@event_store), time_promotions_discount) | ||
| order.calculate_total_value(PricingCatalog.new(@event_store)) | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
|
|
||
| def calculate_sub_amounts(command) | ||
| with_retry do | ||
| @repository.with_aggregate(Offer, command.aggregate_id) do |order| | ||
| order.calculate_sub_amounts(PricingCatalog.new(@event_store), time_promotions_discount) | ||
| order.calculate_sub_amounts(PricingCatalog.new(@event_store)) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def time_promotions_discount | ||
| PromotionsCalendar.new(@event_store).current_time_promotions_discount | ||
| end | ||
|
|
||
| end | ||
|
|
||
| class OnCouponRegister | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.