Radu Posted April 28, 2012 Share Posted April 28, 2012 I have a quick concern, what is happening or asked differently what is the best aproach to have 2 modules overriden the same class, let's say product class. Thank you! Link to comment Share on other sites More sharing options...
El Patron Posted April 28, 2012 Share Posted April 28, 2012 What we have done, If an already existing override exists, then we append the change to the existing override. We of course back it up first. But there is no standard (ps compliant) way we could find to address this issue...so we rolled our own. Link to comment Share on other sites More sharing options...
bellini13 Posted April 28, 2012 Share Posted April 28, 2012 assuming you do not try to override the same functions, that should work ok. you would really be better off to fail during the module install, and provide a message to the user as to why it failed. then offer to merge the files together properly. Link to comment Share on other sites More sharing options...
El Patron Posted April 28, 2012 Share Posted April 28, 2012 This for us seems one of the rather larger issues we face today as module developers. assuming you do not try to override the same functions, that should work ok. you would really be better off to fail during the module install, and provide a message to the user as to why it failed. then offer to merge the files together properly. We are for one not terribly comfortable with existing override handling in prestashop. For example: module (1) is installed, Creates a backup of the original override Then either modifies an existing ovrerride or copies in it's override. Module (2) is installed and creates it's own back up and override. Customer then decides to upgrarde or remove Module(1) via uninstall Module (1) doesn't know that it's backup of the override is now out of date, i.e. uninstall will copy it's original backup of the override and replace the product version. Module (2) is now malformed. You can program a lot of stop logic into Module 1, but you have no control over Module 2's logic. if you could use overrides with different names than the parent, most of the install/uninstall problems would be resolved. This doesn't keep one from messing up another modules override but at least makes load/fallback easier. For example: You could then have an override fille named ConfigurationMyModule that: class Configuration extends ConfigurationCore Link to comment Share on other sites More sharing options...
bellini13 Posted April 28, 2012 Share Posted April 28, 2012 I agree with you, it would be good if you could have "Class extend Class" multiple times, I'm just not sure how inheritance works in PHP, and if you can do such a thing. Link to comment Share on other sites More sharing options...
El Patron Posted April 30, 2012 Share Posted April 30, 2012 I agree with you, it would be good if you could have "Class extend Class" multiple times, I'm just not sure how inheritance works in PHP, and if you can do such a thing. This may be of interest: http://www.php.net/manual/en/language.oop5.traits.php Link to comment Share on other sites More sharing options...
Radu Posted November 18, 2012 Author Share Posted November 18, 2012 Thank you for replies, for some reason I wasn't receiving updates of the post, I changed the setting accordingly now. Still not perfect but in presta 1.5 the merging is done automatically if the modules don't override the same method. I guess the hooks especially dynamic hooks are a good solution, for now dynamic hooks are at their beginning. Anyway it really depends on the module but I too don't feel comfortable to override a method especially it's a big chunk of code making it very probable other module will overwrite it. Elpatron, For your modules do you offer an automatically way to merge the overrides? Link to comment Share on other sites More sharing options...
El Patron Posted November 18, 2012 Share Posted November 18, 2012 Thank you for replies, for some reason I wasn't receiving updates of the post, I changed the setting accordingly now. Still not perfect but in presta 1.5 the merging is done automatically if the modules don't override the same method. I guess the hooks especially dynamic hooks are a good solution, for now dynamic hooks are at their beginning. Anyway it really depends on the module but I too don't feel comfortable to override a method especially it's a big chunk of code making it very probable other module will overwrite it. Elpatron, For your modules do you offer an automatically way to merge the overrides? \ I looked at merging...but now I just avoid overrides at all costs. I've rewritten my modules to remove overrides where ever possible. Link to comment Share on other sites More sharing options...
Radu Posted November 18, 2012 Author Share Posted November 18, 2012 Elpatron, thank you for your answer, I was checking the traits but I don't see how it can help, basically traits are same methods shared by multiple classes. for presta we search to override same method by multiple times Still hooks/some similar mechanism to alter function output/return values like "filters" I saw a similar system for shopware ecommerce engine. They had hooks and filters Maybe I don't see all the details... 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