How to store transaction id in hikashop order table as a new field

  • Posts: 21
  • Thank you received: 0
4 years 4 months ago #321534

-- HikaShop version -- : 4.3.0
-- Joomla version -- : 3.9.19
-- PHP version -- : 7.3

I am working on a custom third party payment plugin. I have installed it and have implemented code to redirect on payment page and back on shop successfully. Now I want to store transaction id retrieved from payment gateway in order table as a new field.

I don't know how to store/add transaction id in order table.

I tried below code, but it is also not working.

$orderClass = hikashop_get('class.order');
$order = $orderClass->get($order_id);
if(isset($order->custom_auth_number)){
     $order->custom_auth_number = $authNumber;
}                   
if(isset($order->custom_txn_id)){
    $order->custom_txn_id = $transactionId;
 }
$orderClass->save($order);

So if anyone can help me out from this would be very helpful for me.

Thanks

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 4 months ago #321549

Hi,

This should be fine. However, I would recommend to only add the attributes you want in the $order object, like this:

$orderClass = hikashop_get('class.order');
$order = new stdClass();
$order->order_id = $order_id;
$order->custom_auth_number = $authNumber;
$order->custom_txn_id = $transactionId;
$orderClass->save($order);
Note that you first need to have the columns custom_auth_number and custom_txn_id in the hikashop_order table.
If you don't, the MySQL query will crash.
So you first want to do an ALTER on that table to add these columns if you don't already have them.

The following user(s) said Thank You: ajdev33

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

  • Posts: 21
  • Thank you received: 0
4 years 4 months ago #321564

Isn't this possible to run Alter table or new table SQL script on plugin install ? Because I want field like transaction id to be added in order table dynamically not manually.

Please suggest any solution.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 4 months ago #321571

Hi,

You can use the preflight function of Joomla plugins to do that:
books.google.fr/books?id=FNA3CwAAQBAJ&pg...gin%20joomla&f=false
Or what you could do is actually do a :
$orderClass->get($order_id);
To get the data already in the database, add such check:

if(!isset($orderInDb->xxx)) {
  // run ALTER MySQL query to add the column xxx to hikashop_order
}
directly before your code in the plugin

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

Time to create page: 0.058 seconds
Powered by Kunena Forum