Forked from ViniciusAugusto/Magento Add Attribute Options Programmatically
Created
March 23, 2017 08:38
-
-
Save jwohlfeil/f0ba87e17d910fe326f87d7c71db3036 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('app/Mage.php'); //Path to Magento | |
error_reporting(E_ALL); | |
ini_set("display_errors", 1); | |
umask(0); | |
Mage::app(); | |
$cores = array('AZUL CLARO', | |
'AZUL MARINHO', | |
'BEGE', | |
'BRANCO', | |
'CARAMELO', | |
'JEANS', | |
'LILÁS', | |
'MARROM', | |
'PRETO', | |
'ROSA', | |
'ROSA PINK', | |
'VERMELHO', | |
'VERMELHO ESCURO', | |
'VINHO' | |
); | |
addColor($cores); | |
function addColor($cores){ | |
$arg_attribute = 'color'; | |
$attr_model = Mage::getModel('catalog/resource_eav_attribute'); | |
$attr = $attr_model->loadByCode('catalog_product', $arg_attribute); | |
$attr_id = $attr->getAttributeId(); | |
foreach ($cores as $cor) { | |
echo $cor."<br />"; | |
$arg_value = $cor; | |
$option['attribute_id'] = $attr_id; | |
$option['value']['any_option_name'][0] = $arg_value; | |
$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); | |
$setup->addAttributeOption($option); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment