Import Manufacturers

Last modified by artistan on Fri, May 27, 2011 16:53
Source|Old Revisions  

This is an old revision of the document!

Sometime when you need to deal with import of thousands of Manufacturers, then manual data entry is really a overhead and tedious.

In such case you can follow the following simple steps for the import of manufacturers (Quick & Dirty way):


Follow the following steps:

1> Create a file in the root of magento dir: manufacturer_import.php

2> Write the following code there:

  1. <?php
  2. require_once 'app/Mage.php';
  3. umask(0);
  4. Mage::app('default');
  5. $_manufacturers = file('manufacturers.txt');
  6. $_attribute =  Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'manufacturer');
  7. $manufacturers = array('value' => array(), 'order' => array(), 'delete' => array());
  8. $i = 0;
  9. foreach($_manufacturers as $_manufacturer){
  10.     $i++;
  11.     $manufacturers['value']['option_' . $i] = array($_manufacturer);
  12. }
  13. $_attribute->setOption($manufacturers);
  14. try{
  15.     $_attribute->save();
  16.     echo 'Manufacturer successfully imported';   
  17. }catch(Exception $e){
  18.     echo 'Import Error::'.$e->getMessage();   
  19. }

3> Note i have used manufacturers.txt in the root dir with the values of manufacturers in newline format. For example:

... and so on

You can also use array instead. But above techniques comes into handy when you have hundreds of manufacturers.

4> Simply run from browser:


5> You are done.

Note: Don’t repeat 4 unless you delete those values from backend manually.

Todo: Skip the import for existing values.


You can use above snippet for any attribute with dropdown options like manufacturer:

  1. $_attribute =  Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'any-attribute-with-option-value');


MagePsycho 2011/03/16 05:04

New version for cli via Mage Shell (/shell/); CLI Importer

This one also checks for duplicates!!!