Ich habe versucht, ein neues Feld in magentos 2 Kunde adminhtmlhinzufügen Kunden Attribut Magento2
hinzufügen, was ich tat:
legte einen Setup
Ordner in meinem Modul mit einem i 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();
}
}
Dann genannt php bin/magento setup: upgrade aber nichts passiert.
Der Cache ist standardmäßig deaktiviert.
Ich habe versucht, auch dieses Tutorial neu zu erstellen: http://www.extensions.sashas.org/blog/magento-2-make-customer-attribute.html
aber es auch nicht funktioniert hat.
Magento Version 2.1