Generating a new order on trigger onAfterOrderUpdate blocks operation

  • Posts: 634
  • Thank you received: 16
  • Hikashop Business
5 years 10 months ago #293116

-- HikaShop version -- : 3.4.0
-- Joomla version -- : 3.8.7
-- PHP version -- : 7.1.0

Hi,

I have developed a Hikashop plugin with a trigger onAfterOrderUpdate.

This plugin generates a new order after an order is shipped (its status changes to Shipped).



I use this code (it's on the developer documentation):

If you want to create a new order, you can use such code:

$order = new stdClass();

$order->order_full_price = 0;

$order->order_currency_id = 1;

$order->order_user_id = 64;

$orderClass = hikashop_get('class.order');

$orderClass->save($order);




The operation (A) is this:


1. onAfterOrderUpdate triggers.

2. Check if the order_status is "shipped".

3. If it's shipped, replicates the information of the actual order (A) to a new object (B).

4. Calls the function $orderClass->save(object (B)).

5. Other code runs after point 4....



I expect the function in point 4 to return the id of the new generated order, but the operation seems to never end (it gets stalled) even the order is created.

I need the operation to return the order_id to run some other actions at step 5 once the order has been generated and get back the control of the script (avoid stalling).
I never get the control of the website back, I have to close the browser window.

Shall I consider some extra step in my code?

EDIT: We have created a plugin that triggers when a new order is created just to check if afterOrderCreate trigger was triggering. I can confirm this. To me looks like when triggers from the new created order end, the system doesn't give control back to the original plugin triggered by the change of status of the first order (operation A).

Thanks in advance.

--
Victor

Last edit: 5 years 10 months ago by PeterChain.

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

  • Posts: 81378
  • Thank you received: 13037
  • MODERATOR
5 years 10 months ago #293119

Hi,

The problem is likely coming from something else.
When you create a new order with the save function, HikaShop triggers the different plugins onBeforeOrderCreate and onAfterOrderCreate and send the emails for the order creation.
So it could come from another plugin which doesn't expect the data you have in your $order object.
Or even the emails.
It's hard to say.
If you want to avoid such issue, run the INSERT MySQL query to hikashop_order and hikashop_order_product tables yourself in your plugin. That way, you'll be sure than nothing gets in the way.

The following user(s) said Thank You: PeterChain

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

Time to create page: 0.053 seconds
Powered by Kunena Forum