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.

1 Answer 1


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' => $statusCode,
        'label' => $statusLabel,
    try {
        $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()]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.