I am using the below code to load the attribute using attribute code but it's not working:-
protected $_attribute;
public function __construct(
...
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $attribute,
...
) {
...
$this->_attribute = $attribute;
...
}
$existingAttribute = $this->_attribute
->addFieldToFilter('attribute_code', $attributecode)
->load()
->getFirstItem();
echo '<pre>'; print_r($existingAttribute); echo '</pre>';
Can any one help me in this. It's working fine as below in magento 1
$existingAttribute = Mage::getModel('eav/entity_attribute')->getResourceCollection()
->addFieldToFilter('attribute_code', $attributecode)
->load()
->getFirstItem();
echo $existingAttribute->getId();
echo '<pre>'; print_r($existingAttribute); echo '</pre>';
Thanks for help in advance;