Jump to content

How to use Hook addWebserviceResources?


Recommended Posts

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

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

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

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'));
    }
  • Like 1

Share this post


Link to post
Share on other sites

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 by frojha (see edit history)
  • Like 2
  • Thanks 2

Share this post


Link to post
Share on other sites
  • 2 years later...
  • 5 months later...
  • 1 month later...
  • 3 months later...

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

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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More