Replies: 2 comments 2 replies
-
Does anyone have any feedback, suggestions or opinions on this topic? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hookable calls hooks sequentially by the order which they were registered. Perhaps you could scope down your question what are you mainly looking for? (runnable minimal reproduction are always helpful) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
I'm building an internal ecommerce software for my company using Nuxt and Nitro. I'm planning on adding a plugin system to it that allows extending the behavior of the core.
I would like to add certain hooks for most core processes such as
order:before-create
andorder:after-create
to which plugins can hook into and either perform an action, or provide new data to override the core functionality.Example
I install a
GiftPlugin
which will add a gift to every order above $100. To achieve this, I would have aPOST /api/orders
endpoint at the core of the system, and before saving the order to the database I would call theorder:before-create
hook with the core order data as an argument.The
GiftPlugin
will add the gift product to the line items and return the new order data. The order returned by the plugin is the one that should be saved to the database.Also, the core should allow multiple plugins to edit the order sequentially and each hook would receive the result from the previous plugin.
What I tried
I added a hook to my Nitro app called
order:before-create
and called it like this:I would love to know if this is an adequate implementation of what I'm trying to achieve, if there's something I'm doing wrong or if
hookable
is even the right choice for something like this.Thank you!
Beta Was this translation helpful? Give feedback.
All reactions