itps Posted September 23, 2013 Share Posted September 23, 2013 I can't figure out how to use action hooks. For example In order process I have to get info which carrier is chosen for shipping and then write some extra stuff in database if client finish order process. How can I do that? Link to comment Share on other sites More sharing options...
El Patron Posted September 23, 2013 Share Posted September 23, 2013 here is the official documentation on hooks http://doc.prestashop.com/display/PS15/Hooks+in+PrestaShop+1.5 you can learn more about hooks by researching existing modules in your shop... Link to comment Share on other sites More sharing options...
itps Posted September 23, 2013 Author Share Posted September 23, 2013 in oficial documentation there is only mentioned that action hooks exists without any usage example... Link to comment Share on other sites More sharing options...
El Patron Posted September 23, 2013 Share Posted September 23, 2013 in oficial documentation there is only mentioned that action hooks exists without any usage example... see how to build module with hook http://doc.prestashop.com/display/PS14/Creating+a+PrestaShop+module#CreatingaPrestaShopmodule-Hookingamodule Link to comment Share on other sites More sharing options...
itps Posted September 23, 2013 Author Share Posted September 23, 2013 this link is for old 1.4 version and also anything about action hooks usage Link to comment Share on other sites More sharing options...
El Patron Posted September 23, 2013 Share Posted September 23, 2013 sorry...you could google this yourself, i.e. prestashop 1.5 doc module here is the module doc and using hooks for 1.5 http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module#CreatingaPrestaShopmodule-Implementinghooks Link to comment Share on other sites More sharing options...
itps Posted September 23, 2013 Author Share Posted September 23, 2013 if i could find something useful with google i would not post this topic in forum I already read all oficial documentation, also about module creation, but there is not anything about action hook usage. Link to comment Share on other sites More sharing options...
El Patron Posted September 23, 2013 Share Posted September 23, 2013 uhm...google search works great for me I think the problem is that the links I sent do not point exactly to what you are researching, though you said you have reviewed all the documenation on module writing it does have a section just for hook processing.. http://screencast.com/t/iv1W1KDH and as I stated earlier on, a good way to learn hooks etc. is to look at modules that come with your ps installation. Link to comment Share on other sites More sharing options...
itps Posted September 23, 2013 Author Share Posted September 23, 2013 Hooks in PrestaShop 1.5 have a new naming scheme, with a situation-specific prefix: action. These hooks are triggered by specific events that take place in PrestaShop. display. These hooks result in something being displayed, either in the front-end or the back-end. Implementing hooks section in documentation show example only about display hooks what I learned already, but I want to change some PS functionality with action hooks and i have no idea with what i have to start. Of course i could look at some other modules, but i need some step by step explanation, because i am newbie at prestashop modules and hooks. 1 Link to comment Share on other sites More sharing options...
El Patron Posted September 23, 2013 Share Posted September 23, 2013 I can not explain it better than the documentaton and/or existing modules. they are very simple to use...start out with the example module..learn from that...then you will be able to ask more specific questions Link to comment Share on other sites More sharing options...
Popular Post Kazeno Posted September 24, 2013 Popular Post Share Posted September 24, 2013 Not trying to upset Mr. Moderator over here, but his answer was pretty useless, so here's one of my own. Action hooks are pretty much used the same way as the other ones, i.e. assuming you're writing a module, you must first register the hook on install() like this: public function install() { //... stuff here $this->registerHook('actionValidateOrder'); //... other stuff here } Then you add another method to your module's class, named after your hook, beginning with the word "hook" and all in camelCase: public function hookActionValidateOrder($params) { //the thing you want to do when the hook's executed goes here } The $params array is populated by the function that executes the hook, so you must find it to know what gets passed to it. In this case it's executed by classes/PaymentModule.php, in the following lines: // Hook validate order Hook::exec('actionValidateOrder', array( 'cart' => $this->context->cart, 'order' => $order, 'customer' => $this->context->customer, 'currency' => $this->context->currency, 'orderStatus' => $order_status )); As you can see, in this case it's passed some objects related to the order. Let's say you want to get the id of the carrier related to the order, then your hook function becomes: public function hookActionValidateOrder($params) { $carrier_id = $params['cart']->id_carrier; //do whatever with the carrier } Hope this makes it clearer. 21 3 Link to comment Share on other sites More sharing options...
franklinfs Posted October 3, 2013 Share Posted October 3, 2013 Hi how can i add a new icon in the orders page in backoffice Link to comment Share on other sites More sharing options...
elgris Posted October 31, 2013 Share Posted October 31, 2013 (edited) Hi Kezeno, Thanks for the very clear explanation, I am writing my own module, and I casually use the actionValidateOrder Hook. I follow your indications, and look other modules code, I even use some code an example because they get the same data that I need, well, i finish mymodule and upload to test it. When I hit the install button I found this error: Incapaz de instalar con control manual : Class PaymentModuleOverride does not exist "Incapable of install with manual control : Class PaymentModuloOverride does not exist" I wonder why? if (!defined('_CAN_LOAD_FILES_')) exit; class txtstock extends Module { public function __construct() { $this->name = 'txtstock'; $this->tab = 'others'; $this->version = '0.1'; $this->author = 'Myself'; $this->need_instance = 0; parent::__construct(); if ($this->id) $this->init(); $this->displayName = $this->l('Venta a un txt'); $this->description = $this->l('Escribe un txt con la última venta.'); $this->confirmUninstall = $this->l('Esta seguro que quiere borrar este modulo?'); } public function install() { $this->registerHook('actionValidateOrder'); if(parent::install() == false) return false; return true; } public function hookActionValidateOrder($params){ } Into the public function there is more code, but I decide to cut it to test it and even without the public function code, I can't install my module. I use PS 1.5.3.1 Thanks in advanced for your help. Best regards Edited October 31, 2013 by elgris (see edit history) Link to comment Share on other sites More sharing options...
elgris Posted November 2, 2013 Share Posted November 2, 2013 Hi, I found the error, was my totally my foult. Thanks. Link to comment Share on other sites More sharing options...
dgsdfsfa Posted January 29, 2016 Share Posted January 29, 2016 Hope this makes it clearer. Thank you so much! It's extremely useful. 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