How to save order details in a plugin

  • Posts: 45
  • Thank you received: 0
9 years 10 months ago #187787

-- HikaShop version -- : 2.3.5
-- Joomla version -- : 3.3.6

Hi,

I'm making a new payment plugin. In onOrderAfterConfirmation the payment portal generates a transaction ID that I want/need to store with the order.
I tried the following:

  1. Add the transaction ID to $order->order_payment_params. Nothing is saved.
  2. Add the transaction ID, and call $order->save($order). White screen, function not found apparently.
  3. Add the transaction ID, create a dummy order to have access to the save method. This works, but now I get an SQL error that I want to inject fields that are not in the database.
  4. Add the transaction ID, and copy all fields whose names start with 'order_' to a new object, and try to save that one. A SQL error occurs again, that still some fields are not in the database.
OK, I think I can make this work, but I was asking myself whether there is a smarter way to accomplish this.

Your help is appreciated.

Best regards, Paul

Last edit: 9 years 10 months ago by paulvanharen.

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

  • Posts: 13201
  • Thank you received: 2322
9 years 10 months ago #187800

Hi,

To add a value to the order, I think that the easiest way will be to create a custom field in the order table.
This way it will add a column in the database, and you will just have to add the value to $order->CUSTOMFIELD_NAME and save the order.

To use the "save" function you need to call the order class before:

$orderClass = hikashop_get('class.order');
if(isset($order->CUSTOMFIELD_NAME)){
    $order->CUSTOMFIELD_NAME = $transaction_id;
}
$orderClass->save($order);

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

  • Posts: 45
  • Thank you received: 0
9 years 10 months ago #187930

Dear Xavier,

Thank you for looking into this. Your suggestion is nearly the same as my attempt #3. Instead of adding it as a field to the database, I want to store my data in the params structure. The mechanics for that are already available.

Your code

$orderClass->save($order);
will suffer from the same issues as mine, that in other parts of the checkout process data has been added to this object, that are not reflected in the database. Therefore, you're code will also issue an SQL error.

Last edit: 9 years 10 months ago by paulvanharen.

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

  • Posts: 12953
  • Thank you received: 1778
9 years 10 months ago #187977

Hello,
Note that checking the "modifyOrder" function of the "administrator\components\com_hikashop\helpers\helper.php" file will probably help you, note that you can save your order using the save function of the $orderClass, but you can also save some extra data via "$order->history->history_data".

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

Time to create page: 0.079 seconds
Powered by Kunena Forum