Jump to content

Using overridden class under module for the web service


Pulman

Recommended Posts

Hi,

I'm new Prestashop, I have tried to create a new web service resource and created a new custom module to register the resource, here is the source code:
modules/due/due.php

class Due extends Module
{
    public function __construct()
    {
        // Module information
    }

    public function install()
    {
        return parent::install() && $this->registerHook('addWebserviceResources');
    }

    public function hookAddWebserviceResources($params) {
        return [
            'members' => ['description' => 'The e-shop\'s members', 'class' => 'Member']
        ];
    }

    public function uninstall()
    {
        return parent::uninstall();
    }
}

Now, I create the MemberCore class under modules/due/override/classes/Member.php

class MemberCore extends ObjectModel
{
    /** @var int Member ID */
    public $id;

    /** @var string Lastname */
    public $lastname;

    /** @var string Firstname */
    public $firstname;

    /** @var bool True if carrier has been deleted (staying in database as deleted) */
    public $deleted = 0;

    /** @var string Object creation date */
    public $date_add;

    /** @var string Object last modification date */
    public $date_upd;

    protected $webserviceParameters = [];

    /**
     * @see ObjectModel::$definition
     */
    public static $definition = [
        'table' => 'member',
        'primary' => 'id_member',
        'fields' => [
            'firstname' => ['type' => self::TYPE_STRING],
            'lastname' => ['type' => self::TYPE_STRING],
            'date_add' => ['type' => self::TYPE_DATE],
            'date_upd' => ['type' => self::TYPE_DATE]
        ],
    ];

    /**
     * MemberCore constructor.
     *
     * @param int|null $id
     */
    public function __construct($id = null)
    {
        // It sets default value for member group even when member does not exist
        parent::__construct($id);
    }
}

Then I install the module, but seems the system cannot load the MemberCore class.
However, If I place the MemberCore class under override/classes/Member.php, it works.

Can anyone help to point me what is wrong here.

Thank you!

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