0

我为magento 2 创建了一个模块。我尝试在frontend_customer 和adminhtml_customer 中添加一个新的客户属性。但什么也没发生..有人可以帮我让这个模块工作得很好吗?

socialme/idInput/Setup/installData.php

<?php

    namespace socialme\idInput\Setup;

    use Magento\Customer\Setup\CustomerSetupFactory;
    use Magento\Customer\Model\Customer;
    use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
    use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
    use Magento\Framework\Setup\InstallDataInterface;
    use Magento\Framework\Setup\ModuleContextInterface;
    use Magento\Framework\Setup\ModuleDataSetupInterface;

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

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

         /**
         * @var AttributeSetFactory
         */
         private $attributeSetFactory;

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


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

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

    $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
    $attributeSetId = $customerEntity->getDefaultAttributeSetId();

    /** @var $attributeSet AttributeSet */
    $attributeSet = $this->attributeSetFactory->create();
    $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

    $customerSetup->addAttribute(Customer::ENTITY, 'id_number', [
        'type' => 'varchar',
        'label' => 'ID Number',
        'input' => 'text',
        'required' => false,
        'visible' => true,
        'user_defined' => true,
        'sort_order' => 1000,
        'position' => 1000,
        'system' => 0,
    ]);

    $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'id_number')
        ->addData([
            'attribute_set_id' => $attributeSetId,
            'attribute_group_id' => $attributeGroupId,
            'used_in_forms' => ['adminhtml_customer']
        ]);

    $attribute->save();


  }
}                                                                                

socialme/idInput/etc/module.xml

<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
     <module name="Id_Input" setup_version="2.0.3">
         <sequence>
             <module name="Magento_Customer" />
         </sequence>
     </module>
 </config>

socialme/idInput/registration.p

 \Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Id_Input',
__DIR__
);
4

1 回答 1

0

您使用命名空间 socialme\idInput\Setup; 和模块名称="Id_Input"

命名空间是 < vendorName >\< moduleName >\<whateverFolder>

您的模块名称和注册应该是 < vendorName >_< moduleName > 所以在你的情况下它应该是 socialme_idInput

于 2017-06-13T09:23:10.243 回答