Jump to content

override a php file in the child theme


daniele dexter

Recommended Posts

Hello to all.

I am trying to override a php file.

I would like to insert a file within the created child theme.

I contacted the theme developer (AKIRA) and he tells me that it is not possible to override a php file through the child theme.

I wouldn't want to lose my changes inside the php file in case of a theme update.

 

Can you give me some advice?

Thanks

Link to comment
Share on other sites

31 minutes ago, Inform-All said:

Please give us an example of the file you would like to override.
Because indeed, you are not able to override all the files. 

My file is located inside the "modules" folder: public_html \ modules \ nrtmegamenu \ NrtMegaBrandClass.php

The php file is used to display the brands in the mega menu.

Inside I added a sort for the display in alphabetical order.

In the child theme I have already overridden some tpl files to show, for example, some labels with logic for discounts and I saw that they actually overwrote those of the main theme. My goal is to do something similar.

 

Here is an image of the section

 

example.jpg

Link to comment
Share on other sites

You can actually override this file, but do keep in mind that you need to check if everything is still correct upon every Prestashop or module update.
The override is not on a theme / template file that's why it's not located on the position you tried.


You override should be as the following: 

/override/modules/nrtmegamenu/NrtMegaBrandClass.php

Please read the corresponding docs here: https://devdocs.prestashop.com/1.7/modules/concepts/overrides/#override-a-module

Link to comment
Share on other sites

22 hours ago, Inform-All said:

You can actually override this file, but do keep in mind that you need to check if everything is still correct upon every Prestashop or module update.
The override is not on a theme / template file that's why it's not located on the position you tried.


You override should be as the following: 

/override/modules/nrtmegamenu/NrtMegaBrandClass.php

Please read the corresponding docs here: https://devdocs.prestashop.com/1.7/modules/concepts/overrides/#override-a-module

I did as directed in the guide, but it doesn't seem to have any effect.

I put the file in the path, added the class extension and cleaned the cache.

Is there something I did wrong?

I am attaching an image of the route.

Here how I extended the class: class NrtMegaBrandClassOverride extends NrtMegaBrandClass

percorso.JPG

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

On 12/9/2021 at 3:21 PM, Krystian Podemski said:

It's impossible to override files other than the main module file or module controllers. Unfortunately, if the PHP file renders this part of the template, it would be easier to edit it directly.

 

How will be this, if they create a hook and put their custom hook in child theme and put the custom php file in custom module. In my thought it is easier.

 

Thank you

Link to comment
Share on other sites

On 12/9/2021 at 8:37 AM, daniele dexter said:

I did as directed in the guide, but it doesn't seem to have any effect.

I put the file in the path, added the class extension and cleaned the cache.

Is there something I did wrong?

Have you regenerated class_index.php?

If you've added a new override class you'll need to delete the old class index, which can be found in:

/var/cache/prod/class_index.php

and

/var/cache/dev/class_index.php

A new one will be regenerated automatically.

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