"processing", "complete", "new" are examples of the default Magento order state codes. but how to create custom order state
-
Accept the answer If you find my answer helpful@Nikhil– Keyur ShahNov 14, 2017 at 15:12
-
magento.stackexchange.com/questions/149089/…– KoluilkualeJun 14, 2018 at 10:37
1 Answer
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