What if my change will require more than just a .tpl file change? My change will mostly involve .php code. Is there a my_changes for actual functionality changes? What would be my approach for creating php changes so that they won’t be overwritten when I do an update?
I am guessing I want a CH – code hook, but then, where exactly do I put this code so it isn’t overwritten when I do an update. For instance, say I want to put a CH inside of the products.php file to hook to my bubbles add-on and then later transfer control back to products.php. Say I put it on line 2500 of the products.php file. How do I know this line won’t be overwritten by some new code from CS-Cart when I do an update later?
So I am trying to follow CS-Cart’s instructions here by following their use of the fn_set_hook function. I am noticing that they seem to be loosely followed. Unless of course, I am not understanding, which is possible.
At the bottom of the fn_update_product function inside of /www/controllers/admin/products.php you see the line:
“Knowing the hook name, any addon can intercept execution of the program code, perform necessary manipulations and then return the execution process to the Main program (MP). When calling a certain hook, all variables directly defined in this hook become available for the addon.
Call of the hook within the addon is carried out by defining the function which name consists of the prefix “fn_”, addon name, underscore and the full name of the called hook.”[/quote]
From this, I guess I am looking for something like fn_xxx_update_product() in the /www/addons/ directory right?? How do I know which one it is? When I do a search I see
also if it matters
How am I, or cs-cart supposed to know which of these functions are being called by the code hook?
[quote name=‘brandonvd’]Are you trying to make your own hooks or use the ones already built into CS-Cart? I’ve only ever used the built in ones so I couldn’t really help you with making new ones.
If you are trying to use the built in ones than you are seriously overcomplicating things.[/QUOTE]
Brandon, thanks for your reply.
I am trying to make a CH – Code Hook, not a TH – Template Hook. It seems a TH is what you are describing … please correct me if I am wrong…It also seems that Template Hooks are all that most people on the forums have needed to complete any add-ons. But alas, I do not need to modify any of the front end layout, or any .tpl file, or any other presentation layer files.
I need to modify the way CS-Cart actually works with the data. I need to modify the php execution. To put it simply, I need to intercept (or hook) the (MP) – Main Program code and then do some changeroos to the data, and then return the control to the MP. Basically, when a product is added from the admin back end, I have a bunch of PHP code that has to be run on the data the user puts in before it is eventually inserted into the database.
I have already written the various functions to accomplish what I need, and I put the code in the products.php file in the /controllers/ directory. However, I am not interested in accomplishing my task like this because eventually I will want to update my cs-cart site to 2.0.10 and then other updates after that. So I was hoping I could use what CS-Cart calls CH – code hooks, not TH – template hooks because according to CS-Cart, these CH won’t get overwritten by and update of the cart. I hope this makes sense, but yeah… hoping someone has done something like this…
Ok, thanks again Brandon, you’ve definitely been a help in getting me here. Must respect.
Anyone else wanna chime in? … Jobosales… Sno… I know you guys are out there! Haha, just kidding. I hope you guys can help, I’m on the verge of making my idea a legit add-on I think. Just need this lil’ bit of info so I can move forward.
As you can see there are three files called up from my common templates folder. Originally I just put these in my skins/basic/customer/common_templates folder, but since there are quite a few files in that folder it was hard for me to find them if I wanted to make changes so I made this new folder.
Like I said, it is basically about organization and doing what makes it easiest for me to find and edit my files.
maybe I’m missing the point, but where can I find a list of what functions are available to pass to fn_register_hooks? As I understand it, fn_register_hooks takes a list of pre-defined internal functions in cs-cart and passes control to my addon. If that’s true, I need a list of those functions and the parameters they take, but I can’t seem to find it.
[quote name=‘frednurk’]maybe I’m missing the point, but where can I find a list of what functions are available to pass to fn_register_hooks? As I understand it, fn_register_hooks takes a list of pre-defined internal functions in cs-cart and passes control to my addon. If that’s true, I need a list of those functions and the parameters they take, but I can’t seem to find it.[/QUOTE]
thanks, but I’ve already read that, and the relevant part seems to be:
[QUOTE]Knowing the hook name, any addon can intercept execution of the program code, perform necessary manipulations and then return the execution process to the Main program (MP). When calling a certain hook, all variables directly defined in this hook become available for the addon.[/QUOTE]
The problem is, I don’t know the hook names, or where I can find them and the parameters they take.
Of course, I could be totally misunderstanding this, but I’ve read the docs 5 times and I can’t figure it out.
Ok, maybe I am now misunderstanding what you are trying to do. Let me explain what I understand about fn_register_hooks
I think you can pass any function with any parameters to it because it essentially generates a breakpoint in the code and then allows whatever function with however many parameters that you specific to be generated as well. And that function can be used at that time for purposes of “intercepting” what is going on.
So basically you register some function that you have already written through fn_register_hooks and then later, you will know the function because you already set it, so you can call it when the fn_set_hook is called.
I can’t be exactly sure of all of thise, because a while back I was really digging into this and got sidetracked with the new updates and new features, and I have become a little obsessive about learning about how the Database works. But I assume one day I will get back to this.
I don’t think that’s true. I’m trying to learn the ropes by making an addon called ‘category_news’ that can attach a single news item to a category. I call fn_register_hooks(‘update_category’) and it gets called when a category is updated. My called function is then named ‘fn_category_news_update_category’ as per the limited documentation.
It seems that the function “update_category” has to exist somewhere in the cscart core, or I can’t hook into it. To figure out the args for this, I looked in the core source code, and I found where fn_update_category was defined and what args it took. That seems like a very hard way to find out the list of possible hooks and args. If what I’m saying is true, it is necessary to have a list of all the possible hooks, but there is no such list.
If I was just defining random code hooks and then calling them, it wouldn’t work, because the whole point of ‘hooks’ in general in any api is to allow one to hook into certain actions that have already been built. If I don’t have a list of the actions that can happen in cs-cart, how do I build that list?
I inserted some code into the core that outputs all the hook functions that addons ask to be attached to, and here is the list. Is it complete? What are the args for those functions? What am I missing?
I am a little behind you still on this… Let me ask you two questions.
This may sound odd to you, because you are farther ahead than me, but how would you know any function’s args without looking for where it is defined in the code?
I think I am understanding where you are coming from a little. So you are saying you want to stop the execution of the fn_update_category function and you need to know what args/parameters are passed to this function.
I am quite interested in this now, so I did a search of the core directory and foudn what you found, two instances of ‘update_category’ , both located in fn.catalog.php.
function fn_update_category($category_data, $category_id = 0, $lang_code = CART_LANGUAGE)
and a little later inside the actual fn_update_category function…
you’ve hit on the problem precisely! How would I know the functions args without looking in the code? How do I even know the function exists? If this is indeed how the addon system works, where is the documentation?
Either I’m completely misunderstanding this process or the documentation is completely useless. I’m totally fine if it’s me being an idiot, but I’m pretty confused.
I’ve written a number of smarty-like template languages, and I’ve built a few APIs and used a few more that I haven’t written, and this ‘hook’ thing is a pretty common concept. In order for it to work, you need to have a list of places in the code that you can hook into though. Where’s that list? The documentation for developers seems awfully skimpy.