How to Create Magento 2 Progress Bar For Files Import

Magento 2 Development; Magento 2 tutorial

In the following post, we explore how to create a progress bar for importing files into Magento 2. The article is based on the StackExchange question by Manish Goswami as well as our developing practices. Let’s take a look at the solution proposed on StackExchange and then explore an alternative way.

Magento 2 Import Progress Bar in Terminal

Manish wanted to develop a progress bar in a terminal. When he imports CSV files, it’s absolutely uncertain how many records have been imported and how much work is left to be done. As an example of what he wants, Manish tells about php bin/magento s:s:d -f and provides the following image:

The proposed solution is described below. Since Magento 2 uses Symfony packages, it is possible to implement several customizations. You need to put the following code in your Command extend class and run the command. As a result, you will get a progress bar displayed in the terminal.

The typical command file path is

Namespace/ModuleName/Console/Command/CommandFile.php

The code itself is

The output of the implemented task should look as follows:

For further information on how to get the terminal progress bar for Magento 2 import, follow this link: Magento 2 Terminal Progress bar while uploading csv file from terminal. To explore Symphony in more details, go here: Symphony Progress Bar.

Magento 2 Import Progress Bar in Backend

To get a progress bar in your backend, we recommend you to install the Improved Import & Export Magento 2 extension. It adds the desired element to the corresponding section of your website so that you can control the import processes. Furthermore, the same progress bar is added to the appropriate export section of the module. As a result, you get a Magento 2 export progress bar in the backend as well after installing the module.

To get the extension, follow this link:

Get Improved Import & Export Magento 2 Extension

But let’s be honest: you need a progress bar just because the default Magento 2 import is extremely slow.  Luckily, the Improved Import & Export Magento 2 extension completely revamps the default algorithms, so both import and export processes take much less time than in case of the native instruments of Magento 2. What other benefits over the default import/export processes does the module provide?

Improved Import/Export Processes

The following section of the article explores revolutionary features of the Improved Import & Export Magento 2 extension. We’ve studied the approach provided in the StackExchange question and answer and decided to emphasize benefits over the described method that you will get by using our module.

CLI Import/Export

Although you no longer need to work with the terminal to run import & export processes after installing the Improved Import & Export extension, the module still offers such an opportunity. You can explore the corresponding commands here: Run Import/Export Jobs Via CLI. Why is it unnecessary to use the terminal, you will ask? Find the answer below.

Schedules

The Improved Import & Export Magento 2 extension utilizes cron. It means that you can create any custom schedule of updates fully automating your updates. Due to a user-friendly interface, it’s no longer a problem to schedule an import process repeating it within the specified interval. The advanced flexibility of our module lets you satisfy every business requirement when it comes to the frequency of updates.

If you don’t want to deal with the cron syntax, we offer an alternative way to schedule your import & Export processes. The Improved Import & Export Magento 2 extension offers a list of the predefined intervals. Simply choose one that suits your goals. Note that every interval can be customized. Thus, you will easily tailor it according to your e-commerce needs.

At the same time, the module lets you create import & export jobs that can be run in a manual mode only. They are especially useful if a certain integration doesn’t offer any certain frequency of updates, but you need to import the offered data right after it was provided.

Also, note that despite the schedule, you can always start an update asynchronously, importing/exporting data any time before or after the planned date and time.

The following gif image illustrates the possibilities described above:

Mapping

Unfortunately, you cannot fully automate data updates until attributes of the imported files are matched to the internal Magento 2 attributes. In the case of the aforementioned terminal import, you should edit a data file manually before every update. As for the Improved Import & Export module, it dramatically simplifies your daily routine related to this process.

Our extension lets you create a mapping scheme right within the admin. You match attributes to each other, save the import job, and the extension applies the creates scheme for all further data imports. Thus, you not only avoid manual data file editing but also eliminate the necessity to repeat the same procedure before every import. One time configuration is enough to solve multiple headaches caused by different attribute standards used by Magento 2 and external systems.

And attributes matching with the Improved Import & Export extension is much easier than the default file editing. Just look at it:

Attribute mapping

Furthermore, if you need to update data from an external source that is fully supported by our module, it is possible to apply one of the premade mapping presets. Our team creates mapping schemes for certain integrations reducing the complexity of attributes matching to the following few clicks:

If there is no presets that satisfy your particular business case, ask our team to create them.

Connectivity

While Manish was talking about a progress bag for Magento 2 CSV import, we should tell a few more words about the advanced connectivity options provided by the Improved Import & Export Magento 2 extension. Our module supports not only CSV but also XML and JSON. It means that you can freely import and export data to or from your store using one of these file standards. Thus, it is no longer necessary to rely on third-party tools converting JSON to the supported format.

You also get the ability to use multiple file sources:

  • FTP/SFTP support allows using a local or remote server;
  • Dropbox support allows transferring files to/from the cloud storage;
  • Direct URL uploads allow importing data files right via a direct link to them.

Also, note that all compressed files are unzipped automatically when you import them to Magento 2 with the help of the Improved Import & Export extension.

In addition to data file transfers, our module also offers the ability to import data from Google Sheets or synchronize your store with an external system using REST API. For further information about both features, follow the link below the article. Don’t hesitate to contact our support for more details. You can also explore the functionality of the Improved Import & Export Magento 2 extension by watching the following video:

Conclusion

Now, you know two ways of creating a Magento 2 import progress bar: for the terminal and the Magento admin. Furthermore, you can get a similar interface element for export processes. And don’t forget about the improved performance, advanced usability, and full automation of updates that the Improved Import & Export Magento 2 extension offers. 

For more useful articles, check our Cookbook.

Get Improved Import & Export Magento 2 Extension