Jump to content

Overriding Same Class By Multiple Modules


Recommended Posts

Hello

 

I need to find best solution for following problem:

 

I want to add custom fields to existing table in database instead of creating custom table. Reason is simple, I need to get those values by my side through api. To get this work I made override in desired class:

 

class Carrier extends CarrierCore {

	public $field_1;

	public function __construct($id = null, $id_lang = null) {

		self::$definition['fields']['field_1'] = array('type' => self::TYPE_BOOL, 'validate' => 'isBool');

		parent::__construct($id, $id_lang);
	}

}

Everything is fine, but I need this solution to be independed from another modules, any modules. What I've tested is that another module wouldn't be able to override constructor or if constructor is alerady overrided I won't be able to install my module. How to acheive it? Ofcourse I can create custom table, but to be able to get its values through API by my side I will have to modify API and override getResources mtehod from WebserviceRequest class and what about if it will be alerady overrided?. How can I solve this problem without any overrides or any other solutions? I only need that my module won't collide with any other modules and its installation will be safe.

 

Regards

Edited by mdomski (see edit history)
Link to comment
Share on other sites

You cannot override it again, of course. What you can do is using custom methods from within the modules themselves. Prestashop would load the modules altogether, so that's why they can't overlap. If you want you override to be used only at a module's run time, then use a custom method instead :)

Link to comment
Share on other sites

Yeah I know it's not possible to override the same method multiple times. Using custom methods from other modules is not my point, because I don't need them : ), I just don't want to collide with them while gaining desired funcionality. There should be option to add fields to stock tables (without overrides) and let them to be visible in API or to add own table (like it's possible now) and simply add it to API resources (again without overrides). Maybe I'm missing something?

 

In sum, I'm looking for the best and safe way (not colliding with other modules / no overrides) to add field to stock table (for eg. orders) and get it through API by my side. Another solution would be to create my own table and let it to be visible in API, but as far as I know adding resource to API still needs overrides right?

 

Regards

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