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

A later invocation of an OrderInterceptor-like concept #3286

Open
billycc7 opened this issue Dec 20, 2024 · 0 comments
Open

A later invocation of an OrderInterceptor-like concept #3286

billycc7 opened this issue Dec 20, 2024 · 0 comments

Comments

@billycc7
Copy link

Is your feature request related to a problem? Please describe.
Currently, the OrderInterceptor allows implementors to run checks before order mutations are committed. However, the willAddItemToOrder function does not have visibility into the Order nor OrderLine.

Describe the solution you'd like
Introduce a new function, similar to willAddItemToOrder, that runs at a later stage of the process, after an item has been added to the order (but not yet committed). This function should:

  • Provide access to the OrderLine with a valid id within the current context.
  • Allow implementors to reject the mutation by returning a string, throwing an error, or using a similar mechanism.
  • Trigger a rollback of the transaction if the mutation is rejected.

This additional functionality would enable more complex validations and use cases by allowing checks based on the newly added OrderLine.

Describe alternatives you've considered
We initially implemented a bundle-like concept by overriding Shop API mutations. This approach gave us access to the Order (via activeOrder) and the bundle's OrderLine, allowing us to manage relationships between bundle products and their child items. However, this solution is limited to the Shop API and does not leverage OrderInterceptor functionality.

We also considered extending this approach to the Admin API by overriding draft mutations, aiming for a solution where both Shop API and Admin API would implicitly handle child items. However, after learning about OrderInterceptors, we paused our implementation to explore whether they could provide an alternative.

Additional context
In our current implementation of bundles:

  • We tie child items to their parent (the bundle product).
  • The relative quantities of child items are maintained by noting how many are required for a single bundle and scaling accordingly (e.g., after add, adjust, or remove operations).
  • We reject shop-api attempts to mutate the child items directly.
  • The proposed enhancement to OrderInterceptor could make our implementation more clear and maintainable.
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

No branches or pull requests

1 participant