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

#   \[SOLVED\] Geting the stock from external ERP server and save it after ordering

##

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

Less More

- Posts: 282
- Thank you received: 42
-
-

8 years 3 months ago -  8 years 3 months ago [\#294767](#294767) by [oxido](/forum/user/29793-oxido "View oxido's Profile")  *[\[SOLVED\] Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#294767 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")* was created by *[oxido](/forum/user/29793-oxido "View oxido's Profile")*

-- HikaShop version -- : 3.4.1
-- Joomla version -- : 3.8.10

Hi,
I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP.
So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ?
**A)** onBeforeOrderUpdate(&amp;$order,&amp;$do)
**![B)](/media/kunena/emoticons/1.png "B)")** onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?)
**C)** onBeforeOrderCreate

And i have to use this function to get each product from the order to change the stock? Code:

function getProductInfo($product_id) { $productClass = hikashop_get('class.product'); $productinfo = $productClass-&gt;get($product_id); return $productinfo; }

And if so, how do i save the changes, with: $product-&gt;save(); ?

Last edit: 8 years 3 months ago by [oxido](/forum/user/29793-oxido "View oxido's Profile").

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

- **[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")**
- [![Mohamed Thelji's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar6861.png)](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")
- [ Offline](/forum/user/6861-mohamed-thelji)

Less More

- Posts: 12953
- Thank you received: 1778
-
-
-

8 years 3 months ago [\#294770](#294770) by [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")  Replied by *[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")* on topic *[Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#294770 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")*

Hello,

Note that if you want to update Hikashop product's stock you'll just have to use the "Update the product stock on confirmed status" option through the page "Hikashop-&gt;System-&gt;Configuration-&gt;Main".

If you want to execute special code when order are confirmed then using the "onAfterOrderUpdate(&amp;$order,&amp;$send_email)" trigger will do the job, for more information :
[ www.hikashop.com/support/documentation/6...l#onAfterOrderUpdate](https://www.hikashop.com/support/documentation/62-hikashop-developer-documentation.html#onAfterOrderUpdate)

> onAfterOrderUpdate(&amp;$order,&amp;$send\_email)
> This function will be triggered by HikaShop after an order is updated. You will get in the $order object the information which is updated for the order. The $send\_email variable can be set to true/false in case you want to allow/disallow the email notification to the customer.

You'll have to check the the order_status is set to a "confirmed" order status before executing your code.

Best regards,
Mohamed Thelji.

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

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

Less More

- Posts: 282
- Thank you received: 42
-
-

8 years 3 months ago -  8 years 3 months ago [\#294815](#294815) by [oxido](/forum/user/29793-oxido "View oxido's Profile")  Replied by *[oxido](/forum/user/29793-oxido "View oxido's Profile")* on topic *[Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#294815 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")*

What is wrong with this function, why the product quantity is not saved?
Code:

function onAfterOrderUpdate(&amp;$order,&amp;$send_email){ foreach ($order-&gt;products AS $product){ $this-&gt;setNewStock($product-&gt;product_id); } } function setNewStock($product_id) { $productClass = hikashop_get('class.product'); $product = $productClass-&gt;get(3); $product-&gt;product_quantity = "10"; $productClass-&gt;save(); }

Last edit: 8 years 3 months ago by [oxido](/forum/user/29793-oxido "View oxido's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg5NTE0OS1zb2x2ZWQtZ2V0aW5nLXRoZS1zdG9jay1mcm9tLWV4dGVybmFsLWVycC1zZXJ2ZXItYW5kLXNhdmUtaXQtYWZ0ZXItb3JkZXJpbmc/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: 86289
- Thank you received: 14265
-
-

8 years 3 months ago [\#294816](#294816) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#294816 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")*

Hi,

You need to pass the product to the save function.
So the line:
$productClass-&gt;save();
should be:
$productClass-&gt;save($product);

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

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

Less More

- Posts: 282
- Thank you received: 42
-
-

8 years 3 months ago [\#294845](#294845) by [oxido](/forum/user/29793-oxido "View oxido's Profile")  Replied by *[oxido](/forum/user/29793-oxido "View oxido's Profile")* on topic *[Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#294845 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")*

Thank you for the replay nicolas,
Using this line $productClass-&gt;save($product);
iget this error:
1054 Unknown column 'alias' in 'field list'
And the URL become: /index.php/hikashop-menu-for-products-listing/checkout/confirm/cart_id-24
with this message in page: The requested page can't be found.

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

- **[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")**
- [![Mohamed Thelji's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar6861.png)](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")
- [ Offline](/forum/user/6861-mohamed-thelji)

Less More

- Posts: 12953
- Thank you received: 1778
-
-
-

8 years 3 months ago [\#294856](#294856) by [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")  Replied by *[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")* on topic *[Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#294856 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")*

Hello,

Before debugging your code, can you use the "Check database" button through the page "Hikashop-&gt;System-&gt;Configuration" and tes it again ? Thank you.

Best regards,
Mohamed Thelji.

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

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

Less More

- Posts: 282
- Thank you received: 42
-
-

8 years 3 months ago [\#294890](#294890) by [oxido](/forum/user/29793-oxido "View oxido's Profile")  Replied by *[oxido](/forum/user/29793-oxido "View oxido's Profile")* on topic *[Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#294890 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")*

Hi Mohamed, i have Hikashop 3.5.0 now.
I did what you said, and i have the same problem.
This is the code in my plugin: Code:

&lt;?php defined('_JEXEC') or die; jimport('joomla.plugin.plugin'); class plgHikashopSeniorerp extends JPlugin { public function __construct(&amp;$subject, $config = array()) { parent::__construct($subject, $config); } function onAfterOrderUpdate(&amp;$order,&amp;$send_email){ dump($order, 'COM - onAfterOrderUpdate: '); $send_email = FALSE; foreach ($order-&gt;products AS $product){ $this-&gt;setNewStock($product-&gt;product_id); } } function setNewStock($product_id) { $productClass = hikashop_get('class.product'); $product = $productClass-&gt;get($product_id); $product-&gt;product_quantity = "10"; $productClass-&gt;save($product); } }

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

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26394
- Thank you received: 4078
-
- [](http://obsi.dev)
-

8 years 3 months ago [\#294899](#294899) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#294899 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")*

Hello,

You might not have access to the order products during the trigger "onAfterOrderUpdate".
You have that informaton during the order creation (and it's in "order-&gt;order-&gt;products" but for an update ; you don't and specially if the order modification is just regarding the "order status".
You should perform a lot of check in that trigger to just perform your action when it is really necessary and you should load the order products (or the full order) when it's the right time.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

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

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

Less More

- Posts: 282
- Thank you received: 42
-
-

8 years 3 months ago -  8 years 3 months ago [\#294933](#294933) by [oxido](/forum/user/29793-oxido "View oxido's Profile")  Replied by *[oxido](/forum/user/29793-oxido "View oxido's Profile")* on topic *[Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#294933 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")*

All right, let me simplify my requirement.
I want to create a function that get the product with all of his details, change the stock and save the product, how can I do it?
It does not matter how the function will be called.

This should work, but is not working because i don't have access to the product durring the trigger? Code:

function setNewStock($product_id) { $productClass = hikashop_get('class.product'); $product = $productClass-&gt;get($product_id); $product-&gt;product_quantity = "10"; $productClass-&gt;save($product); }

Because if this is the problem, i will try to find another way to call the function.

Last edit: 8 years 3 months ago by [oxido](/forum/user/29793-oxido "View oxido's Profile").

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

- **[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")**
- [![Mohamed Thelji's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar6861.png)](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")
- [ Offline](/forum/user/6861-mohamed-thelji)

Less More

- Posts: 12953
- Thank you received: 1778
-
-
-

8 years 3 months ago [\#294939](#294939) by [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")  Replied by *[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")* on topic *[Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#294939 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")*

Hello,

As we said :

> You should perform a lot of check in that trigger to just perform your action when it is **really necessary** and you should **load the order products** (or the full order) when it's the right time.

Note that you can load the full order by using that kind of code : Code:

$orderClass = hikashop_get('class.order'); $full_order = $orderClass-&gt;loadFullOrder($order-&gt;order_id,true);

Best regards,
Mohamed Thelji.

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

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

Less More

- Posts: 282
- Thank you received: 42
-
-

8 years 3 months ago [\#294977](#294977) by [oxido](/forum/user/29793-oxido "View oxido's Profile")  Replied by *[oxido](/forum/user/29793-oxido "View oxido's Profile")* on topic *[Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#294977 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")*

Hi Mohamed, tnx for the replay.

To load an order by ID, it is assumed that the order already exists in the database, right?
What i'm trying to do is to perform a check of stock for all the products from cart before creating the order.
So i thought to perform the check / update, using "onBeforeOrderCreate" and to set the real stock by taking it from my ERP server and saving it to the site's database, doing this before creating the order, i don't need to change something else in HS code, I just let HikaShop follow the course to creating the order or not.

> You should perform a lot of check in that trigger to just perform your action when it is really necessary and you should load the order products (or the full order) when it's the right time.

Can you help me with this, what check's should i perfom?
And when it's the right time? How can I figure this out?

Thank you!

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50Lzg5NTE0OS1zb2x2ZWQtZ2V0aW5nLXRoZS1zdG9jay1mcm9tLWV4dGVybmFsLWVycC1zZXJ2ZXItYW5kLXNhdmUtaXQtYWZ0ZXItb3JkZXJpbmc/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: 86289
- Thank you received: 14265
-
-

8 years 3 months ago [\#294983](#294983) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#294983 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")*

Hi,

When you do:
$product = $productClass-&gt;get($product_id);
$product contains all the data from the product in the hikashop_product table + additional data, like the alias.
If you want to then save that $product, you need to first unset that extra data.
However, if you just want to update the stock of the product, there is no need to load the data of the product and thus you can avoid that issue altogether.
For that, just write your code like that: Code:

function setNewStock($product_id) { $productClass = hikashop_get('class.product'); $product = new stdClass(); $product-&gt;product_id = $product_id; $product-&gt;product_quantity = "10"; $productClass-&gt;save($product); }

The following user(s) said Thank You: [oxido](/forum/user/29793-oxido "View oxido's Profile")

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

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

Less More

- Posts: 282
- Thank you received: 42
-
-

8 years 3 months ago [\#295002](#295002) by [oxido](/forum/user/29793-oxido "View oxido's Profile")  Replied by *[oxido](/forum/user/29793-oxido "View oxido's Profile")* on topic *[Geting the stock from external ERP server and save it after ordering](/forum/31-development/895149-solved-geting-the-stock-from-external-erp-server-and-save-it-after-ordering#295002 "-- HikaShop version -- : 3.4.1 -- Joomla version -- : 3.8.10  Hi, I'm when i create an order on my shop, i'm getting the REAL stock from another server, from an ERP. So, let's say that in ERP i have stock 200 for Product A, i add Product A in cart, quantity 1, on checkout page when i press Finish, what trigger can i use to save the remaining stock 199 in hikashop ? A) onBeforeOrderUpdate(&amp;$order,&amp;$do) B) onBeforeProductUpdate(&amp;$element,&amp;$do)? (I think this is triggered only when i add or edit the product, not when stock is updated, right?) C) onBeforeOrderCreate  And i have to use this function to get each product from the order to change the stock?  And if so, how do i save the changes, with: $product-&gt;save(); ?")*

:woohoo: That was it nicolas!
Thank you!

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

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

[](#top)
