php - Magento 将自定义字段添加到客户帐户教程问题

标签 php magento

我关注了this tutorial完全通过第 2 步。我实际上将所有文件都放在了他可以下载的设计目录中的文件到我的应用程序目录中。巧合的是,我也在尝试添加“学校”属性,到目前为止我没有改变任何东西。我在 eav_attribute 表中看到“学校”。该模块在系统>配置>高级>模块输出中列为已启用。我已经重新索引并刷新缓存,登录和注销。当我尝试编辑客户时,我仍然看不到“学校”属性。我正在使用 vs 1.7。该字段是否应在客户的“帐户信息”选项卡中找到?本教程有什么过时的地方吗?

这些都在代码下载中,但仅供引用(他缺少 php 标记的结尾,所以我也添加了这些): Controller /IndexController.php

<?php
class Excellence_Profile_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {

        $this->loadLayout();     
        $this->renderLayout();
    }
}
?>

etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Excellence_Profile>
            <version>0.1.0</version>
        </Excellence_Profile>
    </modules>
    <frontend>
        <routers>
            <profile>
                <use>standard</use>
                <args>
                    <module>Excellence_Profile</module>
                    <frontName>profile</frontName>
                </args>
            </profile>
        </routers>
        <layout>
            <updates>
                <profile>
                    <file>profile.xml</file>
                </profile>
            </updates>
        </layout>
    </frontend>
    <admin>
        <routers>
            <profile>
                <use>admin</use>
                <args>
                    <module>Excellence_Profile</module>
                    <frontName>profile</frontName>
                </args>
            </profile>
        </routers>
    </admin>
    <global>
     <fieldsets>
       <checkout_onepage_quote>
         <customer_school>
             <to_customer>school</to_customer>
         </customer_school>
       </checkout_onepage_quote>
        <customer_account>
            <school>
                <to_quote>customer_school</to_quote>
            </school>
        </customer_account>    
      </fieldsets>
    </global>
    <global>
        <fieldsets>
            <customer_account>
                 <school><create>1</create><update>1</update><name>1</name></school>
            </customer_account>
        </fieldsets>
    </global>
    <global>
        <models>
            <profile>
                <class>Excellence_Profile_Model</class>
                <resourceModel>profile_mysql4</resourceModel>
            </profile>
            <profile_mysql4>
                <class>Excellence_Profile_Model_Mysql4</class>
                <entities>
                    <profile>
                        <table>profile</table>
                    </profile>
                </entities>
            </profile_mysql4>
        </models>
        <resources>
            <profile_setup>
                <setup>
                    <module>Excellence_Profile</module>
                    <class>Mage_Customer_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </profile_setup>
            <profile_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </profile_write>
            <profile_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </profile_read>
        </resources>
        <blocks>
            <profile>
                <class>Excellence_Profile_Block</class>
            </profile>
        </blocks>
        <helpers>
            <profile>
                <class>Excellence_Profile_Helper</class>
            </profile>
        </helpers>
    </global>
</config>

模型/实体/学校

<?php
class Excellence_Profile_Model_Entity_School extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
    public function getAllOptions()
    {
        if ($this->_options === null) {
            $this->_options = array();
            $this->_options[] = array(
                    'value' => '',
                    'label' => 'Choose Option..'
            );
            $this->_options[] = array(
                    'value' => 1,
                    'label' => 'School1'
            );
            $this->_options[] = array(
                    'value' => 2,
                    'label' => 'School2'
            );
            $this->_options[] = array(
                    'value' => 3,
                    'label' => 'School3'
            );

        }

        return $this->_options;
    }
}
?>

最佳答案

这个答案对我有帮助! Adding Custom Signup Attributes in Magento 1.7

@pragnesh

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

关于php - Magento 将自定义字段添加到客户帐户教程问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17099455/

相关文章:

Magento getProductUrl() 未返回正确的 url

email - 如何知道和查找 Magento 中的所有电子邮件?

html - 在文本列中剪切标题文本

php - 在结帐页面 magento 更新产品数量

php - 如何从 javascript 发出 ajax 请求以获取核心 php 功能

php - 为什么我使用 "IntlDateFormatter"时会有这个时间差?

php - 'AND' 与 '&&' 作为运算符

Magento:将验证码添加到自定义联系表单

php - 修改SQL查询以过滤结果

php - 如何在同一个代理服务器上使用php和java apis通过webservices与远程应用服务器进行交互