Posts Tagged ‘data’
Tutorial: Magento CSV Batch Product Upload
There are a few different ways to import products into Magento. The fastest way to upload lots of products is the CSV spreadsheet import. This can be done using a number of methods, but here I will explain the super-easy way. First thing we need is to get a template into which we can add our other products. Using this method we can add Simple Products.
Login to Magento and add a new product. We’ll use this as a basis for our CSV, you could add a few products making sure you set different options and setting for each to give a wider set of variables.
Export Sample CSV
The next step is to export your example products into a CSV file which you an edit and update in Microsoft Excel, or other spreadsheet application. Go to System > Import/Export > Profiles. Click on the “Export All Products” option. The default options on the wizard page should be acceptable, but double check the format type is CSV, you’ll want headers in the first row and you will want all the fields to begin with. There should be no export filters applied.
Click on the “Run Profile” tab on the left hand side, click on “Run Profile In Popup”. A page will pop-up showing the progress of the export. Once the export has completed you will have to log-into your website filesystem. Navigate to the <magento-install>/var/export in which you’ll find the CSV file. Download this onto your local computer.
Edit Original CSV Spreadsheet
Open up the file, it should open correctly in a spreadsheet application, if not right click and choose the program from the options. It will look something like the one at the top of this post. The list below are the ones you are most likley to use, with example content.
- store
- websites
- attribute_set
- type – “default”
- sku – product ID
- category_ids – “3,4,2″
- name
- short_description
- description
- price – “3.33″
- weight “1.4″
- visibility – “Catalog, Search”
- tax_class -”Taxable Goods”
- qty – “34″
- is_in_stock – “1″ for yes, “0″ for no
Simply create a new row for each of the products you wish to have in your store. Some of the columns can be duplicated (store, website, attribute_set, typpe, even category_ids) throughout your products, the rest need to be entered manually, or copied from another source. In Microsoft Excel when saving your spreadsheet select the alternative format “CSV (MSDOS)” your document should have a .csv extension like the original.
Upload Products CSV
Once you have completed your spreadsheet you’ll have to upload it to Magento, then import the products using the Import All Products profile. Go go System > Import/Export > Profiles. Click on the “Import All Products” profile, and select the “Upload File” tab, find and upload your document. Now click the profile wizard tab, again, the default settings should be fine; make sure the format is CSV.
Import Products
Select the “Run Profile” tab and choose your file from the drop-down menu. Click on the “Run Profile in Popup”, a pop-up will show your product as they are imported to the system. The original spreadsheet you created also acts as a back-up of your products. I will discuss exporting produts from Magneto at a later date, but invoices much the same Import/Export profiles.
That’s it.
PHP’s SimpleXML
SimpleXML is a PHP library extension available from PHP 5+. It enables PHP to easily access the data and structure of an SML document.
Previously DOM and DOM XML were used by PHP developers to parse XML. DOM and DOM XML requires tens of commands to do what what SimpleXML can do in a couple of lines. Furthermore, unlike DOM and DOM XML, SimpleXML creates a PHP onject which requires many fewer commands to access, read and write to the XML document structure.
The SimpleXML document needs to be created before and, if manipulated, re-created before it can be parsed using PHP. An XML document can be created from scratch using a simple PHP string..
$string = ""; $xmObject = simplexml_load_string($string);
Alternatively, a pre-created XML document can be used to create an object from file…
$xmlObject = simplexml_load_file('test.xml');
Once the script has made its additions/changes to the object, it can be exported back as XML using the following command…
$xml = new SimpleXMLElement($xmlObject);
That’s pretty much it.
MySQL’s new XML Functions
XML or Extensible Markup Language is an increasingly popular method of storing general information. To date its most widely used purpose has been feeds for various websites; but XML is much more than just an easy way to get the latest from your favourite blogs and news websites. MySQL has now introduced XML Functions allowing seamless integration of XML within a database.
A key part of this is XPath, a language specifically designed for reading information in an XML document. XPath can be used to navigate through elements and attributes in an XML document. XPath is used in conjunction with two MySQL functions which find and replace/return the data from the database.
- ExtractValue() uses two attributes to find and return specific information within an XML document in your MySQL Database.
- UpdateXML() uses three attributes to find and replace data within the XML document on the database.
I’ll be adding a post about SimpleXML for PHP which forgoes the need for a database all together.

















