gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 18:56:09 26 4
gpt4 key购买 nike

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

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

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

最佳答案

您可以从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();

在字体末尾显示属性。

将以下代码添加到位于以下位置的 edit.phtml 文件应用程序/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.7 中添加自定义注册属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16600791/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com