I have built a Payment Module and I want to add some custom status on table sales_order_status using etc/db_schema.xml.
Is this possible?
Thank you.
Made this, hope it will answer your question.
I did that threw an install data file though
/**
* @param $statusLabel
* @param $statusCode
* @param $statusState
*/
private function addOrderStatus($statusLabel,$statusCode,$statusState){
$statusRepository = $this->statusRepository->create();
/** @var Status $status */
$this->logger->logInfo("Create Status %s",[$statusCode]);
$status = $this->statusFactory->create();
$status->setData([
'status' => $statusCode,
'label' => $statusLabel,
]);
try {
$statusRepository->save($status);
$this->logger->logSuccess("Status %s saved",[$statusCode]);
} catch (Exception $e) {
$this->logger->logError("Status %s already exist : %s",[$statusCode,$e->getMessage()]);
}
$this->logger->logInfo("Associate State %s to status",[$statusState,$statusCode]);
try {
$status->assignState($statusState, false, true);
$this->logger->logSuccess("State %s associated",[$statusState]);
} catch (Exception $e) {
$this->logger->logError("State %s not associated : %s",[$statusState,$e->getMessage()]);
}
}