Jump to content

Recommended Posts

Hi everyone. I was wondering if some of my more experienced colleagues from here can shed some light on why a hook like hookActionOrderStatusUpdate($params)  only gets triggered randomly.

I wrote a module to do something on any order status change. It's irrelevant what the module does. For simplicity's sake, let's take this example:

public function hookActionOrderStatusUpdate($params) {

   $this->adminDisplayWarning($this->l('Hook has been triggered'));

}

This alone should be perfectly enough to trigger this message to be displayed *every* time any order's status is changed. But it only triggers the hook sometimes. The module installs correctly, and on install the "hook" is installed correctly, since it does trigger *sometimes*.

Update: THE HOOK DOES GET TRIGGERED every time an order's status changes, but the $this->adminDisplayWarning('....') only gets displayed randomly.

 

I've tried setting all caches to off, force recompilation of templates (this shouldn't even matter, because it's directly a hook into another admin screen, order status updates), nothing seems to matter. The hook sometimes gets triggered, sometimes is doesnt. Is this a mysql/database related issue ? Some bug in Prestashop's hook::exec mechanisms ? 

I am on vers. 1.6.1.17, and the module needs to work on this version, not 1.7.x.

Any ideas ?

I'm looking forward to potential answers. Thank you !

 

Edited by ChewieTheWookie
reformulated for better presenting the case (see edit history)
Link to comment
Share on other sites

this is an action hook, not a display hook.

It is possible that the hook is being called, but if you are simply trying to display output in the browser to verify if the hook is being called is probably not the best solution, as this hook may be called where browser output is not applicable.

Perhaps you should write a debug statement to a log file to truly confirm if the hook is being called.

Also it is quite possible there are other modules registering this hook, and those modules could be interfering if an exception is being thrown, that would likely stop the remaining hooks from being called

Link to comment
Share on other sites

I am aware that this is an action hook. I understand what you say, and how it works. 

The problem is NOT that the hook doesn't get triggered, as I've later found out, the hook does get triggered every time an order gets updated, 

It is definitely - at least in this particular case - being called from a place where display IS allowed, at least in form of error messages or warnings, and as I've stated, *sometimes* they do get displayed.

The problem is, that a simple confirmation message cannot be sent to that controller or that process (the updating of the order), because, the hook itself and the exec hook "capability" of Prestashop doesn't exactly prescribe a clear way to do this.

So... in the meantime, I've played around with 2 more action hooks, actionObjectOrderHistoryAddBefore,  and actionObjectOrderHistoryAddAfter, both of them behave the same way, they are triggered just fine, but the $this->adminDisplayWarning('Hook has been triggered') still doesn't get "transmitted" by the hook back to the order modification screen , *only randomly*.

I've tried forcing php's ob_flush, tried filling the buffer with larger messages, none seems to result in a clear, straight-forward way of being able to display a confirmation message  / warning message of this hook's triggering, on the order status change screen. 

Any thoughts on that ? What is a clear way of displaying a message from this hook, in the order status change screen.

So steps would be... the module registers the hook on install ( actionOrderStatusPostUpdate), and then the function gets triggered whenever an order's status changes. I want that confirmation of this triggering, to be displayed, on the order status change screen.

Thanks again

Link to comment
Share on other sites

The problem is that hook can be called from other places.  While order status can be changed from the back office order details page, it can also be changed in other places, including places that are not triggered from a displayable area.  So you can't rely on using the adminDisplayWarning in that hook

You will need to go through the Order Controller and trace through the code to see if you can locate a suitable place for your warning.  It may or may not be possible to accomplish it entirely through a module.

Link to comment
Share on other sites

  • 2 weeks later...

I figured it out. Unfortunately, your suggestions didn't turn out to be valid, but that's ok, thank you anyway for trying to help me.

The answer is simple, the hook for displaying the error or confirmation, must not be called upon the order changing, but simply on going to the orders list screen. 

So the steps to reproduce this are: when the hook for the order status change is triggered, store a value in the configuration table. Then add a hook to the module that gets triggered on the order list page; if the value is let's say... zero, display the result from two other fields and set the same zero to one. If the value is already one... don't do anything.

I've succesfully finished the module and I hope it will be available on the marketplace if it will be approved. The customer for whom the module was initially created is actually happy with it.

 

Link to comment
Share on other sites

I don't know how to mark the post / question as solved. 

On 12/25/2017 at 10:19 PM, bellini13 said:

edit your original topic

I tried that, I can't find any "mark as solved" or any similar button.

Could it be because I'm on a linux computer ? I don't see errors in the console, so the pages are loaded fully here. The only moderation action I see is "hide" . 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...