- Posts: 279
- Thank you received: 42
[SOLVED] Geting the stock from external ERP server and save it after ordering
-- 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(&$order,&$do)
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->save(); ?
Please Log in or Create an account to join the conversation.
- Posts: 12953
- Thank you received: 1778
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->System->Configuration->Main".
If you want to execute special code when order are confirmed then using the "onAfterOrderUpdate(&$order,&$send_email)" trigger will do the job, for more information :
www.hikashop.com/support/documentation/6...l#onAfterOrderUpdate
onAfterOrderUpdate(&$order,&$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 or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
You need to pass the product to the save function.
So the line:
$productClass->save();
should be:
$productClass->save($product);
Please Log in or Create an account to join the conversation.
Using this line $productClass->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 or Create an account to join the conversation.
- Posts: 12953
- Thank you received: 1778
Before debugging your code, can you use the "Check database" button through the page "Hikashop->System->Configuration" and tes it again ? Thank you.
Best regards,
Mohamed Thelji.
Please Log in or Create an account to join the conversation.
I did what you said, and i have the same problem.
This is the code in my plugin:
Please Log in or Create an account to join the conversation.
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->order->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 & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Please Log in or Create an account to join the conversation.
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?
Please Log in or Create an account to join the conversation.
- Posts: 12953
- Thank you received: 1778
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 :
Best regards,
Mohamed Thelji.
Please Log in or Create an account to join the conversation.
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.
Can you help me with this, what check's should i perfom?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.
And when it's the right time? How can I figure this out?
Thank you!
Please Log in or Create an account to join the conversation.
When you do:
$product = $productClass->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:
Please Log in or Create an account to join the conversation.
Thank you!
Please Log in or Create an account to join the conversation.