-
-
Notifications
You must be signed in to change notification settings - Fork 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
Order interceptor #2123
Comments
A generalized version of this that is also worth considering would be to allow interceptors for all GraphQL operations. This would allow users to "decorate" any existing operation. Could an existing NestJS mechanism be used for this? This could be the low-level implementation upon which the order interceptor is built. As part of this task we'd need a working demo of product bundling plugin as well as a docs guide. |
Another use-case:
|
Just a little tangent on the interface. What about |
@michaelbromley Is there any timeline estimate on this feature? We are currently in the midst of developing a product bundle plugin, and would like to contribute, as long as the release of this feature is somewhere in the coming months :-)
|
We do something similar in this plugins. If you throw an error, the transaction is rolled back, so no items are added. The benefit of this is that you don't have to do a dry run first, and repeat the action if the dry run succeeds |
I can't give a better estimate than "it's on the list for v3.x". It certainly won't be within 1 month. Perhaps 2 for a pre-release, but maybe 3 or more. I'll coordinate with you when I have a better idea of feature priority for the next minor. |
Another use case:
Some shops have very limited stocks and if another active order already has that variant, they can then prevent it being added to another order (in a given time window) |
@martijnvdbrug now there is an ETA available! |
I would see this as out of scope, since you can create a custom query that provides this functionality. You could even use a shared service for the actual logic, that you use in the OrderInterpector as well. In this way the custom query is just a thin wrapper around the shared business logic. |
Is your feature request related to a problem? Please describe.
In some more advanced use-cases a need has emerged to be able to intercept operations on an order and do some validation or take some other side-effectful action.
Use-case: Product bundles
Ref: #236
Let's say we want to create a plugin that allows us to group multiple product variants into a "bundle" that can get purchased at a special price. We want to ensure that the entire bundle is added or removed at once, and not allow the bundle to be added and then have individual variants from that bundle removed.
Allowing us to intercept the "add item", "adjust quantity", "remove item" operations would let us enforce this constraint.
Use-case: Min, max quantities
We want to enforce a rule that a certain product has a minimum and maximum quantity that may be purchased in a single order (this is independent of stock control). Using validation allows us to enforce these constraints when the customer attempts to update the order contents.
Describe the solution you'd like
We should extend the
OrderOptions
interface to allow an array ofOrderInterceptor
objects which would look roughly like this:So taking the min, max use-case, we could define the
willAddItemToOrder
hook to check the variant's custom fields for min, max values, and if the quantity being added does not fall within this range, we can return an error message.Describe alternatives you've considered
An alternative is to re-implement the various graphql mutations that update order contents, but this is tedious, error-prone and does not handle instances where the OrderService APIs are used directly elsewhere.
The text was updated successfully, but these errors were encountered: