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
< MAGENTO EAN -> D E B U G >
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
sku,ean
COOLSAUCE1,1234567001746
Honeypot-1,1234567001739
gaiterjones-1,1234567001715
HTC Touch Diamond,1234567001661
mycomputer,1234567001654
computer_fixed,1234567001647
computer,1234567001630
micronmouse5000,1234567001623
logidinovo,1234567001616
logitechcord,1234567001609
microsoftnatural,1234567001593
You can see an example of the scripts output here.
You might want to validate the generated EAN codes, specifically to validate the 13th checksum code, do this here.
Sean says:
Hello,
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.
PAJ says:
Open the .csv in a text editor and you will see the codes correctly, Excel is reformatting them as a number.
silvian says:
is the script creating an EAN attribute and assigns the EAN to that attribute ?
PAJ says:
It doesnt create the attribute but you can manually create one, export the ean data and import it into magento.
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.
http://www.amazon.com/gp/seller/asin-upc-isbn-info.html
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.
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
PAJ says:
What version of Magento are you using?
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
PAJ says:
The test code works on my Magento 1.9x dev store, do you have the full error trace?
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 1.9.0.1
Can you help me please?
Thank you, Paolo.
davide says:
i have the same problem with magento 1.9.2.4, a solution?
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…
thx