Sometimes you need to override default controller behavior in cs-cart. But you can't use override
modifier like in hooks.
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.
define hook in your addon's init.php
file.
add next function in your addon's func.php
file
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.
We excluded default controller from $controllers_cascade
array.
categories.post.php
and addif ($mode == 'view') {
//your code here.
}