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
    Which attributes customer, products etc? – Sukumar Gorai Jun 17 '18 at 16:23
0

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, privacy policy and cookie policy

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