0

In Magento 1.9. We can use below code to load all values of particular attributes

$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'brand');

    if ($attribute->usesSource()) {
        return $options = $attribute->getSource()->getAllOptions(false);
    }

How to do the same in Magento 2.4 version?

0

I got the solution & working fine for me. If anyone has still the best or short solution can answer.

put below code on a constructor of any helper or block class.

 public function __construct(
        \Magento\Eav\Api\AttributeRepositoryInterface $eavAttribute
    ) 
 
    {
        $this->_eavAttribute = $eavAttribute;
    }

Put below function in helper or block file.

 public function getBrandListing()
    { 
        $brand = $this->_eavAttribute->get(\Magento\Catalog\Model\Product::ENTITY, 'brand');
        $allOptions = $brand->getSource()->getAllOptions();
        return $allOptions;
    }

Now call the getBrandListing function from any file by creating the object of helper.

0

This might help:

  protected $_eavAttribute;
    
    public function __construct(
            \Magento\Eav\Api\AttributeRepositoryInterface $eavAttribute
    ) {
        $this->_eavAttribute = $eavAttribute;
    }
    
    public function getManufacturerListing()
    { 
        $manufacturerAttr = $this->_eavAttribute->get(\Magento\Catalog\Model\Product::ENTITY, 'manufacturer_name');
        $allOptions = $manufacturerAttr->getSource()->getAllOptions();
        return $allOptions;
    }

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.