Skip to content

Instantly share code, notes, and snippets.

@keithgreer
Last active December 23, 2021 10:24
Show Gist options
  • Save keithgreer/a19e4b770766a17d7e8758d20bd3db8f to your computer and use it in GitHub Desktop.
Save keithgreer/a19e4b770766a17d7e8758d20bd3db8f to your computer and use it in GitHub Desktop.
M1: Import Values to Dropdown/Multiple Select Attributes - https://keithgreer.dev/import-values-to-dropdownmultiple-select-attributes
<?php
require_once '../app/Mage.php';
umask(); Mage::app('default');
$_manufacturers = file('import.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 'Attribute values successfully imported';
} catch(Exception $e){
echo 'Import Error::'.$e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment