How To Override Core Functions?

I have this function:



fn_user_logout( …



and I want to override it



in init.php i have:



if ( !defined('AREA') ) { die('Access denied'); }



fn_register_hooks(

'get_category_data_pre',

'fn_advanced_addon_fn_user_logout_pre'

);



in func.php I have:



fn_advanced_addon_fn_user_logout_pre( …





what mI doing wrong here?

The fn_user_logout function does not contain any hooks. Therefore you cannot make any changes with this function. Please find more details about PHP hooks here:



http://docs.cs-cart…/php_hooks.html

[quote name='eComLabs' timestamp='1421057839' post='202321']

The fn_user_logout function does not contain any hooks. Therefore you cannot make any changes with this function. Please find fore details about PHP hooks here:



http://docs.cs-cart…/php_hooks.html

[/quote]



thanks, just 2 question:



*if I want to override that funcion on my addon, how can I do that?



*is there a way to know what functions has a hook to use?



Thanks

[quote name='nil2567' timestamp='1421174485' post='202492']

*if I want to override that funcion on my addon, how can I do that?

[/quote]



Unfortunately there is no way to do it without hooks.


[quote name='nil2567' timestamp='1421174485' post='202492']

*is there a way to know what functions has a hook to use?

[/quote]



You can check required function and find similar code:



fn_set_hook('hook_name', $param1, $param2, .... $paramN);

Unfortunately there is no way to do it without hooks.



You can check required function and find similar code:

fn_set_hook('hook_name', $param1,  $param2, .... $paramN);

Hi eComLabs,

I want to override following function in my_changes add on. So, Can you please suggest me How to create directory for this in cs cart ?

Thanks.

 fn_set_hook('get_categories', $params, $join, $condition, $fields, $group_by, $sortings, $lang_code);

Hi eComLabs,

Is there any way to reverse Parent category order like Des without change order of sub categories using below hook ?

Hi eComLabs,

I want to override following function in my_changes add on. So, Can you please suggest me How to create directory for this in cs cart ?

Thanks.

 fn_set_hook('get_categories', $params, $join, $condition, $fields, $group_by, $sortings, $lang_code);

Hi eComLabs,

Is there any way to reverse Parent category order like Des without change order of sub categories using below hook ?

It is better to use the get_categories_post hook for this task

Hi eComLabs,

Thanks for this.

It is better to use the get_categories_post hook for this task

Can you please give some more details about this ? because I am developing this first time.

Thanks.

Hi eComLabs,

Thanks for this.

Can you please give some more details about this ? because I am developing this first time.

Thanks.

1. Create the ini.php file in app/addons/my_changes/ and declare hook in it:

fn_register_hooks(
   'get_categories_post'
);

2. Create the func.php file in app/addons/my_changes/ and add the following function:

fn_my_changes_get_categories_post($categories_list, $params, $lang_code)

In this function you can make the modification you want.

You can find more details in this documentation.

Note that if you want to change the $categories_list array, use

fn_my_changes_get_categories_post(&$categories_list, $params, $lang_code)

instead of

fn_my_changes_get_categories_post($categories_list, $params, $lang_code)

Thanks Simtech for reply.

I had checked $categories_list but there is no option for name based sorting because no name available for category in array.

1. Create the ini.php file in app/addons/my_changes/ and declare hook in it:

fn_register_hooks(
   'get_categories_post'
);

2. Create the func.php file in app/addons/my_changes/ and add the following function:

fn_my_changes_get_categories_post($categories_list, $params, $lang_code)

In this function you can make the modification you want.

You can find more details in this documentation.

Thanks Simtech for reply.

I had checked $categories_list but there is no option for name based sorting because no name available for category in array.

What do you see if you print the content of the array?

fn_print_r($categories_list);

What do you see if you print the content of the array?

fn_print_r($categories_list);

Hi eComLabs,

When i print the array i got following content:
It is not full array code.sorry.

Array
(
    [1] => Array
        (
            [category_id] => 1
            [parent_id] => 0
            [id_path] => 1
            [category] => one
            [position] => 10
            [status] => A
            [company_id] => 1
            [level] => 0
            [has_children] => 4
            [subcategories] => Array
                (
                    [0] => Array
                        (
                            [category_id] => 4
                            [parent_id] => 1
                            [id_path] => 1/4
                            [category] => one-c
                            [position] => 40
                            [status] => A
                            [company_id] => 1
                            [level] => 1
                        )
            )

    )

[2] => Array
    (
        [category_id] => 2
        [parent_id] => 0
        [id_path] => 2
        [category] => two
        [position] => 20
        [status] => A
        [company_id] => 1
        [level] => 0
        [has_children] => 5
        [subcategories] => Array

Hi eComLabs,

When i print the array i got following content:
It is not full array code.sorry.

As you can see, category names exist in the array. Just find a way to sort array by these values

As you can see, category names exist in the array. Just find a way to sort array by these values

Thanks eComLabs.

Hi there,

Not sure if this is the proper topic but do I have any hooks for the fn_init_language ?. Looking to intercept the part where the CS-Cart sets the default language based on browser settings.

Looking forward for an answer.

There are no hooks for the fn_init_language() function. However, you might be able to set a REQUEST varaible in an init.pre.php controller to force the language or to apply different logic for determining language. I.e.

$_REQUEST['sl'] = 'en';

Should force the language to be English (en) regardless of what the browser comes up with.

I am afraid, it will not work since fn_init_language is called before any controller

But it can redirect if CART_LANGUAGE is not what you want. It would then stick for future pages.