Last active
May 24, 2023 15:10
-
-
Save magevision/e1ac2bbd93704500c4b983fdba7dd475 to your computer and use it in GitHub Desktop.
AddCustomOrderStatusProgrammatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace MageVision\Blog88\Setup\Patch\Data; | |
use Magento\Framework\Setup\ModuleDataSetupInterface; | |
use Magento\Framework\Setup\Patch\DataPatchInterface; | |
use Magento\Sales\Model\Order; | |
class CreateCustomOrderStatus implements DataPatchInterface | |
{ | |
private const STATUS_CODE = 'custom_status'; | |
private const STATUS_LABEL = 'Custom'; | |
private ModuleDataSetupInterface $moduleDataSetup; | |
/** | |
* @param ModuleDataSetupInterface $moduleDataSetup | |
*/ | |
public function __construct( | |
ModuleDataSetupInterface $moduleDataSetup | |
) { | |
$this->moduleDataSetup = $moduleDataSetup; | |
} | |
/** | |
* @inheritDoc | |
*/ | |
public function apply() | |
{ | |
$this->moduleDataSetup->startSetup(); | |
$this->moduleDataSetup->getConnection()->insert( | |
$this->moduleDataSetup->getTable('sales_order_status'), | |
[ | |
'status' => self::STATUS_CODE, | |
'label' => self::STATUS_LABEL | |
] | |
); | |
$this->moduleDataSetup->getConnection()->insert( | |
$this->moduleDataSetup->getTable('sales_order_status_state'), | |
[ | |
'status' => self::STATUS_CODE, | |
'state' => Order::STATE_PROCESSING, | |
'is_default' => 0, | |
'visible_on_front' => 1 | |
] | |
); | |
$this->moduleDataSetup->endSetup(); | |
} | |
/** | |
* @inheritDoc | |
*/ | |
public static function getDependencies() | |
{ | |
return []; | |
} | |
/** | |
* @inheritDoc | |
*/ | |
public function getAliases() | |
{ | |
return []; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment