Skip to main content

How to save order details in a plugin

More
11 years 8 months ago - 11 years 8 months ago #187787 by paulvanharen
-- 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: 11 years 8 months ago by paulvanharen.

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

More
11 years 8 months ago #187800 by Xavier
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:
Code:
$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.

More
11 years 8 months ago - 11 years 8 months ago #187930 by paulvanharen
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
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: 11 years 8 months ago by paulvanharen.

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

More
11 years 8 months ago #187977 by Mohamed Thelji
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.276 seconds
Powered by Kunena Forum