Generate EAN Barcodes for All Magento Products – Magento EAN Barcode Generator

created October 10, 2012, last updated June 23, 2014.

closeThis post was last updated 10 years 2 months 12 days ago, some of the information contained here may no longer be actual and any referenced software versions may have been updated!

Generate EAN Barcodes for All Magento Products

Following on from my post about mass exporting Magento data, I had the requirement to also mass generate EAN13 barcodes from scratch for all Magento products in a store.

The barcode graphic functionality came courtesy of Folke Ashberg and I simply added the functionality to my basic export php script.

The script creates the EAN code and checksum (currently programmed for EAN13) using the a 5 digit product number derived from the Magento product id and your registered manufacturer code. The barcode image is generated on the fly and cached locally.

My requirement was to generate the EAN code and not the barcode image so I am not 100% if the image is to the EAN standard, I think the font may need to be changed, however if you require EAN numbers and images, e.g. for Amazon etc. then this is a good place to start!

Magento EAN Generator

You can download a standalone version of my Magento EAN Generator from GitHub here. Install the code in a web accessible folder, or in your Magento installation folder. Open the application config file and configure the correct path to your Magento installation. Also configure your EAN prefix code.

Run the script by browsing to http://www.yoursite/eaninstallfolder/ean.php?export, this will generate a delimited txt file containing SKU and EAN13 code for all visible products in your store.

Or run the script from the command line using

php php.ean debug

Exporting EAN data for 64 Magento product/s …
Data file created at /home/www/dev/magento/myexport/eanexporttest.csv
Export finished.


Configure a writeable folder for the data file in config.

The CSV file contains the EAN data

HTC Touch Diamond,1234567001661

You can see an example of the scripts output here.

Auto Generated Magento Product EAN13 Barcode


You might want to validate the generated EAN codes, specifically to validate the 13th checksum code, do this here.


  1. Sean says:


    I used this to generate a CSV. How ever when I open it in excel it only shows
    sku ean
    IF-402303 1.23456E+11
    IF-402315 1.23456E+11
    IF-402300 1.23456E+11
    IF-402311 1.23456E+11

    Any ideas on how to get the barcodes to show up with product names.

  2. Steve Brown says:

    In order to use your scrip do I actually need to buy EAN codes from a legitimate source? Or can I just create/start with a random 13 digit number? I would like to use EAN codes on our Magento site in cooperation with Amazon integration plugin.

    On Magento Admin portal I keep getting an “Invalid EAN code” upon attempting to “Add to Marketplace” my product.

    • PAJ says:

      You can generate dummy EAN numbers if you like with any prefix codes you want, for them to be valid your company needs to be registered and assigned a valid prefix code.

  3. willard says:

    Hi I installed your great script, but sadly it returns the following error. The paths are correct, I double ckecked.

    Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::getType() in /home/pannen/public_html/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php on line 445

    • andrei says:

      yes same error here: Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::getType() in C:\xampp2\htdocs\tibbis\app\code\core\Mage\Eav\Model\Entity\Collection\Abstract.php on line 445

      I’m useing Magento 1.8.

      Any ideas?

      Thank you

  4. Paolo Gatti says:

    Hello, I have this error:

    Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Product_Flat::getType() in /home/pannen/public_html/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php on line 445

    I’m using Magento CE

    Can you help me please?

    Thank you, Paolo.

  5. Art van Delay says:

    Hi gaitorjones!
    Thank you for your code. It´s fantastic…Unfortunately I only get half of my product list.
    Any switches to export all products, despite activeted / deactivated, or any clue…


This site uses Akismet to reduce spam. Learn how your comment data is processed.