In this Blog, we will learn about Cs-Cart Hooks in the coding scenario and their types.
What is hooking?
‘Hooking’ is a programming concept that is used to control flow. Hook are the entry points in the code for external code and for modifications. We can use hook in Cs-cart to manipulate the data or get the data in between the flow of the code.
There is also a Cs-Cart hook explanation.
The hook is very important in creating add-ons in CS-Cart.
Cs-Cart Hooks Types
There are two types of hooks used in Cs-Cart.
- PHP Hooks
- TPL Hooks
PHP Hooks
PHP hook are specifically specified in the core code of the Cs-Cart. We can use these hooks by calling a specified function of the hook in the addon.
How to use Hooks in Cs-Cart
There are two ways to set hooks in the add-on:-
- Using addon Init and func file
- Using addon XML scheme 4.0 and Bootstrap.
Using the addon Init and func file
Firstly, we have to register the hook which we are going to use in ‘init.php’ by using ‘fn_registers_hooks’.
Now Hook is registered, you can use it by creating a hook function in the addon. We have to create a specified function in the addon ‘func.php’ file. The hook Function name should be specified in this way: –
‘fn_addon_name_hook_name(arguments) {
//Your code
}
Example
Using addon XML scheme 4.0 and Bootstrap
The OOPS concept is needed for using the hook in this way.
In this, we have to use scheme 4.0 so that we can use autoloader PSR-4 in the addon XML file.
In the addon.xml file, you can load the controller using namespace through the PSR4 tag.
Now, you have to create the src folder inside the addon.
Use ServiceProvider.php for registering hook handlers classes.
Now, map hook in bootstrap.php using getHookHandlerMap() function.
Then, you have to create methods in the hook handler class according to the map.
Note:- The blog will contain TPL Hook.
For Rest API documentation:- Refer to this link
Current Product Version - 1.0
Be the first to comment.