在Magento 1.7中添加自定义注册属性 [英] Adding Custom Signup Attributes in Magento 1.7

查看:68
本文介绍了在Magento 1.7中添加自定义注册属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索了有关在Magento中添加自定义注册属性的教程.虽然有一些可靠的教程,但我最喜欢的是:自定义客户注册属性,但未更新Magento 1.7.

I have scoured the web for tutorials for adding custom signup attributes in Magento. While there are a few solid tutorials out there, my favorite being this one: custom customer signup attributes but none are updated for Magento 1.7.

让我知道是否有人有推荐的教程,或者知道在Magento 1.7.x中添加自定义注册属性的必要步骤.

Let me know if anyone has a tutorial to recommend or knows the steps necessary to add custom signup attributes in Magento 1.7.x.

我可以告诉你,我和其他许多开发人员将非常感激,因为这个问题也已经发布在Magento论坛上并记录在Wiki中,但可悲的是,仅适用于以前版本的Magento.

I can tell you that myself and many other dev's will be incredibly grateful since this question has also been posted on the Magento forums and documented on the Wiki but sadly only for previous versions of Magento.

推荐答案

您可以从magento根目录运行以下脚本,此scipt向客户添加属性,可在创建客户和编辑客户详细信息时访问,例如我已使用'mobile'在这里,您可以使用getMobile()方法在编辑客户中创建该属性并创建客户页面....此脚本还会自动添加并显示在管理面板中.

you can run following script from magento root directory, this scipt add attribute to customer and accessible in create customer and edit customer detail, example i have taken 'mobile' here so you can get that attribute using getMobile() method in edit customer and create customer page.... this script also automatically add and display in admin panel try these..

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();

在字体结尾"上显示属性.

将以下代码添加到位于以下位置的 edit.phtml 文件中 app/design/frontend/base/default/template/customer/form/edit.phtml

Display attribute on Font End.

add following code to edit.phtml file located at 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 1.7中添加自定义注册属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆