1

In Magento 2, How do I get all the attributes and it's description ?

Please provide me a solution. Anyone have any script ?

1
  • 1
    Which attributes customer, products etc? Commented Jun 17, 2018 at 16:23

1 Answer 1

1

Try below code for getting all custom attributes of Product.

protected $_attributeFactory;



public function __construct(
    ....
    \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeFactory,
    ....
) {
    ....
    $this->_attributeFactory = $attributeFactory;
    ....
}

public function getCustomAttributes()
    {
    $attributeList = $this->_attributeFactory->getCollection();
    $attributeList->addFieldToFilter('is_user_defined',['eq' => 1]);

    foreach($attributeList as $attribute)
    {
        echo '<pre>';print_r($attribute->getData());
    }
}
die;

It's working fine for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.