We need to know how can we populate data in the transaction table from admin?
Is it triggered with any actions performed on the orders objects?
class MyClass { protected $saveTransaction; public function __construct \Magento\Framework\DB\TransactionFactory $transactionFactory ){ $this->saveTransaction = $transactionFactory->create(); } public function saveManyObjects() { ... $this->saveTransaction->addObject($order); $this->saveTransaction->addObject($customer); $this->saveTransaction->addObject($customObject); $this->saveTransaction->save(); } }
For a transaction you need to inject \Magento\Framework\DB\TransactionFactory, which offers all needed functionality. You can add objects to save by addObject() method. You can add all methods: orders, customers, products or even custom objects. save() does an automatically commit or rollback for you.
SQL statement
$connection = $this->getConnection(); $connection->beginTransaction(); try { ... $connection->commit(); } catch (\Exception $e) { $connection->rollBack(); throw $e; }
Here we have an event triggered after place an order in Magento 2.
Event Name: sales_order_place_after
You can use this event for check the transaction data. Here we have an example will help you to understand that how we can use this event.
I hope it will help you.
Thanks
--
If answer is helpful, Please give 'Kudos' and accept 'Answer as Solution'
Thanks @PankajS_Magento & @helen_mykytej for the quick reply.
We are now clear on how we can populate data in the transaction table via the programming logic.
But could you please explain, how can we achieve this without modifying the code?
That is, if a customer/admin performs actions on Magento, at what point would the transaction table data would be available. What are the steps needed to follow? We tried placing order, adding invoice, shipment etc but the transaction table doesn't populate data.
Looking forward to your inputs on this!
Thanks!