byronpk Posted March 15, 2016 Share Posted March 15, 2016 (edited) Hi Everyone Quick question. According to the hook documentation (http://doc.prestashop.com/display/PS15/Hooks+in+PrestaShop+1.5), the hook named "actionOrderStatusPostUpdate" is meant to be fired AFTER the order status of an object has already been changed, if I understand correctly? Thus, I assumed since the orderStatus has already been changed I could safely change it again in my code without any issues. My code contains a conditional block that scans the products in the order the moment it goes to the "Payment Received" status, and if the order contains any "restricted items" it would notify the user and change the order status to "Restricted: <reason>" (ID: 15). When I run the code and the hook fires, I end having the status set and then immediately replaced with "Payment Received". https://www.dropbox.com/s/uc4ebr2ybytx2ks/Screenshot%202016-03-15%2012.52.47.jpg Is this normal behaviour for the POST update hook? Since the status is supposed to ALREADY BE CHANGED, why would it change it anyway? ... } else { // Restricted order... $order->setCurrentState(15, 1); ... Is there another way to do this that I can ensure it changes correctly? Edited March 15, 2016 by byronpk (see edit history) Link to comment Share on other sites More sharing options...
lumedevikeira Posted May 11, 2016 Share Posted May 11, 2016 Did you solve the problem?? I have tried some hooks like actionOrderStatusPostUpdate and It didn't run ok. Hi Everyone Quick question. According to the hook documentation (http://doc.prestashop.com/display/PS15/Hooks+in+PrestaShop+1.5), the hook named "actionOrderStatusPostUpdate" is meant to be fired AFTER the order status of an object has already been changed, if I understand correctly? Thus, I assumed since the orderStatus has already been changed I could safely change it again in my code without any issues. My code contains a conditional block that scans the products in the order the moment it goes to the "Payment Received" status, and if the order contains any "restricted items" it would notify the user and change the order status to "Restricted: <reason>" (ID: 15). When I run the code and the hook fires, I end having the status set and then immediately replaced with "Payment Received". https://www.dropbox.com/s/uc4ebr2ybytx2ks/Screenshot%202016-03-15%2012.52.47.jpg Is this normal behaviour for the POST update hook? Since the status is supposed to ALREADY BE CHANGED, why would it change it anyway? ... } else { // Restricted order... $order->setCurrentState(15, 1); ... Is there another way to do this that I can ensure it changes correctly? Link to comment Share on other sites More sharing options...
byronpk Posted May 11, 2016 Author Share Posted May 11, 2016 Did you solve the problem?? I have tried some hooks like actionOrderStatusPostUpdate and It didn't run ok. Hi lumedevikeira I have not unfortunely. We eventually used a totally different approach to the problem, and some smart DB hacks. I don't feel it's a "solution" since it's not recommended or good. Link to comment Share on other sites More sharing options...
PrestaMake Posted April 3, 2019 Share Posted April 3, 2019 2019 and still this problem persists. Anybody figured how to solve this? Link to comment Share on other sites More sharing options...
byronpk Posted April 3, 2019 Author Share Posted April 3, 2019 (edited) 10 hours ago, Daniuz said: 2019 and still this problem persists. Anybody figured how to solve this? This is why I don't bother with the forums anymore, either people just don't know that answer, they never reply or the answers are irrelavant and don't work. To this day I'm still having to solve my own problems because the forums are mostly useless 😕 Regardless, I'd post the entire module file that I used to get around this problem if I still had access to it, I had finished/given up on that project 3 years ago and I've moved on to bigger and far more frustrating problems Edited April 3, 2019 by byronpk Adding more details. (see edit history) Link to comment Share on other sites More sharing options...
PrestaMake Posted April 3, 2019 Share Posted April 3, 2019 14 minutes ago, byronpk said: This is why I don't bother with the forums anymore, either people just don't know that answer, they never reply or the answers are irrelavant and don't work. To this day I'm still having to solve my own problems because the forums are mostly useless 😕 Regardless, I'd post the entire module file that I used to get around this problem if I still had access to it, I had finished/given up on that project 3 years ago and I've moved on to bigger and far more frustrating problems There are some cools guys in the forum which helps for free, and if its needed they quote you for the help. It actually seems more as a Prestashop bug that was never fixed rather than community not helping How come you can not modify an status when certain status is set? Thats a shame xD I guess I am gonna need to do Database way which is not recommended. Thanks for replying too my friend 1 Link to comment Share on other sites More sharing options...
byronpk Posted April 3, 2019 Author Share Posted April 3, 2019 12 minutes ago, Daniuz said: There are some cools guys in the forum which helps for free, and if its needed they quote you for the help. It actually seems more as a Prestashop bug that was never fixed rather than community not helping How come you can not modify an status when certain status is set? Thats a shame xD I guess I am gonna need to do Database way which is not recommended. Thanks for replying too my friend Perhaps, but I dug through my old development work backups and found the module I wrote, I used two hooks to solve my problem. Sadly the code is copyrighted to the company I used to work for, but I can share small snippits without triggering any red flags: The hook OrderHistoryAddAfter I believe fires after an update occurs in the OrderHistory. So I intercepted that call and updated the order status it just wrote directly in the database: /** * hookActionOrderHistoryAddAfter * Hooks into actionOrderHistoryAddAfter updating the Order History table with new Order status * * @param resource $params OrderHistory object */ public function hookActionOrderHistoryAddAfter($params) { if($this->orderState !== 2) { $history = $params['order_history']; $history->changeIdOrderState($this->orderState, (int)$history->id_order); if(isset($this->orderState)) { $sql = 'UPDATE '._DB_PREFIX_.'order_history SET id_order_state = '. $this->orderState.' WHERE id_order_history ="'. $history->id .'";'; if (!Db::getInstance()->execute($sql)) { die("ERROR"); } } } } The other hook I used was OrderStatusPostUpdateHook instead of OrderStatusUpdate /** * Hooks into the PrestaShop onOrderStatusUpdateHook * * @link http://doc.prestashop.com/display/PS15/Hooks+in+PrestaShop+1.5 Hook reference on PrestaShop dev site * @param mixed $params Input parameters from the PrestaShop hook system */ public function hookActionOrderStatusPostUpdate($params) { // Thread variables $id_thread = 0; $thread_email = null; $order_message = ''; // Grab the debug status from the database // Get the FishBowl configuration from the database $sql = "SELECT `debug` FROM ". _DB_PREFIX_."fishbowl_config WHERE `id_fishbowl_config` = 1;"; if ($app_data = Db::getInstance()->ExecuteS($sql)) { $this->debug = strval($app_data[0]['debug']); } // Right, here goes all the code you need to get the basic details about an order // Basic detail variables, defining the order, it's current state, etc, etc. $id_lang = Configuration::get('PS_LANG_DEFAULT'); $order_state = $params['newOrderStatus']; $order_id = $params['id_order']; $order = new Order((int)$order_id); ... So, it basically fires AFTER the order status was updated by the purchase, (which was too late for me), but the other hook would trigger the moment the entry was made into the history and I'd latch onto that and change the order status in the DB after the call was completed, essentially cheating the system Hope this helps you find a solution that works for you friend 1 Link to comment Share on other sites More sharing options...
PrestaMake Posted April 3, 2019 Share Posted April 3, 2019 (edited) 8 minutes ago, byronpk said: So, it basically fires AFTER the order status was updated by the purchase, (which was too late for me), but the other hook would trigger the moment the entry was made into the history and I'd latch onto that and change the order status in the DB after the call was completed, essentially cheating the system Hope this helps you find a solution that works for you friend Thank you mate! I will try to check it out more deeply later. As for now I tried to use the following hook public function hookActionOrderHistoryAddAfter($params) { echo "hello"; } and it seems that is not properly working at PS 1.7.4 as it does not do anything (and I can not hook my module to ActionOrderHistoryAddAfter, dont know why) Edited April 3, 2019 by Daniuz (see edit history) Link to comment Share on other sites More sharing options...
byronpk Posted April 3, 2019 Author Share Posted April 3, 2019 2 hours ago, Daniuz said: Thank you mate! I will try to check it out more deeply later. As for now I tried to use the following hook public function hookActionOrderHistoryAddAfter($params) { echo "hello"; } and it seems that is not properly working at PS 1.7.4 as it does not do anything (and I can not hook my module to ActionOrderHistoryAddAfter, dont know why) Darn it, that's a shame still this was for PS 1.6, so I don't know if it would work as it on PS 1.7, you did declare the hooks in the install() section and reinstall your module right? /** * Install the PrestaShop Module * * @return boolean Success or Fail */ public function install() { if (!parent::install() || !$this->registerHook('actionOrderStatusPostUpdate') || !$this->registerHook('actionOrderHistoryAddAfter') ) { return false; } return true; } 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