daniele dexter Posted December 7, 2021 Share Posted December 7, 2021 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 More sharing options...
Inform-All Posted December 7, 2021 Share Posted December 7, 2021 Please give us an example of the file you would like to override. Because indeed, you are not able to override all the files. Link to comment Share on other sites More sharing options...
daniele dexter Posted December 7, 2021 Author Share Posted December 7, 2021 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 Link to comment Share on other sites More sharing options...
Inform-All Posted December 8, 2021 Share Posted December 8, 2021 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 More sharing options...
daniele dexter Posted December 9, 2021 Author Share Posted December 9, 2021 (edited) 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 Edited December 9, 2021 by daniele dexter (see edit history) Link to comment Share on other sites More sharing options...
Krystian Podemski Posted December 9, 2021 Share Posted December 9, 2021 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. 1 Link to comment Share on other sites More sharing options...
SmartDataSoft Posted December 11, 2021 Share Posted December 11, 2021 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 More sharing options...
lordignus Posted December 13, 2021 Share Posted December 13, 2021 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now