Tuesday, 6 November 2012

Magento - Import Manufacturers

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

2> Write the following code there:

 

<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('default');
$_manufacturers = file('manufacturers.txt');
$_attribute =  Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'manufacturer');
$manufacturers = array('value' => array(), 'order' => array(), 'delete' => array());
$i = 0;
foreach($_manufacturers as $_manufacturer){
$i++;
$manufacturers['value']['option_' . $i] = array($_manufacturer);
}
$_attribute->setOption($manufacturers);
try{
$_attribute->save();
echo 'Manufacturer successfully imported';
}catch(Exception $e){
echo 'Import Error::'.$e->getMessage();
}
?>

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



Dell
Toshiba
Sony
Fujitsu



No comments:

Post a Comment