1、首先在当前模块的etc/di.xml增加配置例如:
<type name="Magento\Framework\Console\CommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="Products" xsi:type="object">Pao\PaymentExt\Console\Products</item>
</argument>
</arguments>
</type>
2、然后在当前模块新建Console/Products 继承 Symfony\Component\Console\Command\Command 实现execute和configure方法
protected function execute(InputInterface $input, OutputInterface $output)
{
//写上你要实现的代码
}
protected function configure(){
$this->setName("Set:Products");//命令的名字
$this->setDescription('Saaaaa');//命令的描述
parent::configure();
}
3、在安装目录执行更新模块:php bin/magento:setup:upgrade
4、在安装目录执行 php bin/magento查看是否正常添加