How to get attribute image in Magento2 using product object?


Just inject this \Magento\Catalog\Api\ProductRepositoryInterfaceFactory in your constructor.

protected $_productRepositoryFactory;

public function __construct(
        \Magento\Catalog\Api\ProductRepositoryInterfaceFactory $productRepositoryFactory
) {

    $this->_productRepositoryFactory = $productRepositoryFactory;

Get the image this way:

$product = $this->_productRepositoryFactory->create()->getById($item->getProductId());

reference Get product image


Try Below code.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($_product->getId());
$image= $product->getData('attr_code');
  • i want attribute image not product image – imtiaz Jan 25 at 13:58

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.