1

How to get attribute image in Magento2 using product object?

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');
  • 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.