Kriuchko
8/12/2019 - 10:06 AM

*Module* - Add custom gender option for customer

\!h /app/code/local/Theme/Genderoptions/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Theme_Genderoptions>
            <version>1.0.0.0</version>
        </Theme_Genderoptions>
    </modules>
    <global>
        <resources>
            <custom_gender_options>
                <setup>
                    <module>Theme_Genderoptions</module>
                    <class>Mage_Customer_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </custom_gender_options>
        </resources>
    </global>
</config>

\!h /app/code/local/Theme/Genderoptions/sql/custom_gender_options

<?php

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

$tableOptions        = $installer->getTable('eav_attribute_option');
$tableOptionValues   = $installer->getTable('eav_attribute_option_value');
$attributeId = (int)$installer->getAttribute('customer', 'gender', 'attribute_id');
$data = array(
    'attribute_id' => $attributeId,
    'sort_order'   => 2,
);
$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'     => 'Company',
);
$installer->getConnection()->insert($tableOptionValues, $data);

\!h /app/etc/modules/Theme_Genderoptions.xml

<?xml version="1.0"?>

<config>
    <modules>
        <Theme_Genderoptions>
            <active>true</active>
            <codePool>local</codePool>
        </Theme_Genderoptions>
    </modules>
</config>