Read More
Read More
Menu Close

    Get Attribute Id By Attribute Code In Magento2

    Get Attribute Id By Attribute Code In Magento2 – if you want to get the attribute id by attribute code.so here i am going to explain how to get the attribute id by attribute code. just you have to follow some steps.

    1. Create constructor

    /**
     * @var \Magento\Eav\Model\ResourceModel\Entity\Attribute
     */
    protected $_eavAttribute;
    /**
     * @param   Context                                           $context
     * @param   \Magento\Eav\Model\ResourceModel\Entity\Attribute $eavAttribute
     */
    public function __construct(
        Context $context,
        \Magento\Eav\Model\ResourceModel\Entity\Attribute $eavAttribute
    )
    {
        $this->_eavAttribute = $eavAttribute;
        parent::__construct($context);
    }
    
    2 . Call the getIdByCode method of Attribute in any method
    
    
    $attributeId = $this->_eavAttribute->getIdByCode('customer', 'company_name');
    
    
    
    

    In this way, you can get the attribute id by attribute code.

    Searching for an experienced
    Magento 2 Company ?
    Read More
    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top