Add new modification API for the extension where the event can't reach #11770
Replies: 3 comments 11 replies
-
One a first view,it looks quite promising. |
Beta Was this translation helpful? Give feedback.
-
I am not quite sure why you call it hooks instead of events. All you basically want is more event triggers, especially for library classes. There will always be limitations on what can be modified. Perhaps a more fundamental approach can solve the issue of more flexible modification capabilities in a better way. I am thinking of a decorator design pattern (see e.g. https://refactoring.guru/design-patterns/decorator) in conjunction with a factory class (https://refactoring.guru/design-patterns/factory-method). Also, I am planning to port our Override Engine (https://www.mhccorp.com/opencart/free-items/override-engine-oc3) to OpenCart 4. |
Beta Was this translation helpful? Give feedback.
-
@punitkumar: Modifying methods from the Cart class, such as getProducts or add, would be easy with our planned Override Engine. It would merely be a matter of overriding these methods, they can still call the parent method if needed. The problem with hooks and/or event is that you have to add pre-planned triggers in so many places, where most of them won't ever be used, and on the other hand, where some wanted trigger places could still be missing. Thinking about it, even without our planned Override Engine, if we implemented a simpler decorator design pattern, you'd still gain more flexibility compared to events/hooks triggers. |
Beta Was this translation helpful? Give feedback.
-
First of all, removing ocmod from opencart 4 is best decision because it was doing so much conflict between extensions. but as we know, an event can't reach everywhere so we may need one more parallel API which do the job which event can't do.
I have the idea which i was implemented in my own project mazaengine. let me explain in detail with example.
i am talking about a hook API. first let me show the implementation of it then i will show you how to use
Library file:
Startup:
Trigger: (Currently added only two trigger, but in real project we should implement many place where event does not reach)
1). Allow to modify where condition of sql query of getProducts
File: catalog/model/catalog/product.php
2). Allow to add new custom tab beside description and specifications in product page
File: catalog/view/template/product/product.twig
Register for hook is same as register for event
This is not final implementation, i initially made in opencart 3 so required to change it as per opencart 4 coding standard. I want to take attention of @danielkerr on this, please let us know your thoughts
So now let's start discussion on this.
Beta Was this translation helpful? Give feedback.
All reactions