7

I want to develop progress bar in a terminal because when I import CSV file its started to import but user has no idea how many records have been imported indicator will be like when we hit php bin/magento s:s:d -f I have added example image answer will be appreciated!

enter image description here

1 Answer 1

5

I found that Magento 2 itself using Symfony packages which is very flexible and we can customize it as per our need basis if you are in confusion to use it then only put this code in your Command extend class and fire command this will show you the terminal progress bar.

My command file path :- Namespace/ModuleName/Console/Command/CommandFile.php

use Symfony\Component\Console\Helper\ProgressBar;

// creates a new progress bar (50 units)
$progressBar = new ProgressBar($output, 50);

// starts and displays the progress bar
 $progressBar->start();

 $i = 0;
 while ($i++ < 50) {
// ... do some work

// advances the progress bar 1 unit
$progressBar->advance();

// you can also advance the progress bar by more than 1 unit
// $progressBar->advance(3);
}

// ensures that the progress bar is at 100%
$progressBar->finish();

Here you can explore it more :- https://symfony.com/doc/current/components/console/helpers/progressbar.html

Here is output of implemented task :-

6
  • Have you implemented this functionality in your instance? Can you share me the output/UI how it looks once we implement this code? May 29, 2018 at 6:03
  • Hi @Pavan please find my edited answer. May 29, 2018 at 6:26
  • Thanks a lot for your info. I want to implement this for the native product import which we do from Admin panel. As my catalog has 20K prods, once the import starts we really dont have any idea of how many prod's were imported. So for this, what needs to be done? Jun 6, 2018 at 12:16
  • Product importing from terminal is good and also much convenient user will have more idea about how many record have been imported. Jun 6, 2018 at 12:28
  • Please suggest me if you want this functionality in admin panel. Jun 6, 2018 at 12:29

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.