1

How to get attribute image in Magento2 using product object?

2 Answers 2

0

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());
$product->getData('image');

reference Get product image

0

Try Below code.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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