Change hikashop order status from external code

  • Posts: 68
  • Thank you received: 3
8 months 6 days ago #354586

-- 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

Last edit: 8 months 6 days ago by Petike1007.

Please Log in or Create an account to join the conversation.

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
8 months 6 days ago #354588

Hi,

Yes. You can do it like that:

// 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.

  • Posts: 68
  • Thank you received: 3
8 months 6 days ago #354594

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.

Please Log in or Create an account to join the conversation.

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
8 months 6 days ago #354597

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

The following user(s) said Thank You: Petike1007

Please Log in or Create an account to join the conversation.

  • Posts: 68
  • Thank you received: 3
7 months 2 weeks ago #355053

I'm using the code like this:

$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);
                }
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:
 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: 7 months 2 weeks ago by Petike1007.

Please Log in or Create an account to join the conversation.

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
7 months 2 weeks ago #355054

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.

Please Log in or Create an account to join the conversation.

Time to create page: 0.063 seconds
Powered by Kunena Forum