Using onAfterOrderUpdate in administrator backend

  • Posts: 11
  • Thank you received: 0
4 years 4 days ago #316799

-- HikaShop version -- : 3.5.1
-- Joomla version -- : 3.8.2
-- PHP version -- : 7.1

Hi, I've been trying to create a function when admin modifies a order from backend, and I've had no luck.. I've tried using variations of below code in order.php (classes and controllers) any help would be appreciate! ( I want to create a function when admin cancels an order, needs to send an API to outside affiliate) Thanks!

function onAfterOrderUpdate (&$order,&$send_email) {
var_dump('ahasdh'); exit;
$config =& hikashop_config();
$confirmed = $config->get('order_confirmed_status');
$orderClass = hikashop_get('class.order');
$orderInDb = $orderClass->loadFullOrder($order->order_id);
if (!isset ($order->order_status))
return true;
if ($order->order_status = $confirmed) {
return true;
}

if ($order->order_status == $confirmed) {

// my simple action to test
}
}

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

  • Posts: 81361
  • Thank you received: 13037
  • MODERATOR
4 years 3 days ago #316802

Hi,

You need to place that code inside a Joomla plugin of the group "hikashop".
Here, you can find information on how to build Joomla plugins:
docs.joomla.org/Portal:Plugin_Development
And here, you can see what the PHP code can look like for a Joomla plugin of the group "hikashop":
www.hikashop.com/support/documentation/6...mentation.html#howto

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

  • Posts: 11
  • Thank you received: 0
4 years 3 days ago #316822

Many Thanks!
Another question if that's ok, I need to store 3rd party affiliate info into the order, what suggested methods would there be? After onOrderConfirm? Is it possible to use cookies when writing functions? Thanks! (Because API info must only be sent if the 3rd party affiliate cookie exists)
Thanks!

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

  • Posts: 81361
  • Thank you received: 13037
  • MODERATOR
4 years 2 days ago #316826

Hi,

In that case, you can use the onBeforeOrderCreate(&$order, &$do) trigger.
You could first create a custom field of the table "order" so that you could store the information you want in that column of the hikashop_order table.
Then, you can check the cookies of the customer in that trigger with the $_COOKIE PHP global array:
www.php.net/manual/en/reserved.variables.cookies.php
www.tutorialrepublic.com/php-tutorial/php-cookies.php

And in the onBeforeOrderCreate function of your plugin, you can just have that code:
$order->xxx = $var;
where xxx is the column name of your custom field and $var contains the string you want to store. HikaShop will save your data for you automcatically since your code will be just before the saving process.

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

Time to create page: 0.060 seconds
Powered by Kunena Forum