Trigger from when order status was changed to shipped

  • Posts: 252
  • Thank you received: 1
7 years 4 months ago #255812

-- HikaShop version -- : 2.6.4
-- Joomla version -- : 3.5
-- PHP version -- : 5.5.12

Hi,
I need a trigger when order status was changed to shipped, but in the document there seems no such an Order API. How could I do this? Thanks in advance.

Best Regards

Please Log in or Create an account to join the conversation.

  • Posts: 81361
  • Thank you received: 13036
  • MODERATOR
7 years 4 months ago #255817

Hi,

There is. You can use the "onAfterOrderUpdate" trigger.
In it you need to check that $order->order_status is equal to "shipped" and that $order->old->order_status is set to "confirmed" so that you know that the status of the order has just been changes from confirmed to shipped.

The following user(s) said Thank You: twscott

Please Log in or Create an account to join the conversation.

  • Posts: 252
  • Thank you received: 1
7 years 4 months ago #255882

Thanks, Nicolas. I works.
But I found when I update the order status, the function was triggered 3 time. Is there ways to make it call only once?

Best regards

Please Log in or Create an account to join the conversation.

  • Posts: 81361
  • Thank you received: 13036
  • MODERATOR
7 years 4 months ago #255896

Hi,

It is called only once per order and per save.
If you have HikaMarket and you change the status of an order, you'll also have each sub order's status changed and thus, the trigger will also be called for each sub sale.
So in that case, you probably only want to take into account the save of main orders and thus add a check on $order->order_type (or $order->old->order_type) equal to "sale" in your code.
Mass actions or third party plugins (or even some particular HikaShop plugins) can also potentially save orders to change something after an order is saved. Deactivating them can help avoid that, but if you have them, it's probably that you use them, so it's better to add additional checks in your plugin in such cases.

The following user(s) said Thank You: twscott

Please Log in or Create an account to join the conversation.

Time to create page: 0.039 seconds
Powered by Kunena Forum