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

Stacking Promotions #7

Merged
merged 11 commits into from
Oct 2, 2023
Merged

Stacking Promotions #7

merged 11 commits into from
Oct 2, 2023

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Sep 29, 2023

This is a working prototype of stacking promotions. For now the only calculator that does it "right" is the distributed amounts calculator.

The way it's done it we introduce a wrapper around the Spree::Order, Spree::LineItem, Spree::Shipment and Spree::ShippingRate objects. They get an instance variable discounts that holds the discounts from the previously applied lanes, and a discounted_amount getter that subtracts the discounts from the item's amount.

mamhoff added 11 commits October 2, 2023 20:31
For calculating and retrieving intermediate amounts on line items,
orders, shipments, and shipping rates, we need some kind of value object
that holds a reference to the order and behaves more or less like the
real things.

I've considered using Ruby Refinements instead of Delegators for this,
but they are clunky in that they need to be referenced in every file
using them.
We need a way to store intermediate amounts on the order we adjust. This
accomplishes this in part by storing the discounts on custom delegators
to the Solidus objects.
The responsibilities for this class are now in the Discountable::*
classes.
We want to run the promotion chooser on all discounts eligible for an
item by lane. For that we need a collection of discounts for that item
on that lane. This separates creating the discount and adding it, giving
us space to do the selection.
We need the discount choosing to happen per lane, and that can't happen
in the OrderDiscounter.
This has no functional changes, but it renames some variables in this
class so things don't seem as confusing.
This was used in the order discounter anticipating features we don't
have.
Otherwise we get discounted amounts from discounts from the current lane
(which we don't want).
This change allows use to actually use the "lanes" feature in our
calculators.
@mamhoff mamhoff force-pushed the adjustments-by-lane branch from 22607e7 to 5756e6a Compare October 2, 2023 18:32
Copy link
Collaborator

@davecandlescience davecandlescience left a comment

Choose a reason for hiding this comment

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

LGTM

@mamhoff mamhoff merged commit dea262b into main Oct 2, 2023
mamhoff added a commit that referenced this pull request Jul 1, 2024
mamhoff added a commit that referenced this pull request Oct 25, 2024
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