Every week, we get about 2 requests from customers asking us to import their products’ database (in a CSV format) into VirtueMart on their Joomla website. Usually, every customer has the following 4 columns (fields) in his CSV file:
- Product Name
- Product Description
- Product Price
- Product Category
The remaining columns differ based on the customer’s business. But usually, the above 4 columns are pretty much standard. Almost every customer tells us the same story: He created a CSV file containing all his products, he installed a Joomla Extension called CSVI VirtueMart (CSVI stands for “Comma Separated Values Improved”), and he tried to import the CSV into his VirtueMart database tables by using the aforementioned extension. In many cases, not only the import did not work, but it also corrupted the VirtueMart tables (which means that the user had to revert from a previous backup to fix the affected tables).
The problem is that CSVI VirtueMart is made with the programmer in mind, and it also expects the following for the import to be successful:
- Columns to be in specific positions inside the CSV file
- Data is escaped properly
- CSV file is an actual file, and not an Excel file
In addition to the above, CSVI VirtueMart‘s import functionality is very poor, as it’s unable to import advanced data such as custom fields. (size, options, etc…) Not to mention that it’s also unable to import nested categories and product images. All in all, using CSVI VirtueMart to import the data for your products can be a very painful process and it might just take you days to do the import properly (that is if you don’t run into issues where CSVI VirtueMart completely corrupts your existing VirtueMart data). We think that CSVI VirtueMart did a great job simplifying the process, but the import functionality is still not stable and can be potentially dangerous to your data and your website.
So, what is the solution? Well, the solution to importing a CSV file into VirtueMart is either developing a PHP script yourself that will do this or hiring a Joomla Expert in order to do this for you.
In essence, here’s what you or the Joomla expert should do:
- Create a PHP file that will read the CSV file using the function fgetcsv
- Loop through the array resulting from reading your CSV file and insert the data into the appropriate VirtueMart tables
- That’s it!
Doing the above is not an easy task (although it seems like it is). This is because you need to ensure that your data is read properly and inserted properly into the appropriate tables. What if you have a product that belongs to multiple categories? What if you have a product with one or more attributes? (such as T-Shirt size or T-Shirt color) What if you have a product with a complex discount structure?
Of course, the process can be more complicated if you want to import images as well. The easiest (yet still complicated) way of doing this is to create another PHP script that will import a zip file which contains the images of your products where each image is named after a product. For example, if you have a product called “White Teddy Bear”, then the associated image should be named “white-teddy-bear.jpg”. This will ensure that the script is able to associate the image with the product. So, in short, the script should extract the zip file to a temporary directory, intelligently associate the images with their respective products, and finally move the images to the right folder that contains the images of all the VirtueMart products. Needless to say, importing the images should happen after importing the products.
As you can see from the above, the concept is not that hard, but the application can be quite challenging, especially when you have lots of products, your products’ data is not consistent, and your products have images with names resembling, but not identical, to the names of the products. A Joomla expert can take 1 to 2 days creating the import script(s) and testing them – depending on your data and your requirements.
If you need help importing a CSV file into VirtueMart, then look no further: We are very experienced in Joomla and we are always ready and eager to help you. Just contact us and we’ll take it from there!
That’s a pure truth, indeed. CSV improved is poor, dangerous (tested on humans). Really, the better way may be to write own script. Or if you are capable to do it – to improve its code!