【问题标题】:Class Company\Module\Console\ImageImportConsole\Interceptor does not exist类 Company\Module\Console\ImageImportConsole\Interceptor 不存在
【发布时间】:2021-08-09 07:04:21
【问题描述】:

我正在创建一个自定义命令行来将图像从 M1 导入到 M2。

我创建了一个运行正常的命令。现在,我正在尝试调用我的助手类来进行控制台。但是出现错误 -

In ClassReader.php line 24:
Class Company\Module\Console\ImageImportConsole\Interceptor does not exist

这里是扩展命令类-

<?php
namespace Company\Module\Console;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;

class ImageImportConsole extends Command
{

    const PRODUCT_ID = 'productId'; // key of parameter

    protected $helper;

    public function __construct(
        Company\Module\Helper\Data $helper
    ) {
        $this->helper = $helper;
    }

    protected function configure(){
        $options = [
            new InputOption(
                self::PRODUCT_ID, // the option name
                '-id', // the shortcut
                InputOption::VALUE_REQUIRED, // the option mode
                'Optional Parameter. Product entity_id. It will start importing image from this id.' // the description
            ),
        ];
        $this->setName('imageimporttool:start');
        $this->setDescription('Image Import Tool');
        $this->setDefinition($options);
        parent::configure();
    }

    protected function execute(InputInterface $input, OutputInterface $output){
        $id = $input->getOption(self::PRODUCT_ID);

        // $helper = new Data();
        $this->helper->test();
        // if ($id) {
        //     // $output->writeln("Hi " . $id . ", Success!");
        // } else {
            
        // }

        $output->writeln("Success");
    }
}

当我尝试建立渐变时,出现此错误。

如何在命令中调用辅助类?

【问题讨论】:

    标签: php command magento2


    【解决方案1】:

    最后,经过一番研究,我找到了解决方案。

    我们必须通过Magento\Framework\App\State 来调用助手类。

    <?php
    namespace Company\Module\Console;
    
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    use Symfony\Component\Console\Input\InputOption;
    use Magento\Framework\App\State;
    
    class ImageImportConsole extends Command
    {
    
        const PRODUCT_ID = 'productId'; // key of parameter
    
        protected $helper;
    
        public function __construct(
            Company\Module\Helper\Data $helper,
            State $state,
        ) {
            $this->helper = $helper;
            $this->state = $state;
        }
    
        protected function configure(){
            $options = [
                new InputOption(
                    self::PRODUCT_ID, // the option name
                    '-id', // the shortcut
                    InputOption::VALUE_REQUIRED, // the option mode
                    'Optional Parameter. Product entity_id. It will start importing image from this id.' // the description
                ),
            ];
            $this->setName('imageimporttool:start');
            $this->setDescription('Image Import Tool');
            $this->setDefinition($options);
            parent::configure();
        }
    
        protected function execute(InputInterface $input, OutputInterface $output){
            $id = $input->getOption(self::PRODUCT_ID);
    
            $this->helper->test();//this we start working
    
            $output->writeln("Success");
        }
    }
    
    

    【讨论】:

      【解决方案2】:
      1. 删除vendor/ 并运行composer install
      2. 检查Company\Module\Console\ImageImportConsole\Interceptor - 它是否存在于您的项目中?也许您只是在其他地方导入了这个类,但它不存在?

      对我来说,其他一切看起来都不错。

      【讨论】:

      • 我再次尝试安装作曲家。但同样的错误。
      【解决方案3】:

      运行命令行:

      php bin/magento setup:di:compile
      php bin/magento c:f
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-27
        • 1970-01-01
        • 2019-03-17
        • 2014-03-30
        • 2022-08-20
        相关资源
        最近更新 更多