frojha 5 Posted October 4, 2017 Posted October 4, 2017 Hello, is there a code example available of the hook addWebserviceResources? I want to add a custom webservice resource, but all tutorials are outdated and are based on class override (which isn't possible in PrestaShop 1.7). Best regards Share this post Link to post Share on other sites
frojha 5 Posted October 4, 2017 Posted October 4, 2017 Trying this ends in an semi white page: public function hookAddWebserviceResources($extra_resources) { $extra_resources['resources']['mypageresource'] = array('description' => 'Manage My Pages', 'class' => 'CMS'); return $extra_resources; } Share this post Link to post Share on other sites
razaro 577 Posted October 4, 2017 Posted October 4, 2017 Hi Not sure how that hook works, but check few things first. Try to enable debug mode and see why you get white page. Also CMS is already available in web service 'content_management_system' => array('description' => 'Content management system', 'class' => 'CMS'), classes/webservice/WebserviceRequest.php line 302. Share this post Link to post Share on other sites
frojha 5 Posted October 4, 2017 Posted October 4, 2017 After inserting some "debug" output in WebserviceRequest.php it seems this is the correct syntax: public function hookAddWebserviceResources() { return array('mypageresource' => array('description' => 'Manage My Pages', 'class' => 'CMS')); } 1 Share this post Link to post Share on other sites
razaro 577 Posted October 4, 2017 Posted October 4, 2017 Thanks for sharing. But to ask, you can use custom class, one form module maybe instead CMS ? Share this post Link to post Share on other sites
frojha 5 Posted October 4, 2017 Posted October 4, 2017 (edited) Of course it was just a test. Finally I do something like this: require_once(_PS_MODULE_DIR_.'mymodule/classes/customClass.php'); require_once(_PS_MODULE_DIR_.'mymodule/classes/extraClass.php'); class MyModule extends Module { public function __construct() { // Basic module stuff here... } public function install() { return parent::install() && $this->registerHook('addWebserviceResources'); } public function hookAddWebserviceResources() { return array( 'custom' => array( 'description' => 'My Custom Resource', 'class' => 'custom' ), 'extra' => array( 'description' => 'My Extra Resource', 'class' => 'extra' ) ); } } mymodule/classes/customClass.php looks like: class custom extends CMS { // extend or adjust CMS stuff here } Edited October 4, 2017 by frojha (see edit history) 2 2 Share this post Link to post Share on other sites
razaro 577 Posted October 4, 2017 Posted October 4, 2017 That is great share, thank you. Hope other people will find your post as it is really useful. Share this post Link to post Share on other sites
frojha 5 Posted October 10, 2017 Posted October 10, 2017 (edited) Does someone know why are the columns class_name, is_module and module_name in the table webservice_account? Can use them somehow with core functions? Edited October 10, 2017 by frojha (see edit history) Share this post Link to post Share on other sites
Digital Human 3 Posted March 6, 2020 Posted March 6, 2020 @frojha ok, and how do make the actual API call now? Share this post Link to post Share on other sites
Jluis 1 Posted August 25, 2020 Posted August 25, 2020 @frojha , how to make a call to a function in the "custom" class ? Share this post Link to post Share on other sites
SIWA_Fabian 0 Posted October 8, 2020 Posted October 8, 2020 Hello guys! So far this thread is the only thing i found regarding the API-Hook. Is there any documentation about this hook? I need to create a very specific JSON-Output when the API is called. Share this post Link to post Share on other sites
MikeCodes 3 Posted January 11 Posted January 11 i think it's easier to write your own api instead of using that prestashop thing..... 1 Share this post Link to post Share on other sites
SIWA_Fabian 0 Posted January 11 Posted January 11 I found out how it works by now and actually its quite easy. As always the docs are kind of missing, but I'll explain it here as soon as i got time. Stay tuned Share this post Link to post Share on other sites
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