Sometimes you need to override default controller behavior in cs-cart. But you can't use override modifier like in hooks.
override
What are approaches we can use to override default controllers?
The simplest approach I found is to use dispatch_assign_template hook from fn.control.php file.
dispatch_assign_template
fn.control.php
define hook in your addon's init.php file.
init.php
add next function in your addon's func.php file
func.php
function fn_myaddon_dispatch_assign_template($controller, $mode, $area, &$controllers_cascade) { if ($controller !== 'categories' || $mode !== 'view') { return; } //excluded default categories controller $default_controller_path = DIR_ROOT . '/app/controllers/frontend/categories.php'; $controllers_cascade = array_filter( $controllers_cascade, static function ($item) use ($default_controller_path) { return $default_controller_path !== $item; } ); }
We passed &$controllers_cascade parameter by reference.
&$controllers_cascade
We excluded default controller from $controllers_cascade array.
$controllers_cascade
categories.post.php
if ($mode == 'view') { //your code here. }
The simplest approach I found is to use
dispatch_assign_templatehook fromfn.control.phpfile.define hook in your addon's
init.phpfile.add next function in your addon's
func.phpfileWe passed
&$controllers_cascadeparameter by reference.We excluded default controller from
$controllers_cascadearray.categories.post.phpand add