0

I've a custom command line module as follows:

<?php
namespace Test\MosIntegration\Console;

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

class FixOrders extends Command
{
    protected $_helper;
    protected $_state;

    public function __construct(
        \Test\MosIntegration\Helper\Data $helper,
        \Magento\Framework\App\State $state
    )
    {
        $this->_helper = $helper;
        $this->_state = $state;
        //$this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
        parent::__construct();
    }


    protected function configure()
    {
        $this->setName('mosaic:fixorders');
        $this->setDescription('Fix missing orders');
        $this->setDefinition([
            new InputArgument(
                'batch_id',
                InputArgument::REQUIRED,
                __("Batch Id")
            ),
        ]);

        parent::configure();
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);

    }
}

i've already set "$this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);", but when i ran setup:upgrade, the command prompt still show

  [Magento\Framework\Exception\LocalizedException]
  Area code is not set

it is very strange because i've 4 others command in another module it works fine, anyone knows what are the problems?

1
  • did you try with $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
    – S.P
    Commented Jun 13, 2022 at 11:50

1 Answer 1

0

Might be because of the area try changing for(I've always used admin area for cli command). That being said i'm not sure it will fix your issue.

    try {
        $this->state->setAreaCode(Area::AREA_ADMINHTML);
    } catch (Exception $e) {
        $output->writeln('<error>' . $e->getMessage() . '</error>');
    }
1
  • thx for the reply, i found the problem it is the helper problem, i removed the helper injection in contructor than works fine, not sure the reason.
    – hkguile
    Commented Jun 11, 2022 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.