在Magento 1.7中添加自定义注册属性

Mor*_*ton 2 magento e-commerce

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

如果有人有教程推荐或知道在Magento 1.7.x中添加自定义注册属性所需的步骤,请告诉我.

我可以告诉你,我和其他许多开发人员都会非常感激,因为这个问题也发布在Magento论坛上并记录在Wiki上,但遗憾的是只有以前版本的Magento.

Pra*_*ara 8

你可以从magento根目录运行以下脚本,这个scipt添加属性给客户,并且可以在创建客户和编辑客户详细信息中访问,例如我已经'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();
Run Code Online (Sandbox Code Playgroud)

在字体结尾显示属性.

添加以下代码,以edit.phtml位于应用程序/设计/前端/基/默认/模板/客户/表格/ 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>
Run Code Online (Sandbox Code Playgroud)

  • 这个脚本为我做了!非常感谢!遇到了麻烦! (3认同)