I'm using a piece of code to add dropdown values to a specific attribute. The code I'm using is:
<?php
require "app/Mage.php";
umask(0);
Mage::app();
$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
$values = array("test4","test5","test6");
$attrCode = 'myattribute';
$values = array_map('utf8_encode',$values);
$iProductEntityTypeId = Mage::getModel('catalog/product')->getResource()->getTypeId();
$aOption = array();
$aOption['attribute_id'] = $installer->getAttributeId($iProductEntityTypeId, $attrCode);
for($iCount=0;$iCount<sizeof($values);$iCount++){
$aOption['value']['option'.$iCount][0] = $values[$iCount];
}
$installer->addAttributeOption($aOption);
$installer->endSetup();
?>
This works perfectly for new values. However I'm going to use an exported CSV with all data to import into the attribute meaning that values that already have been added shouldn't be added anymore. When I run the above script twice, all 3 values are added twice while in fact nothing should be added when run for the second time.
How should I change this script to make this possible?