cancel
Showing results for 
Search instead for 
Did you mean: 

Create custom attribute

Create custom attribute

Hi all. I have a problem with my code for create atrribute:

$attribute = $this->attributeFactory->create();

$attribute->setAttributeCode($data['code']);
$attribute->setEntityTypeId($data['entity_type_id']);
$attribute->setFrontendInput($data['input_type']);
$attribute->setDefaultFrontendLabel($data['label']);
$attribute->setIsUserDefined($data['is_user_defined']);
$attribute->setIsRequired($data['is_required']);
$attribute->setBackendType('varchar');

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

Magento\Eav\Model\Entity\AttributeFactory and Magento\Eav\Model\Entity\Attribute\SetFactory are undefined classes Smiley Sad

 

Pls help me...

 

1 REPLY 1

Re: Create custom attribute

It looks like you're missing some dependencies for your code. You'll need to inject the

\Magento\Eav\Model\Entity\AttributeFactory

and potentially

\Magento\Eav\Model\Entity\Attribute\SetFactory

using dependency injection.