Kriuchko
8/12/2019 - 12:48 PM

*Module* - Add customer phone number

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

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

\!h /app/code/local/Theme/Customerphone/sql/customer_phone/mysql4-install-1.0.0.0.php

<?php

/* @var $installer Mage_Customer_Model_Entity_Setup */
$installer = $this;
 
$installer = $this;

$installer->startSetup();

$vCustomerEntityType = $installer->getEntityTypeId('customer');
$vCustAttributeSetId = $installer->getDefaultAttributeSetId($vCustomerEntityType);
$vCustAttributeGroupId = $installer->getDefaultAttributeGroupId($vCustomerEntityType, $vCustAttributeSetId);

$installer->addAttribute('customer', 'customer_phone_number', array(
        'label' => 'Phone number',
        'input' => 'text',
        'type'  => 'varchar',
        'forms' => array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'),
        'required' => 0,
        'user_defined' => 1,
));

$installer->addAttributeToGroup($vCustomerEntityType, $vCustAttributeSetId, $vCustAttributeGroupId, 'mobile', 0);

$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'customer_phone_number');
$oAttribute->setData('used_in_forms', array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'));
$oAttribute->save();

$tablequote = $this->getTable('sales/quote');
$installer->run("ALTER TABLE `sales_flat_quote` ADD `customer_phone_number` INT NOT NULL");

$installer->endSetup();

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

<?xml version="1.0"?>

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

\!h /app/design/frontend/rwd/theme/template/customer/form/edit.phtml

<li class="fields">
    <div class="field">
        <label><?php echo $this->__('Telephone number (optional)') ?></label>
        <div class="input-box">
            <input type="text" name="customer_phone_number" value="<?php echo $this->escapeHtml($this->getCustomer()->getData('customer_phone_number')); ?>" class="input-text" />
        </div>
    </div>
</li>