2016-07-27 9 views
2

추가내가이 고객 adminhtml에게 magentos에 새 필드를 추가하려고 고객 속성 Magento2

내가 무슨 짓을했는지 :

는 그런 다음 InstallData.php

<?php 

namespace Company\Module\Setup; 

use Magento\Framework\Module\Setup\Migration; 
use Magento\Framework\Setup\InstallDataInterface; 
use Magento\Framework\Setup\ModuleContextInterface; 
use Magento\Framework\Setup\ModuleDataSetupInterface; 
use Magento\Catalog\Setup\CustomerSetupFactory; 
use Magento\Eav\Model\AttributeRepository; 

/** 
* @codeCoverageIgnore 
*/ 
class InstallData implements InstallDataInterface 
{ 

    /** 
    * @var CustomerSetupFactory 
    */ 
    protected $customerSetupFactory; 


    protected $attributeRepository; 

    /** 
    * @param CustomerSetupFactory $customerSetupFactory 
    * @param AttributeSetFactory $attributeSetFactory 
    */ 
    public function __construct(
     CustomerSetupFactory $customerSetupFactory, 
     AttributeRepository $attributeRepository 
    ) { 
     $this->customerSetupFactory = $customerSetupFactory; 
     $this->attributeRepository = $attributeRepository; 
    } 


    /** 
    * {@inheritdoc} 
    */ 
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) 
    { 

     $installer = $setup; 
     $installer->startSetup(); 

     /** @var CustomerSetup $customerSetup */ 
     $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); 

     $customerSetup->addAttribute(CUSTOMER::ENTITY, 'custom_field', [ 
      'type' => 'varchar', 
      'label' => 'Custom Field', 
      'input' => 'text', 
      'required' => false, 
      'visible' => true, 
      'user_defined' => true, 
      'sort_order' => 1000, 
      'position' => 1000, 
      'system' => 0, 
     ]); 

     $MyAttribute = $customerSetup->getEavConfig()->getAttribute(CUSTOMER::ENTITY, 'custom_field'); 
     $MyAttribute->setData(
      'used_in_forms', 
      ['adminhtml_customer'] 
     ); 

     $this->attributeRepository->save($MyAttribute); 

     $setup->endSetup(); 


    } 
} 

내 모듈에 Setup 폴더를 넣어 전 php bin/magento setup : 업그레이드는 있지만 아무 일도 일어나지 않습니다.

캐시는 기본적으로 사용되지 않습니다.

나는이 튜토리얼 다시 시도 : http://www.extensions.sashas.org/blog/magento-2-make-customer-attribute.html

을하지만 너무 작동하지 않았다. 2.1

답변