Magento - 将自定义属性添加到扩展核心Customer模块

时间:2012-08-08 08:42:09

标签: magento-1.4 magento-1.5 magento-1.6 magento

您必须向客户添加自定义属性。所以我扩展了核心Customer模块,这些是涉及的文件和目录树:

//app/code/local/Nauba/etc/config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Nauba_Customer>
        <version>0.0.1</version>
    </Nauba_Customer>
</modules>

<global>
    <models>
        <customer>
            <rewrite>
                <customer>Nauba_Customer_Model_Customer</customer>
            </rewrite>
        </customer>
    </models>     
</global>   
</config>


 // app/code/local/Nauba/Customer/Model/Customer.php

class Nauba_Customer_Model_Customer extends Mage_Customer_Model_Customer
{
    function _construct()
    {
        parent::__construct();
    }
}




// app/etc/modules/Nauba_Customer.xml

<?xml version="1.0"?>
<config>
<modules>
    <Nauba_Customer>
        <active>true</active>
        <codePool>local</codePool>
   </Nauba_Customer>
</modules>
</config>






//app/code/local/Nauba/Customer/sql/nauba_customer_setup/mysql4-upgrade-1.6.2.0.2-1.6.2.0.3.php

$installer = $this;
$installer->startSetup();
/**
 * Adding custom attributes to customer
 */

$installer->addAttribute('customer', 'elite_invitation', array(
    'label'             => 'ID prodotto invito Elite',
    'type'              => 'varchar',
    'visible'           => true,
    'visible_on_front'  => false,
    'required'          => false,
    'backend'           => '',
    'frontend'          => '',
    'input'             => 'text',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE
));


$installer->endSetup();

现在启用模块并使用新的自定义模型而不是核心Mage_Customer,但不执行sql升级。任何错误的想法?

thanx luke

1 个答案:

答案 0 :(得分:1)

您必须在全局

下的xml中定义“资源”
    <resources>
      <nauba_customer_setup>
         <setup>
             <module>your module name</module>
         </setup>
      </nauba_customer_setup>
     </resources>