[Skip to main content](#vessel-content)

#   Generating a new order on trigger onAfterOrderUpdate blocks operation

##

- **[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")**
- [![PeterChain's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar570.png)](/forum/user/570-peterchain "View PeterChain's Profile") Topic Author
- [ Offline](/forum/user/570-peterchain)

Less More

- Posts: 640
- Thank you received: 16
-
-

8 years 5 months ago -  8 years 5 months ago [\#293116](#293116) by [PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")  *[Generating a new order on trigger onAfterOrderUpdate blocks operation](/forum/35-orders-management/894798-generating-a-new-order-on-trigger-onafterorderupdate-blocks-operation#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):   The operation (A) is this:  1. onAfterOrderUpdate triggers.  2. Check if the order&#95;status is &quot;shipped&quot;.  3. If it's shipped, replicates the information of the actual order (A) to a new object (B).  4. Calls the function $orderClass-&gt;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&#95;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")* was created by *[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")*

-- 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):**
Code:

If you want to create a new order, you can use such code: $order = new stdClass(); $order-&gt;order_full_price = 0; $order-&gt;order_currency_id = 1; $order-&gt;order_user_id = 64; $orderClass = hikashop_get('class.order'); $orderClass-&gt;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)](/media/kunena/emoticons/9.png "B)").

4. Calls the function $orderClass-&gt;save(object (![B)](/media/kunena/emoticons/9.png "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: 8 years 5 months ago by [PeterChain](/forum/user/570-peterchain "View PeterChain's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg5NDc5OC1nZW5lcmF0aW5nLWEtbmV3LW9yZGVyLW9uLXRyaWdnZXItb25hZnRlcm9yZGVydXBkYXRlLWJsb2Nrcy1vcGVyYXRpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86360
- Thank you received: 14296
-
-

8 years 5 months ago [\#293119](#293119) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Generating a new order on trigger onAfterOrderUpdate blocks operation](/forum/35-orders-management/894798-generating-a-new-order-on-trigger-onafterorderupdate-blocks-operation#293119 "-- 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):   The operation (A) is this:  1. onAfterOrderUpdate triggers.  2. Check if the order&#95;status is &quot;shipped&quot;.  3. If it's shipped, replicates the information of the actual order (A) to a new object (B).  4. Calls the function $orderClass-&gt;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&#95;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")*

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](/forum/user/570-peterchain "View PeterChain's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg5NDc5OC1nZW5lcmF0aW5nLWEtbmV3LW9yZGVyLW9uLXRyaWdnZXItb25hZnRlcm9yZGVydXBkYXRlLWJsb2Nrcy1vcGVyYXRpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.046 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
