Jump to content

Is there a way to use core controllers in modules without using the override?


tech2js

Recommended Posts

I want to override one core controller, but instead of changing in override folder, I want to provide my new version of the controller directly from the module. In this way, the  core files will not be affect when upgrading.. can this be done?

I have tried a couple of times, but it gives me 404 error when requiring the file.

 

Any suggestions? Has anyone done this with prestashop.. i did this countless of times in wordpress and it works like a charm.. but no luck with prestashop so far.. i am using v. 1.6

Link to comment
Share on other sites

thank you for your fast reply..

What do you mean by this " hook actionDispatcher".. how might I do that sir?

do i need to create a function like this? public function hookActionDispatcher(){} ??

please clarify for me.. sorry for not catching what you meant. thakns

 

for example: if I have a file in modules/my_module/Product.php  that is a copy of Product.php.. how do i implement what you mentioned above?

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

1 hour ago, tech2js said:

I want to override one core controller, but instead of changing in override folder, I want to provide my new version of the controller directly from the module. In this way, the  core files will not be affect when upgrading.. can this be done?

I have tried a couple of times, but it gives me 404 error when requiring the file.

 

Any suggestions? Has anyone done this with prestashop.. i did this countless of times in wordpress and it works like a charm.. but no luck with prestashop so far.. i am using v. 1.6

 

This is not a good practice. And in an upgrade, overrided files are not modified. I don't know what you mean with "In this way, the  core files will not be affect when upgrading".

Link to comment
Share on other sites

2 minutes ago, joseantgv said:

 

This is not a good practice. And in an upgrade, overrided files are not modified. I don't know what you mean with "In this way, the  core files will not be affect when upgrading".

well, you might be right with the override.. I am looking for a way to use core functions/classes without the use of overrides.. instead, use modules without the overrides.. so, you are saying that it can be done, but just not a good practice?

Link to comment
Share on other sites

9 minutes ago, joseantgv said:

 

This is not a good practice. And in an upgrade, overrided files are not modified. I don't know what you mean with "In this way, the  core files will not be affect when upgrading".

I am still learning prestashop.. and I wanted to see how things are being done and what are the things that are considered good practices as a developer.. in this particular instance, the reuse of classes and controller files in modules without the override.. can you show how it is done, and why it is a bad practice? Thanks a ton!

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

26 minutes ago, tech2js said:

well, you might be right with the override.. I am looking for a way to use core functions/classes without the use of overrides.. instead, use modules without the overrides.. so, you are saying that it can be done, but just not a good practice?

 

The correct way to do what you need is with overrides. Probably there are other options like @tdsoft answer, but I can't see the point of do that.

Link to comment
Share on other sites

1 hour ago, joseantgv said:

 

The correct way to do what you need is with overrides. Probably there are other options like @tdsoft answer, but I can't see the point of do that.

i understand.. thank you.. but you are saying that it can be done.. just not a good practice.. am i correct?

Link to comment
Share on other sites

3 minutes ago, joseantgv said:

 

I've never done and never seen anything different than an override, but as you know, all is possible ;)

got it.. thanks.. what do you think is the downside of doing it instead of the override? If i choose to go that way, will there be negative down the line?

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

1 minute ago, tech2js said:

got it.. thanks.. what do you think is the downside of doing it instead of the override? If i choose to go that way, will there be negative down the line?

 

But you don't have any advantage of doing this way because you will have to do an override anyway in Dispatcher class! Forget about doing strange things and use PS recommendations as long as you can ;)

Link to comment
Share on other sites

1 minute ago, joseantgv said:

 

But you don't have any advantage of doing this way because you will have to do an override anyway in Dispatcher class! Forget about doing strange things and use PS recommendations as long as you can ;)

Oh!! so, even if it can be done.. I will still have to user override on Dispatcher class.. i see.. so, there is really no advantage to not using overrides.. thank you for your time and sharing your knowledge is a big help.

Link to comment
Share on other sites

Just now, tech2js said:

Oh!! so, even if it can be done.. I will still have to user override on Dispatcher class.. i see.. so, there is really no advantage to not using overrides.. thank you for your time and sharing your knowledge is a big help.

 

Because you have to say to PS that instead of executing Core class, execute yours, so you should use an override anyway... 

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