Jump to content

Proper way to detect when order is shipped


Nils-H

Recommended Posts

I have a module that will send an email when the order status is set to shipped. What is the proper way to detect this? The way I'm currently doing it is to create a module that registers a hook with "actionOrderStatusPostUpdate", and check the "newOrderStatus" to see if it has the id '4', which corresponds to "shipped". However, this does seem a little fragile, in case the id of this status changes. I also notice that the order status has a "shipped" property, but there are multiple order statuses with this property set to "true", so that wouldn't work either. Is there a better way to do this detection?

Link to comment
Share on other sites

What you are doing is the 'correct' way of doing it, as the chances that the default order status changing from '4' is remote. To enhance that, you could alter the module to allow the merchant to configure what status or statuses represent shipped.

 

You could also rely on the Order function hasBeenShipped to further verify, but I will suspect this would return true if the order status was '4'.

Link to comment
Share on other sites

Thanks. I found a slightly better way, inspired by the OrderHistory class. The id of the sipped status is stored in the configuration table, so I use Configuration::get('PS_OS_SHIPPED') instead of hard coding the constant 4.

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...