2

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

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

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

4

3 回答 3

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

在 Font End 上显示属性。

将以下代码添加到位于 app/design/frontend/base/default/template/customer/form/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>
于 2013-05-17T05:19:10.533 回答
0

我很高兴地说我已经能够找到解决问题的方法!在 Magento 论坛上发帖但没有得到回应后,我决定自己解决这个问题。我希望我的解决方案能帮助其他可能遇到类似问题的 Magento 开发人员。

1.我发现以下教程非常有用: http: //www.magentocommerce.com/wiki/5__-_modules_and_development/customers_and_accounts/registration_fields

2.不幸的是,我的主题没有位于以下位置的 register.phtml 文件:app/design/frontend/default/yourtheme/template/customer/form/

3.在阅读了其他一些 Stack Exchange 和论坛帖子后,我发现在这种情况下,Magneto 默认位于:app/design/frontend/base 的基础位置,而 register.phtml 文件位于 /app/design/frontend/base/默认/模板/客户/表单/register.phtml

4.这是你们中的一些人也可能遇到的问题。在认为我已经弄清楚之后,我对这个文件进行了更改……没有,前端没有更新。我尝试刷新缓存,但没有奏效。

5.所以我一直在搜索,发现在我的情况下(可能在你的情况下!) register.phtml 实际上存储在 /app/design/frontend/base/default/template/persistent/customer/form/

6.编辑完 register.phtml 文件后,我开始做生意了

我希望这对那些遇到同样问题的人有所帮助。如果您有任何问题,请随时更新此线程,乐于以任何方式提供帮助。

于 2013-05-23T04:15:53.193 回答
0

作为您的上述问题,我认为您的链接仅适用于较低版本的 magento

下面的链接将非常有用,可以在 1.7 中将自定义属性添加到您的注册过程中

利用[customer-registration-fields-magento][1]

于 2013-05-17T04:11:53.360 回答