-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Handling of active orders when price of variants is changed. #664
Comments
How are other frameworks/stores handling this?It is surprisingly difficult to find discussions of this issue on the trackers of OSS e-commerce projects, as well as in the wider e-commerce context. Here's what I found:
Exploration of problemScenario 1
Possible handlings
Scenario 2
Possible handlings
Scenario 3
Possible handlings
ImplementationWe could define a strategy which controls how these scenarios are handled. Rough sketch: export type PriceCalculationResult = {
price: number;
priceIncludesTax: boolean;
};
export interface ChangedPriceHandlingStrategy {
handlePriceChange(ctx: RequestContext,
current: PriceCalculationResult,
existingItems: OrderItem[]): PriceCalculationResult | string;
} The idea is that any time an OrderLine is changed (item added, quantity increased) we check the price (as returned from the configured If the calculated price does not equal the OrderItem.listPrice, then we invoke the Example: to use the existing price already in the Order: handlePriceChange(ctx, current, existingItems) {
return {
price: existingItems[0].listPrice,
priceIncludesTax: existingItems[0].priceIncludesTax,
}
} Example: overwrite with the latest price: handlePriceChange(ctx, current, existingItems) {
return current;
} The Additionally, the entire Order could be checked in this way when transitioning to the |
In my initial implementation, there are a couple of new fields on the type OrderLine {
"""
Non-zero if the unitPrice has changed since it was initially added to Order
"""
unitPriceChangeSinceAdded: Int!
"""
Non-zero if the unitPriceWithTax has changed since it was initially added to Order
"""
unitPriceWithTaxChangeSinceAdded: Int!
} The value of these fields are calculated using a new DB column on OrderItem, The new Refreshing all pricesOne part that is not yet implemented is the ability to refresh (update the prices of) all OrderLines in an Order. At first I was thinking of triggering this when e.g. transitioning to the
|
Relates to #664 BREAKING CHANGE: The OrderItem entity has a new field, `initialListPrice`, used to better handle price changes to items in an active Order. This schema change will require a DB migration.
Let us also allow adding any custom algorithmic implementation in the handlePriceChange method by implementing any other services or even custom logics by the developer. |
@BeepLoveKarki yes, will be supported - the ChangedPriceHandlingStrategy is an InjectableProvider so you can inject via the |
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
a. Allow customers to purchase the variants they have in the cart, at the old price. (The flag mentioned above will help in handling in the frontend)
a. Purge all existing active orders which contain that variant OR Remove that variant from all existing active orders.
b. Update the existing active orders with the new price.
Describe alternatives you've considered
Till the time this is implemented, you can check if the line.unitPriceWithTax is equal to the current variant.priceWithTax. If not, customers can be intimated that older price is active for them.
If you want to stop customers from purchasing at the older price, delete those orders from the DB.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: