I'm trying to write an observer and send product data to external source.

Have everything done except that when I get image it shows default Magento image.

public function __construct(
    \Magento\Sales\Api\Data\OrderInterface $order,
    \Magento\Catalog\Model\Product $product,
    \Magento\Catalog\Helper\Image $imgHelper
) {
     $this->_order = $order;
     $this->_product = $product;
     $this->_imgHelper = $imgHelper;

public function execute(\Magento\Framework\Event\Observer $observer){
    $itemCollection = $order->getItemsCollection();
    foreach($itemCollection as $item){
        $product = $this->_product->load($item->getData('product_id'));
        $this->_imgHelper->init($product, 'product_thumbnail_image')->getUrl();

The image which I get is:


Do I miss something?

2 Answers 2


First please check whether product object is loaded successfully or not by fetching id using $product->getId() if product object is fine then Try to use this

$this->_imgHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->getUrl();

instead of this

$this->_imgHelper->init($product, 'product_thumbnail_image')->getUrl();

I hope this will help


damn it seem to be i had error in external source, limit of file name there was 100 chars..

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.