- Posts: 75
- Thank you received: 4
Change hikashop order status from external code
- Petike1007
-
Topic Author
- Offline
Less
More
3 years 1 month ago - 3 years 1 month ago #354586
by Petike1007
Change hikashop order status from external code was created by Petike1007
-- HikaShop version -- : 4.7.3
Hi,
Is there any way to change hikashop order status with an extarnal php code and send the order status email to the user as well?
I make a hikashop webshop which is connected to a billing software which is connected to the bank.
When the user choose bank wire, he got a fee request form (like a pre invoice) and when the transfer is made then the invoice is automatically generated. In this state I have to modify the order status in hikashop to close the order.
I can get the payment status from the billing software and I would like to change the order status in hikashop to completed and send the email to the user.
I hope it's clear, and possible.
Thanks
Hi,
Is there any way to change hikashop order status with an extarnal php code and send the order status email to the user as well?
I make a hikashop webshop which is connected to a billing software which is connected to the bank.
When the user choose bank wire, he got a fee request form (like a pre invoice) and when the transfer is made then the invoice is automatically generated. In this state I have to modify the order status in hikashop to close the order.
I can get the payment status from the billing software and I would like to change the order status in hikashop to completed and send the email to the user.
I hope it's clear, and possible.
Thanks
Last edit: 3 years 1 month ago by Petike1007.
Please Log in or Create an account to join the conversation.
3 years 1 month ago #354588
by nicolas
Replied by nicolas on topic Change hikashop order status from external code
Hi,
Yes. You can do it like that:
Yes. You can do it like that:
Code:
// first step if you are outside of Joomla, make sure that the Joomla libraries are loaded
// for example: https://joomla.stackexchange.com/questions/23458/how-does-joomla-initialise-all-active-libraries-and-plugins
// second step, load hikaShop
if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }
// third step, build the order object
$order = new stdClass();
$order->order_id = $order_id;
$order->order_status = 'confirmed';
// add a history line and ask HikaShop to notify the customer
$order->history = new stdClass();
$order->history->history_reason = 'billing software triggered the status update'
$order->history->history_notified = 1;
// save the order
$orderClass = hikashop_get('class.order');
$orderClass->save($order);
The following user(s) said Thank You: Petike1007
Please Log in or Create an account to join the conversation.
- Petike1007
-
Topic Author
- Offline
Less
More
- Posts: 75
- Thank you received: 4
3 years 1 month ago #354594
by Petike1007
Replied by Petike1007 on topic Change hikashop order status from external code
If I put my code into a function in a hikashop plugin how can I call that from a cron?
I have a hikashop plugin called billing and in the billing.php I made a function updateStatusFromBillingSoftware and put the code below into it.
I have a hikashop plugin called billing and in the billing.php I made a function updateStatusFromBillingSoftware and put the code below into it.
Please Log in or Create an account to join the conversation.
3 years 1 month ago #354597
by nicolas
Replied by nicolas on topic Change hikashop order status from external code
Hi,
You can implement the onHikashopCronTrigger event of HikaShop:
www.hikashop.com/support/documentation/6...nHikashopCronTrigger
Then, you can configure your HikaShop cron task:
www.hikashop.com/support/documentation/5...ashop-cron-task.html
You can implement the onHikashopCronTrigger event of HikaShop:
www.hikashop.com/support/documentation/6...nHikashopCronTrigger
Then, you can configure your HikaShop cron task:
www.hikashop.com/support/documentation/5...ashop-cron-task.html
The following user(s) said Thank You: Petike1007
Please Log in or Create an account to join the conversation.
- Petike1007
-
Topic Author
- Offline
Less
More
- Posts: 75
- Thank you received: 4
3 years 1 week ago - 3 years 1 week ago #355053
by Petike1007
Replied by Petike1007 on topic Change hikashop order status from external code
I'm using the code like this:
Where $current_status coming from the billing software. When it's paid there, it's changing the status in the webshop to confirmed and add the history as well...works well..
But looks like the onAfterOrderUpdate event not running after this, as I have there a code with:
which is not happening just when I change the status on the admin.
Should I add any code to run the event?
Code:
$current_status = $bill_api->getDocument($order['order_invoice_number']);
if ($current_status->getPaymentStatus() == 'paid') {
$orderObj = new stdClass();
$orderObj->order_id = (int)$order['order_id'];
$orderObj->order_status = 'confirmed';
$orderObj->history = new stdClass();
$orderObj->history->history_notified = 1;
$orderObj->history->history_reason = "Invoice ready";
$orderObj->history->history_type = "modification";
$orderClass = hikashop_get('class.order');
$orderClass->save($orderObj);
}
But looks like the onAfterOrderUpdate event not running after this, as I have there a code with:
Code:
if($order->order_status != $order->old->order_status){
if($order->order_status == "confirmed"){
}
}
which is not happening just when I change the status on the admin.
Should I add any code to run the event?
Last edit: 3 years 1 week ago by Petike1007.
Please Log in or Create an account to join the conversation.
3 years 1 week ago #355054
by nicolas
Replied by nicolas on topic Change hikashop order status from external code
Hi,
No. onAfterOrderUpdate is definitely triggered if you're calling the save function.
I suppose that the problem is with how you check that your code is running.
When you change the status of an order in the backend, it is done via an ajax HTTP request. And the output of that request is not necessarily displayed. So to make sure that the event is being called, I would recommend using a call to the hikashop_writeToLog() function. You can pass to it some text as the first parameter and that text will be logged in the "payment log file" setting of the HikaShop configuration.
That way, you can make sure that the event is called even if nothing outputs on the browser during the process.
No. onAfterOrderUpdate is definitely triggered if you're calling the save function.
I suppose that the problem is with how you check that your code is running.
When you change the status of an order in the backend, it is done via an ajax HTTP request. And the output of that request is not necessarily displayed. So to make sure that the event is being called, I would recommend using a call to the hikashop_writeToLog() function. You can pass to it some text as the first parameter and that text will be logged in the "payment log file" setting of the HikaShop configuration.
That way, you can make sure that the event is called even if nothing outputs on the browser during the process.
Please Log in or Create an account to join the conversation.
Time to create page: 0.215 seconds