Jump to content

Override the Tools class


Nirmal

Recommended Posts

i like to overload the Tools class , which works fine for me but when i am trying to validate the module through module validator of prestashop, it showing error,

 

class MyTools extends Tools {

 

public static function jsonEncode($data, $default = 'JSON_NUMERIC_CHECK')

    {

        if (function_exists('json_encode'))

            return json_encode($data, $default);

        else

        {

            include_once(_PS_TOOL_DIR_.'json/json.php');

            $pear_json = new Services_JSON();

            return $pear_json->encode($data);

        }

    }

 

}

 The module uses forbidden functions/methods.

json_encode() should be replaced with Tools::jsonEncode()

I am just overload the method by just adding $default = JSON_NUMERIC_CHECK.

 

i am using prestashop 1.5 (version)

 
Edited by Nirmal (see edit history)
Link to comment
Share on other sites

@CartExpert.net Can you do that from a module ?

 

I think that if Prestashop its forcing to use Tools::json_encode, at least, it should support the same arguments than the native function. A second parameter (optional) should be available.

 

@Nirmal

If you cannot do that from the module, will be difficult to validate it against the Prestashop Validator.

 

Probably there is some information about that in the docs.

 

edit

 

I found this: http://doc.prestashop.com/display/PS15/Overriding+default+behaviors

 
Overriding a class

In order to override the Product class, your file needs to be called Product.php and must feature a Product class that then extends ProductCore class.

The file can be placed in either of these locations:

  • /override/classes/Product.php
  • /modules/my_module/override/classes/Product.php

 

 

 

That should allow overriding Tools::json_encode, and the validator should not complain.

 

Kind regards

Edited by steinsgate (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...