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

#   retrieve order\_id onBeforeOrderCreate

##

- **[zerocul](/forum/user/2030-zerocul "View zerocul's Profile")**
- [![zerocul's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/2030-zerocul "View zerocul's Profile") Topic Author
- [ Offline](/forum/user/2030-zerocul)

Less More

- Posts: 20
- Thank you received: 0
-
-

15 years 5 months ago [\#16789](#16789) by [zerocul](/forum/user/2030-zerocul "View zerocul's Profile")  *[retrieve order\_id onBeforeOrderCreate](/forum/4-how-to/16789-retrieve-order-id-onbeforeordercreate#16789 "is there a way to retrieve order&#95;id onBeforeOrderCreate?  otherwise, what would be the best way around it?  I am looking to link an id (not hikashop table) created before order to the newly created order&#95;id (hikashop&#95;order).  I am quite desperate now. Please help. :(")* was created by *[zerocul](/forum/user/2030-zerocul "View zerocul's Profile")*

is there a way to retrieve order_id onBeforeOrderCreate?

otherwise, what would be the best way around it?

I am looking to link an id (not hikashop table) created before order to the newly created order_id (hikashop_order).

I am quite desperate now. Please help. ![:(](/media/kunena/emoticons/5.png ":(")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzE2Nzg5LXJldHJpZXZlLW9yZGVyLWlkLW9uYmVmb3Jlb3JkZXJjcmVhdGU/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)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86292
- Thank you received: 14271
-
-

15 years 5 months ago [\#16790](#16790) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: retrieve order\_id onBeforeOrderCreate](/forum/4-how-to/16789-retrieve-order-id-onbeforeordercreate#16790 "is there a way to retrieve order&#95;id onBeforeOrderCreate?  otherwise, what would be the best way around it?  I am looking to link an id (not hikashop table) created before order to the newly created order&#95;id (hikashop&#95;order).  I am quite desperate now. Please help. :(")*

The event onBeforeOrderCreate is called, as the name tells you, before the order is created. So you don't have the order_id at that time since the order_id is generated automatically by MySQL when a new entry in the order table is inserted.
If you really need it at that point, the only way I can see (which is not perfect), would be to do a query and load the max order_id of the order table and increment it so that you get the next order_id which will be used and there is a very high probability that there won't be any order created between that time and the creation of the order.
But maybe you should do it differently: add a custom order field and use the unique_id() PHP function to generate an unique id that you can put in the custom field, use it in your code, and then you will be able to identify the order with that unique id.

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

- **[zerocul](/forum/user/2030-zerocul "View zerocul's Profile")**
- [![zerocul's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/2030-zerocul "View zerocul's Profile") Topic Author
- [ Offline](/forum/user/2030-zerocul)

Less More

- Posts: 20
- Thank you received: 0
-
-

15 years 5 months ago [\#16791](#16791) by [zerocul](/forum/user/2030-zerocul "View zerocul's Profile")  Replied by *[zerocul](/forum/user/2030-zerocul "View zerocul's Profile")* on topic *[Re: retrieve order\_id onBeforeOrderCreate](/forum/4-how-to/16789-retrieve-order-id-onbeforeordercreate#16791 "is there a way to retrieve order&#95;id onBeforeOrderCreate?  otherwise, what would be the best way around it?  I am looking to link an id (not hikashop table) created before order to the newly created order&#95;id (hikashop&#95;order).  I am quite desperate now. Please help. :(")*

hmm I found another way around it (I just realised cart is only deleted after onAfterOrderCreate is triggered) so before the order is created, i retrieve the cart id and put into another table, then after the order is created, i retrieve the newly created order_id by matching the cart_id's.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzE2Nzg5LXJldHJpZXZlLW9yZGVyLWlkLW9uYmVmb3Jlb3JkZXJjcmVhdGU/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)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86292
- Thank you received: 14271
-
-

15 years 5 months ago [\#16792](#16792) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: retrieve order\_id onBeforeOrderCreate](/forum/4-how-to/16789-retrieve-order-id-onbeforeordercreate#16792 "is there a way to retrieve order&#95;id onBeforeOrderCreate?  otherwise, what would be the best way around it?  I am looking to link an id (not hikashop table) created before order to the newly created order&#95;id (hikashop&#95;order).  I am quite desperate now. Please help. :(")*

That's also a possibility indeed.

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

- **[zerocul](/forum/user/2030-zerocul "View zerocul's Profile")**
- [![zerocul's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/2030-zerocul "View zerocul's Profile") Topic Author
- [ Offline](/forum/user/2030-zerocul)

Less More

- Posts: 20
- Thank you received: 0
-
-

15 years 5 months ago [\#16795](#16795) by [zerocul](/forum/user/2030-zerocul "View zerocul's Profile")  Replied by *[zerocul](/forum/user/2030-zerocul "View zerocul's Profile")* on topic *[Re: retrieve order\_id onBeforeOrderCreate](/forum/4-how-to/16789-retrieve-order-id-onbeforeordercreate#16795 "is there a way to retrieve order&#95;id onBeforeOrderCreate?  otherwise, what would be the best way around it?  I am looking to link an id (not hikashop table) created before order to the newly created order&#95;id (hikashop&#95;order).  I am quite desperate now. Please help. :(")*

on a related question, can you tell me what variables can I expect in $order-&gt;cart within onAfterOrderCreate function? would cart_product_id be in there?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzE2Nzg5LXJldHJpZXZlLW9yZGVyLWlkLW9uYmVmb3Jlb3JkZXJjcmVhdGU/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)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86292
- Thank you received: 14271
-
-

15 years 5 months ago [\#16799](#16799) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: retrieve order\_id onBeforeOrderCreate](/forum/4-how-to/16789-retrieve-order-id-onbeforeordercreate#16799 "is there a way to retrieve order&#95;id onBeforeOrderCreate?  otherwise, what would be the best way around it?  I am looking to link an id (not hikashop table) created before order to the newly created order&#95;id (hikashop&#95;order).  I am quite desperate now. Please help. :(")*

You have all the information you want including the cart_product_id but cart_product_id is for each products of the cart. So it's in a products array and not directly in that object. For example, for the first product of the cart:
$order-&gt;cart-&gt;products[0]-&gt;cart_product_id;

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

- **[zerocul](/forum/user/2030-zerocul "View zerocul's Profile")**
- [![zerocul's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/2030-zerocul "View zerocul's Profile") Topic Author
- [ Offline](/forum/user/2030-zerocul)

Less More

- Posts: 20
- Thank you received: 0
-
-

15 years 5 months ago -  15 years 5 months ago [\#16801](#16801) by [zerocul](/forum/user/2030-zerocul "View zerocul's Profile")  Replied by *[zerocul](/forum/user/2030-zerocul "View zerocul's Profile")* on topic *[Re: retrieve order\_id onBeforeOrderCreate](/forum/4-how-to/16789-retrieve-order-id-onbeforeordercreate#16801 "is there a way to retrieve order&#95;id onBeforeOrderCreate?  otherwise, what would be the best way around it?  I am looking to link an id (not hikashop table) created before order to the newly created order&#95;id (hikashop&#95;order).  I am quite desperate now. Please help. :(")*

![:(](/media/kunena/emoticons/5.png ":(") no luck, i tried the following in onAfterOrderCreate and cart_product_id is empty:

echo "cartproductid is ".$order-&gt;cart-&gt;products[0]-&gt;cart_product_id;

Last edit: 15 years 5 months ago by [zerocul](/forum/user/2030-zerocul "View zerocul's Profile"). Reason: typo

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzE2Nzg5LXJldHJpZXZlLW9yZGVyLWlkLW9uYmVmb3Jlb3JkZXJjcmVhdGU/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)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86292
- Thank you received: 14271
-
-

15 years 5 months ago [\#16810](#16810) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: retrieve order\_id onBeforeOrderCreate](/forum/4-how-to/16789-retrieve-order-id-onbeforeordercreate#16810 "is there a way to retrieve order&#95;id onBeforeOrderCreate?  otherwise, what would be the best way around it?  I am looking to link an id (not hikashop table) created before order to the newly created order&#95;id (hikashop&#95;order).  I am quite desperate now. Please help. :(")*

As a general advice, you should include the library dbug on your website: [ dbug.ospinto.com/](http://dbug.ospinto.com/)
and then use that code:

new dbug($order);
exit;

That will display you nicely the whole object and you will be able to easily see where the information you're looking for is stored.

I just checked it on our end and the cart_product_id of the products is not given to the event onAfterOrderCreate.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzE2Nzg5LXJldHJpZXZlLW9yZGVyLWlkLW9uYmVmb3Jlb3JkZXJjcmVhdGU/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.190 seconds

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

[](#top)
