I created a custom CLI command where I have to delete the order Items using the Order Increment ID, Item SKU.

I used the ask() method after executing the command php bin/magento webkul:orderDelete when this command runs then it asks for the admin to add the increment ID: After adding the integer ID I couldn't able to fetch what admin input in the terminal

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        // $helper = $this->getHelper('question');
        $orderId = $input->getArgument(self::ORDER_ARGUMENT);
        $allowAll = $input->getOption(self::ALLOW_ALL);
        $orderAllColl = $this->orderCollectionFactory->create();  //Get Order Collection
        foreach ($orderAllColl as $orderCollData) {
            $order = $this->_orderRepository->get($orderCollData->getEntityId());
            $orderIncrementId[] = $order->getIncrementId();                        //Delete Order
                // echo print_r($matchId);
             $question = $objectManager->create('\Symfony\Component\Console\Question\ConfirmationQuestion', ['question'=>'Please enter the Order Increament Id:', 'default' => FALSE]);
        $helper = $this->getHelper('question');
             $ans = $helper->ask($input, $output, $question);
             echo 'abc'.$ans;

I am not able to get any data in the $ans variable after pressing Enter adding the increment ID of the order.

Can you please help me with how can I get the input value in the variable that I am accessing?

Thank you

1 Answer 1

protected function execute(InputInterface $input, OutputInterface $output)
        $question = $this->_objectManager->create('\Symfony\Component\Console\Question\ConfirmationQuestion', ['question'=>'your question', 'default' => FALSE]);
        $helper = $this->getHelper('question');
        echo $ans = $helper->ask($input, $output, $question);
        if ($ans == 'yes') {
           $output->writeln('Hello World!');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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