frojha Posted October 4, 2017 Share 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 Link to comment Share on other sites More sharing options...
frojha Posted October 4, 2017 Author Share 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; } Link to comment Share on other sites More sharing options...
razaro Posted October 4, 2017 Share 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. Link to comment Share on other sites More sharing options...
frojha Posted October 4, 2017 Author Share 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 Link to comment Share on other sites More sharing options...
razaro Posted October 4, 2017 Share Posted October 4, 2017 Thanks for sharing. But to ask, you can use custom class, one form module maybe instead CMS ? Link to comment Share on other sites More sharing options...
frojha Posted October 4, 2017 Author Share 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 Link to comment Share on other sites More sharing options...
razaro Posted October 4, 2017 Share Posted October 4, 2017 That is great share, thank you. Hope other people will find your post as it is really useful. Link to comment Share on other sites More sharing options...
frojha Posted October 10, 2017 Author Share 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) Link to comment Share on other sites More sharing options...
Digital Human Posted March 6, 2020 Share Posted March 6, 2020 @frojha ok, and how do make the actual API call now? Link to comment Share on other sites More sharing options...
Jluis Posted August 25, 2020 Share Posted August 25, 2020 @frojha , how to make a call to a function in the "custom" class ? Link to comment Share on other sites More sharing options...
SIWA_Fabian Posted October 8, 2020 Share 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. Link to comment Share on other sites More sharing options...
MikeCodes Posted January 11, 2021 Share Posted January 11, 2021 i think it's easier to write your own api instead of using that prestashop thing..... 1 Link to comment Share on other sites More sharing options...
SIWA_Fabian Posted January 11, 2021 Share Posted January 11, 2021 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 Link to comment Share on other sites More sharing options...
myownez Posted August 1, 2021 Share Posted August 1, 2021 @SIWA_Fabian - Hi, Did you end up publishing an explanation of how to use the "addWebserviceResources" hook? Thanks! Link to comment Share on other sites More sharing options...
SIWA_Fabian Posted August 2, 2021 Share Posted August 2, 2021 Sry I forgot about that I'll have a look into it if I find the time this week. Link to comment Share on other sites More sharing options...
damian_pm Posted October 22, 2021 Share Posted October 22, 2021 ObjectModel works only with tables from database, for example: namespace PrestaShop\Module\ApiFish\Controller\Api; use ObjectModel; class Custom extends ObjectModel { /** * @see ObjectModel::$definition */ public static $definition = [ 'table' => 'attribute', 'primary' => 'id_attribute', 'multilang' => true, 'fields' => [ 'id_attribute_group' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true], 'color' => ['type' => self::TYPE_STRING, 'validate' => 'isColor'], 'position' => ['type' => self::TYPE_INT, 'validate' => 'isInt'], /* Lang fields */ 'name' => ['type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128], ], ]; } 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