Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Adicionando atributos dropdown programaticamente, com opções
 
albertobraschi
Member
 
Avatar
Total Posts:  43
Joined:  2008-09-06
Curitiba/PR
 

Para quem precisa adicionar atributos dropdown com muitas opções, esse script cai como uma luva.

<?php
define
('MAGENTO'realpath('/var/www/magento'));
ini_set('memory_limit''128M');

require_once 
MAGENTO '/app/Mage.php';

Mage::app();

$model Mage::getModel('catalog/entity_attribute');

$model->setAttributeCode('mediaFormat');//attribute code
$model->setIsComparable(0);
$model->setIsConfigurable(0);
$model->setIsFilterable(0);
$model->setIsFilterableInSearch(0);
$model->setIsGlobal(0);
$model->setIsRequired(0);
$model->setIsSearchable(0);
$model->setIsUnique(0);
$model->setIsUsedForPriceRules(0);
$model->setIsVisibleInAdvancedSearch(0);
$model->setIsVisibleOnFront(0);
$model->setDefaultValueYesno(0);
$model->setUsedInProductListing(0);

$model->setFrontendInput('multiselect'); //make it a multiselect/dropdown
//0 is the admin value, 1 is the "default store view" (frontend) value
$frontEndLabel=array('0'=>'Media Format',
                      
'1'=>'Media Format');

$model->setFrontendLabel($frontEndLabel);
//0 is the admin value, 1 is the "default store view" (frontend) value
$optionData = array('value' =>
                        array(
'option_0'=>array('0'=>'dvd','1'=>'dvd'),
                              
'option_1'=>array('0'=>'vhs','1'=>'vhs'),
                              
'option_2'=>array('0'=>'blue-ray','1'=>'blue-ray')
                        )
                    ,
                    
'order' =>
                        array(
'option_0'=>1,
                              
'option_1'=>2,
                              
'option_2'=>3)
               );
$model->setOption($optionData);


$data['backend_model''eav/entity_attribute_backend_array';
$data['apply_to'= array();
$model->addData($data);
$model->setEntityTypeId(Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId());
$model->setIsUserDefined(1);
var_dump($model);

try 
{
    $model
->save();
}
catch(Exception $e{
    
echo $e->getMessage();
}
?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
caputmundi
Sr. Member
 
Avatar
Total Posts:  174
Joined:  2010-01-05
 

Este script es para agregar desplegable para seleccionar más de una vez?

Parece que no puedo en vez de usar el atributo fabricante sin necesidad de utilizar la lista desplegable.
Tengo el problema de los productos de carga de csv con la inclusión del fabricante, y la lista desplegable no cobra si uso el campo de texto pero no de búsqueda, hacer?

 
Magento Community Magento Community
Magento Community
Magento Community
 
papiga01
Jr. Member
 
Total Posts:  25
Joined:  2010-02-18
 

hi albertobraschi,

its a very good script, but how to set \’blue-ray\’ as Default-value ?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top