Pergunta

I have a client who would like to add the option 'Transgender' in addition to Male and Female in the gender field.

Can I do this directly in the database? Would I need to update anything beyond the following tables:

eav_attribute_option
eav_attribute_option_value

I'm on CE 1.7

Thanks

Foi útil?

Solução

Can you do this in the database? Yes. Should you? No.

Rule #1 about Fight Magento Club - Never touch the database directly.

So create an install script. There are dozens of tutorials out there for that. Once you have that set up, the process isn't dissimilar from adding options to other EAV option types:

<?php


$installer = $this;

/* @var $installer Mage_Customer_Model_Entity_Setup */
$installer->startSetup();

$tableOptions        = $installer->getTable('eav_attribute_option');
$tableOptionValues   = $installer->getTable('eav_attribute_option_value');

// add options for level of politeness
$attributeId = (int)$installer->getAttribute('customer', 'gender', 'attribute_id');


// add option
$data = array(
    'attribute_id' => 'Non-Binary, Prefer not to say',
    'sort_order'   => 99,
);
$installer->getConnection()->insert($tableOptions, $data);

// add option label
$optionId = (int)$installer->getConnection()->lastInsertId($tableOptions, 'option_id');
$data = array(
    'option_id' => $optionId,
    'store_id'  => 0,
    'value'     => $label,
);
$installer->getConnection()->insert($tableOptionValues, $data);



$installer->endSetup();

Outras dicas

I think this is also same as query. Since above code is only about getting those two tables and simply inserting values.THere are no any magento method call in the above script.

If he is a developer with mysql he can do simply through database queries.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top