【问题标题】:magento add custom input field to customer account form in adminmagento 将自定义输入字段添加到管理员中的客户帐户表单
【发布时间】:2011-03-03 19:48:41
【问题描述】:

我正在尝试将自定义输入字段添加到管理员中客户的帐户信息选项卡。我已经成功地在 eav 表中为我的输入创建了一个自定义属性,但未能成功找到如何让我的输入显示出来。好奇的人有任何关于如何做到这一点的好资源吗?

【问题讨论】:

    标签: php magento magento-1.4


    【解决方案1】:

    上面的链接已经失效了。我在 http://www.excellencemagentoblog.com/customer-registration-fields-magento1-6 找到了更好的解释。如果您只执行第一步,您将只在管理员中添加添加的字段。

    【讨论】:

      【解决方案2】:

      最快的方法是创建一个php文件并通过浏览器访问它,将以下内容添加到文件中。

      define('MAGENTO', realpath(dirname(__FILE__)));
      ini_set('memory_limit', '32M');
      set_time_limit (0);
      require_once MAGENTO . '/../app/Mage.php';
      Mage::app();
      
      $newFields = array(
          'custom_attribute' => array(
              'type'              => 'text',
              'label'                => 'Customer Custom Attribute'
          )
      );
      
      $entities = array('customer');
      
      $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
      foreach($newFields as $attributeName => $attributeDefs) {
          foreach ($entities as $entity) {
              $setup->addAttribute($entity, $attributeName, array(
                  'position'          => 1,
                  'type'              => $attributeDefs['type'],
                  'label'             => $attributeDefs['label'],
                  'global'            => 1,
                  'visible'           => 1,
                  'required'          => 0,
                  'user_defined'      => 1,
                  'searchable'        => 0,
                  'filterable'        => 0,
                  'comparable'        => 0,
                  'visible_on_front'  => 1,
                  'visible_in_advanced_search' => 0,
                  'unique'            => 0,
                  'is_configurable'   => 0,
                  'position'          => 1,
              ));                
          }
      }
      

      【讨论】:

      • 谢谢,我试试看!
      【解决方案3】:

      你必须告诉属性它在哪些形式中使用:

      Mage::getModel('customer/attribute')
          ->loadByCode('customer', 'your_attrib_code')
          ->setUsedInForms(array('adminhtml_customer'))
          ->save();
      

      为方便起见,这可以放在标准的 Magento 升级脚本中(通常是最初创建属性的同一脚本,或者紧随其后的那个)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-01-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多