Zen Cart Logo
Forums / Code Collaboration / Plugin mod approaches

Plugin mod approaches

Views: 4,091

Results 1 to 3 of 3
20 Feb 2018, 21:22
#1
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Plugin mod approaches

I'm making some modifications to a plugin and would like to minimize changes to the plugin by keeping the majority of my changes elsewhere. Currently, I'm adding code to a function (method) within a class. I've put my code in a file and call it through a require statement. Where is the recommended location for the file? It's not technically a function, since it's only part of a function. Should it nevertheless be put in extra_functions? Or somewhere else?

Another approach might be to create a notifier-observer, but no notifiers exist in this method. What is involved with adding custom notifiers in the desired places, and locate the plugin mods in observers? Would calling a notifier class within another class method work? (Still uncomfortable with OOP and it's jargon, but learning!).

What is best practice in this case?

Thanks for any advice.

21 Feb 2018, 02:34
#3
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Plugin mod approaches

So you've got a couple of things going on here. Good that looking into it.

First of all a function IS a function, but in this case it appears that the intent is to either override a class' method (function) or to modify an existing function (by way of a notifier). Which way this is done is open to debate and in part depends on how much of a change is being done as compared to the base code, what it would take to maintain it and anticipated changes in the future. Ideally, the plugin could be updated to include the notifier(s) to be added (suggest speaking with original author before just making the change.)

As to if a notifier is used, if the parent class extends base, then could add a notifier like: $this->notify('NOTIFIER_NAME_FOR_THIS_NOTIFIER', array(), $param1, $param2, etc...); though some of this format also depends on the proposed ZC version compatibility to consider. And yes a notifier can exist inside of some other function, code, or other area provided that the notifier system has been loaded at a point prior to where/when the code is loaded.

As far as some form of abstraction to override the existing function, well generally would think knowing more about the conditions would help to further advise.

As far where all this gets stored, well edging on class related code and or init_includes related. It pretty much depends on structure and usage.