Nirmal Posted December 13, 2013 Share Posted December 13, 2013 (edited) 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 December 13, 2013 by Nirmal (see edit history) Link to comment Share on other sites More sharing options...
CartExpert.net Posted December 13, 2013 Share Posted December 13, 2013 Hi. You don't need to create a new class, simply put your overriden function in 'overried/classes/Tools.php' Regards.Robin.The CartExpert Team Link to comment Share on other sites More sharing options...
steinsgate Posted December 13, 2013 Share Posted December 13, 2013 (edited) @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 classIn 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 December 13, 2013 by steinsgate (see edit history) Link to comment Share on other sites More sharing options...
CartExpert.net Posted December 13, 2013 Share Posted December 13, 2013 @steinsgate Yes, should have the same number of arguments, otherwise if Strict mode is on it will give warnings. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now