Hi,
I want to create new order status adapted to me, but instead of create them from the Magento backend interface, I want to do it by a Magento module.
I have created the module folder /myMagento2/app/code/Magento/Orderstatus and adding /myMagento2/app/code/Magento/Orderstatus/registration.php file:
<?php
use \Magento\Framework\Component\ComponentRegistrar;
use \Zend\Log\Writer\Stream;
use \Zend\Log\Logger;
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/newstatuses_setup.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('REGISTRATION');
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Newstatuses',
__DIR__
);
I have also created /myMagento2/app/code/Magento/Orderstatus/etc and adding /myMagento2/app/code/Magento/Orderstatus/etc/module.xml file:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Newstatuses" setup_version="1.0.0">
</module>
</config>
Finally, I have created /myMagento2/app/code/Magento/Orderstatus/Setup/InstallData.php:
<?php
namespace Magento\Orderstatus\Setup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\DB\Ddl\Table;
use \Zend\Log\Writer\Stream;
use \Zend\Log\Logger
class InstallData implements InstallDataInterface {
/**
* Installs DB schema for a module
*
* @param SchemaSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{ $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/modulename_setup.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('INIT');
$installer = $setup;
$installer->startSetup();
$data[] = ['status' => 'approved', 'label' => 'Approve'];
$data[] = ['status' => 'disapproved', 'label' => 'Disapprove'];
$setup->getConnection()->insertArray($setup->getTable('sales_order_status'), ['status', 'label'], $data);
$setup->endSetup();
}
}That code is an example from https://webkul.com/blog/create-custom-order-status-programatically-in-magento2/ . I have put logs inside de code and only the registration.php set log in the log file when I execute bin/magento setup:upgrade. I have deleted the module from the setup_module each time I run upgrade, but logs in registration.php file never print.
Any suggestions, please?
Thanks in advances!
Solved! Go to Solution.
Hello @tury_electro
In /myMagento2/app/code/Magento/Orderstatus/registration.php file
On line 14, change 'Newstatuses' to ‘Magento_Orderstatus’
In /myMagento2/app/code/Magento/Orderstatus/etc/module.xml file:
On line 4, change
<module name="Newstatuses" setup_version="1.0.0">
to
<module name="Magento_Orderstatus" setup_version="1.0.0">
Hope it helps.
Hello @tury_electro
In /myMagento2/app/code/Magento/Orderstatus/registration.php file
On line 14, change 'Newstatuses' to ‘Magento_Orderstatus’
In /myMagento2/app/code/Magento/Orderstatus/etc/module.xml file:
On line 4, change
<module name="Newstatuses" setup_version="1.0.0">
to
<module name="Magento_Orderstatus" setup_version="1.0.0">
Hope it helps.