Change Order Status event hook
Permalink Browser Info Environment
So... I'm doing an API integration with a warehouse for my client, and we need to generate an outgoing email every time an order status changes ("Pending", "Authorized", "Shipped", "Complete", "Cancelled").
CoreCommerce didn't seem to have a suitable event to hook into when this occurs, so I set one up. Code is right below.
In file /packages/core_commerce/controllers/dashboard/orders/search.php, at line 61 (the method update_order_status()), add this before the redirect:
Then, to hook into that event, you'd use this (I use it in a package controller's on_start() method for example)
Finally, the contents of the change_order_status.php file look like this:
To the CoreCommerce package maintainers - can we put this into the next release?
CoreCommerce didn't seem to have a suitable event to hook into when this occurs, so I set one up. Code is right below.
In file /packages/core_commerce/controllers/dashboard/orders/search.php, at line 61 (the method update_order_status()), add this before the redirect:
Events::fire('core_commerce_change_order_status', $order, $this->post('oStatus'));
Then, to hook into that event, you'd use this (I use it in a package controller's on_start() method for example)
Events::extend('core_commerce_change_order_status', 'ChangeOrderStatus', 'onChange', DIRNAME_PACKAGES . '/' . $this->pkgHandle . '/models/events/change_order_status.php');
Finally, the contents of the change_order_status.php file look like this:
class ChangeOrderStatus { /** * This gets fired when an order status changes. * @param CoreCommerceOrder $order * @param integer $status */ public function onChange(CoreCommerceOrder $order, $status) { // do magic here } }
To the CoreCommerce package maintainers - can we put this into the next release?
Type: | Discussion |
---|---|
Status: | New |
Cool, I will make sure Andrew sees this.
Thanks for this it will be in the next release.
I using v2.5 and it looks like this was never added so I'm having to make these exact changes (thank you circumerro). This event hook would definitely be a welcome addition. In my current use case its needed to send an additional email to alert the customer when an order has shipped.
Also... it would be nice to have all of the core_commerce events listed in the developer documentation.
Also... it would be nice to have all of the core_commerce events listed in the developer documentation.
Hi, We added a lot of changes into 2.5 to update it for the 5.5 core and we are currently working on getting the add-on compatible with the Internationalization add-on. So, as it stands the events just haven't made it in there yet.
I think for the time being we'll add a link to this thread for any developers interested in having this functionality. If you don't mind, please post back with your experience using the modification.
I think for the time being we'll add a link to this thread for any developers interested in having this functionality. If you don't mind, please post back with your experience using the modification.
The next release of eCommerce will actually incorporate the order status change event as an option available for devs to extend.
What kind of events are available?
I have a need to fire events for pretty much everything that I'd expect an e-commerce addon to do, e.g
Creating / Updating a customer
Creating / updating a customer address
Create / Update Product
Update product stock level
Placing of order etc etc
This is also for a warehouse system, so I need to be able to sync my store in terms of orders, products with the warehouse.
Thanks
I have a need to fire events for pretty much everything that I'd expect an e-commerce addon to do, e.g
Creating / Updating a customer
Creating / updating a customer address
Create / Update Product
Update product stock level
Placing of order etc etc
This is also for a warehouse system, so I need to be able to sync my store in terms of orders, products with the warehouse.
Thanks
Hi craigwillis85,
Here's some documentation on the events currently built into eCommerce:
http://www.concrete5.org/marketplace/addons/ecommerce/documentation...
Here's some documentation on the events currently built into eCommerce:
http://www.concrete5.org/marketplace/addons/ecommerce/documentation...