在Magento 1.7中添加自定义注册属性
我在网上搜寻了一些在Magento中添加自定义注册属性的教程。虽然有一些可靠的教程,但我最喜欢的是这一个:但没有一个是针对Magento 1.7更新的 如果有人要推荐教程,或者知道在Magento 1.7.x中添加自定义注册属性所需的步骤,请告诉我在Magento 1.7中添加自定义注册属性,magento,e-commerce,Magento,E Commerce,我在网上搜寻了一些在Magento中添加自定义注册属性的教程。虽然有一些可靠的教程,但我最喜欢的是这一个:但没有一个是针对Magento 1.7更新的 如果有人要推荐教程,或者知道在Magento 1.7.x中添加自定义注册属性所需的步骤,请告诉我 我可以告诉你,我和许多其他开发人员都会非常感激,因为这个问题也已经发布在Magento论坛上,并记录在Wiki上,但遗憾的是,只适用于以前版本的Magento。作为你的上述问题,我想你的链接只适用于较低版本的Magento 下面的链接非常有用,可以在
我可以告诉你,我和许多其他开发人员都会非常感激,因为这个问题也已经发布在Magento论坛上,并记录在Wiki上,但遗憾的是,只适用于以前版本的Magento。作为你的上述问题,我想你的链接只适用于较低版本的Magento 下面的链接非常有用,可以在1.7中为您的注册过程添加自定义属性
使用
[customer registration fields magento][1]
您可以从magento根目录运行以下脚本,该脚本将属性添加到customer,并可在创建客户和编辑客户详细信息中访问,我在这里举了一个'mobile'
示例,这样您就可以使用getMobile()获得该属性
编辑客户和创建客户页面中的方法。。。。此脚本还会自动添加并显示在管理面板中。请尝试以下操作
define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';
Mage::app();
$installer = new Mage_Customer_Model_Entity_Setup('core_setup');
$installer->startSetup();
$vCustomerEntityType = $installer->getEntityTypeId('customer');
$vCustAttributeSetId = $installer->getDefaultAttributeSetId($vCustomerEntityType);
$vCustAttributeGroupId = $installer->getDefaultAttributeGroupId($vCustomerEntityType, $vCustAttributeSetId);
$installer->addAttribute('customer', 'mobile', array(
'label' => 'Customer Mobile',
'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', 'mobile');
$oAttribute->setData('used_in_forms', array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'));
$oAttribute->save();
$installer->endSetup();
在字体末尾显示属性。将以下代码添加到位于 app/design/frontend/base/default/template/customer/form/edit.phtml
<li>
<label class="required"><?php echo $this->__('Mobile') ?><em>*</em></label>
</li>
<li>
<input type="text" value="<?php echo $this->getCustomer()->getMobile(); ?>" title="<?php echo $this->__('Mobile') ?>" name="mobile" class="input-text validate-digits-range digits-range-1000000000-9999999999 required-entry">
</li>
*
我很高兴地说,我已经找到了解决我的问题的办法!在Magento论坛上发帖后,没有得到回复,我决定亲自动手解决这个问题。我希望我的解决方案能帮助其他可能遇到类似问题的Magento开发人员
1.我发现以下教程非常有用:
2.不幸的是,我的主题没有位于以下位置的register.phtml文件:app/design/frontend/default/yourtheme/template/customer/form/
3.在阅读了其他几个Stack Exchange和论坛帖子后,我发现在本例中,默认值指向位于以下位置的基:app/design/frontend/base,register.phtml文件位于/app/design/frontend/base/default/template/customer/form/register.phtml
4.以下是你们中的一些人可能遇到的问题。在认为我已经弄明白了之后,我对这个文件做了更改,但是…什么都没有,前端没有更新。我试着冲洗一下储藏室,但没用
5.所以我一直在搜索,发现register.phtml实际上存储在/app/design/frontend/base/default/template/persistent/customer/form下/
6.编辑register.phtml文件后,我开始工作了
我希望这能帮助那些遇到同样问题的人。如果您有任何问题,请随时更新此线程,我很乐意以任何方式提供帮助。此脚本为我完成了此任务!非常感谢你!他遇到麻烦了!首先:谢谢你的剧本!但是你能告诉我如何使创建的文本字段在前端可用吗?我只能在后端看到。这看起来有点黑。。。关于这方面的最佳实践有什么意见吗?