我创建了一个新的字段调用子名称,这是帐户注册表单上的一个需求字段.
我有:
将表单添加到register.phtml确定并显示在表单上.
将此代码放入/local/Mage/Customer/etc/config.xml
<childname>
<create>1</create>
<update>1</update>
</childname>
Run Code Online (Sandbox Code Playgroud)
将其添加到/local/Mage/Customer/Model/Resource/Setup.php
'childname' => array(
'type' => 'varchar',
'label' => 'Please Enter Childs Name',
'input' => 'text',
'required' => true,
'visible' => true,
Run Code Online (Sandbox Code Playgroud)
我在eav_attribute表中添加了attribute_code子名设置为varchar
我运行了reg页面并查看了customer_entity_varchar,但它没有被存储?
我在某处丢失了一些代码,不确定哪个文件将数据发送到db?
任何帮助,将不胜感激 !!
提前致谢
运行Magento 1.6
我认为缺少的一件事是你需要告诉magento这个属性在表单中使用,以便它将被处理.基本上,您需要以各种形式包含它,如'customer_account_create','customer_account_edit','checkout_register','adminhtml_customer'.所以你需要在升级"sql文件"中添加如下内容:
$usedInForms = array('customer_account_create', 'customer_account_edit', 'checkout_register', 'adminhtml_customer');
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'childname');
$oAttribute->setData('used_in_forms', $usedInForms);
$oAttribute->save();
Run Code Online (Sandbox Code Playgroud)
所以,我刚刚为自己的客户做了这件事,而且它非常简单.您只需要模块中的3个文件并编辑几个phtml.
etc/config.xml,和Magento一样,你需要配置你的模块.在我们的例子中,我们只需要配置资源.这是我的整个config.xml:
<config>
<modules>
<Osdave_Custattr>
<version>0.1.0</version>
</Osdave_Custattr>
</modules>
<global>
<resources>
<custattr_setup>
<setup>
<module>Osdave_Custattr</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</custattr_setup>
<custattr_write>
<connection>
<use>core_write</use>
</connection>
</custattr_write>
<custattr_read>
<connection>
<use>core_read</use>
</connection>
</custattr_read>
</resources>
</global>
</config>
Run Code Online (Sandbox Code Playgroud)sql/custattr_setup/mysql4-install-0.1.0.php,这是将属性添加到eav属性表中的文件.正如您在config.xml中看到的那样,它会扩展Mage_Customer_Model_Entity_Setup.再次,整个文件:
<?php
$installer = $this;
$installer->startSetup();
$this->addAttribute('customer', 'erp_customer_id', array(
'type' => 'varchar',
'input' => 'text',
'label' => 'ERP Customer ID',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'default' => null,
'visible_on_front' => 1
));
if (version_compare(Mage::getVersion(), '1.6.0', '<=')) {
$customer = Mage::getModel('customer/customer');
$attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId();
$this->addAttributeToSet('customer', $attrSetId, 'General', 'erp_customer_id');
}
if (version_compare(Mage::getVersion(), '1.4.2', '>=')) {
Mage::getSingleton('eav/config')
->getAttribute('customer', 'erp_customer_id')
->setData('used_in_forms', array('adminhtml_customer', 'customer_account_create', 'customer_account_edit', 'checkout_register'))
->save();
}
$installer->endSetup();
Run Code Online (Sandbox Code Playgroud)激活xml文件,app/etc/modules/Osdave_Custattr.xml:
<?xml version="1.0"?>
<config>
<modules>
<Osdave_Custattr>
<active>true</active>
<codePool>local</codePool>
</Osdave_Custattr>
</modules>
</config>
Run Code Online (Sandbox Code Playgroud)现在我只需要编辑我想要显示新字段的phtml文件,即注册,编辑和结帐注册.这是我在app/design/frontend/mypackage/mydesign/persistent/customer/form/register.phtml中添加的内容:
<div class="fieldset">
<h2 class="legend"><?php echo $this->__('ERP Account Information') ?></h2>
<ul class="form-list">
<li>
<label for="erp_customer_id" class="required"><em>*</em><?php echo $this->__('ERP Customer ID') ?></label>
<div class="input-box">
<input type="text" name="erp_customer_id" id="erp_customer_id" value="<?php echo $this->htmlEscape($this->getFormData()->getErpCustomerId()) ?>" title="<?php echo $this->__('ERP Customer ID') ?>" class="input-text" />
</div>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
重要的是,字段的名称与属性的名称相匹配.
Yvoilá,当我注册该字段时,存放在数据库中.
通过这个,可能最好的解决方案是在开始编辑之前恢复你所做的db-and-files备份,并重现我的步骤.您必须更改名称才能与您的名称相匹配.
HTH
| 归档时间: |
|
| 查看次数: |
2497 次 |
| 最近记录: |