I have created a plugin which intercept the cancel function from the interface Magento\Sales\Api\OrderManagementInterface, the plugin intercept before the cancel function is called.
My problem is that when my module is activated, I can't cancel any orders, neither from the page admin/sales/order/view/order_id/10 or from the list of orders.
For example, when i click the cancel button, the text "You canceled the order." is displayed but in fact the order isn't canceled and has still the status "pending".
I have a custom table which reference the sales_order table, but the attribute referencing the table has the action on delete cascade
->addColumn( 'sales_order_id', Table::TYPE_INTEGER, 10, ['nullable' => false, 'unsigned' => true], 'Reference to entity_id of table sales_order' ) ->addForeignKey( $installer->getFkName('my_custom_table', 'sales_order_id', 'sales_order', 'entity_id'), 'sales_order_id', $installer->getTable('sales_order'), /* main table name */ 'entity_id', \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE )
But even with the action on delete cascade, before canceling an order, I'm deleting the record which is referencing to the order being cancelled.
After cancelling an order, the order is not deleted from the database and has the status cancelled, so I'm getting confused on how can my module make the cancel function bug.
The purpose of my function beforeCancel is only to remove the record with an particular id from the table referencing the sales_order table and add it into an other table having no reference.