0

"processing", "complete", "new" are examples of the default Magento order state codes. but how to create custom order state

1

If you are creating extension then you can use below script into your InstallData.php or UpgradeData.php

 $states = [
        'test' => [
            'label' => __('test'),
            'statuses' => ['test' => ['default' => '1']],
            'visible_on_front' => true,
        ],
    ];

    foreach ($states as $code => $info) {
        if (isset($info['statuses'])) {
            foreach ($info['statuses'] as $status => $statusInfo) {
                $data[] = [
                    'status' => $status,
                    'state' => $code,
                    'is_default' => is_array($statusInfo) && isset($statusInfo['default']) ? 1 : 0,
                ];
            }
        }
    }
    $setup->getConnection()->insertArray(
        $setup->getTable('sales_order_status_state'),
        ['status', 'state', 'is_default'],
        $data
    );

Just replace test with your order state code and 'statuses' => ['test' => ['default' => '1']], replace with your order status.

You can find same script in below path,

app\code\Magento\Sales\Setup\InstallData.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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