chrisdac Posted April 16, 2013 Share Posted April 16, 2013 Hi, We're working on a new module, but when implementing its hooks we can't figure out what each hook's $params argument actually contains. For example, we want to do some additional processing after creating of a new order, which involves iterating through that order's details and posting some of that info to an external API. We're using the actionValidateOrder hook to do this, as follows: public function hookActionValidateOrder($params) { ...some code in here } In this case, what does the $params object contain? Does it contain the same object in every hook, or is it different for each hook? Without knowing the contents, it's very hard to figure out how to access the order data. We've tried searching through the documentation and forums for this but no luck so far - any help very much appreciated. Thanks Link to comment Share on other sites More sharing options...
PascalVG Posted April 17, 2013 Share Posted April 17, 2013 (edited) Saech your code for strings like $params = Here you find the definition (mostly something boring like $params = array(); But a little below that, many times the array will be filled, like : $params['total_to_pay'] = $cart->getOrderTotal(); $params['currency'] = $currency->sign; $params['objOrder'] = $order; $params['currencyObj'] = $currency; etc. also, you can try to search for: $params[ (this one has many false matches, as sometimes they use the value, instead of assign, but it's a good try. To start with, maybe have a look at the code of /classes/hook.php . my 2 cents, Pascal Edited April 17, 2013 by PascalVG (see edit history) Link to comment Share on other sites More sharing options...
chrisdac Posted April 17, 2013 Author Share Posted April 17, 2013 Thanks Pascal - I appreciate the help. I think this is one area where Prestashop desperately needs some documentation! A simple reference showing the contents of each hook's $params object would save so much time and make the platform much easier to develop for. Thanks again 1 Link to comment Share on other sites More sharing options...
PascalVG Posted April 17, 2013 Share Posted April 17, 2013 Agree, in-file documentation especially is lacking. Just a basic story what the file does, functions offered, etc. would help already enormously ... 1 Link to comment Share on other sites More sharing options...
sadlyblue Posted April 17, 2013 Share Posted April 17, 2013 Thanks Pascal - I appreciate the help. I think this is one area where Prestashop desperately needs some documentation! A simple reference showing the contents of each hook's $params object would save so much time and make the platform much easier to develop for. Thanks again I totally agree. In an action hook we can't do a var_dump. But in other hooks you can var_dump($params) and see everything. That's how i usually do it, even if the page gets weird, and sometimes it shows the params on top of the page. But, yes we need more documentation on that, and other things (like a glossary of functions for quick reference, instead of having to go through the files...). But things are improving... Pedro Link to comment Share on other sites More sharing options...
bellini13 Posted April 17, 2013 Share Posted April 17, 2013 the easiest way is to just search the classes/controller folder and find the hook you are trying to use, which is actionValidateOrder It actually takes the same/less time to just search the code, then it would to search through documentation online. It took all of 5 seconds to find the parameters passed in // Hook validate order Hook::exec('actionValidateOrder', array( 'cart' => $this->context->cart, 'order' => $order, 'customer' => $this->context->customer, 'currency' => $this->context->currency, 'orderStatus' => $order_status )); 2 Link to comment Share on other sites More sharing options...
chrisdac Posted April 17, 2013 Author Share Posted April 17, 2013 I understand what you're saying, but the problem is that the existing documentation doesn't have any information at all, not even a line of text telling us where to start looking for more info. I'm clearly not the only one who has got stuck here, so it's not unreasonable to suggest that a small amount of additional documentation from Prestashop could save hours of searching by people who are trying to use the system. I'd also disagree that it takes less time to search code than it does to search well structured official docs - this is not the way that a lot of people tend to start looking for help, even though it does make sense. Thanks for your reply. 4 Link to comment Share on other sites More sharing options...
tarek.fellah Posted October 28, 2013 Share Posted October 28, 2013 // Hook validate order Hook::exec('actionValidateOrder', array( 'cart' => $this->context->cart, 'order' => $order, 'customer' => $this->context->customer, 'currency' => $this->context->currency, 'orderStatus' => $order_status )); Hi, in which classe/controller you find it? Link to comment Share on other sites More sharing options...
bellini13 Posted October 28, 2013 Share Posted October 28, 2013 perform a search for the word 'actionValidateOrder' and you will find the answer 1 Link to comment Share on other sites More sharing options...
PascalVG Posted October 28, 2013 Share Posted October 28, 2013 Which leads us to classes/PaymentModule.php ... Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 28, 2013 Share Posted October 28, 2013 (edited) Prestashop have a customized php function for die() and print_r(), it became d() and p()Therefore you can easily check and know what variables inside $params objectYou can use d($params) or p($params) and you'll see all variables inside $params objecte.g public function hookWhatever($params) { d($params); } Edited October 28, 2013 by gonebdg - webindoshop.com (see edit history) 2 1 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