0

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');
        if(isset($helper)){
             $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

0
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!');
        }else{
            $output->writeln('Noooooooo');
        }
        $output->writeln('Done!');
    }

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.