I need some help doing the following.
I am trying to import a list of manufacturers with pre-verification from the targeted store that new manufacturer to be imported does not already exist (if new manufacturer name already exist, skip) and get its new manufacturer ID if imported.
I have the code to just add manufacturer w/o checking for existing manufacturer by name nor getting the new manufacturer ID. The code is here, but I need the abilities thats stated above.
Any help would be great. Thanks in advance.
<?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();
}
?>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…