0

i am want to show correct product image on my order details page:

I am using it as:

$_item = $block->getItem();

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$_product = $objectManager->get('Magento\Catalog\Model\Product')->load($_item->getProductId());

$imageHelper  = $objectManager->get('\Magento\Catalog\Helper\Image');

$image_url = $imageHelper->init($_product, 'product_page_image_small')->setImageFile($_product->getImage())->resize(100, 100)->getUrl();

but showing main product image its not showing child product image. here i am want to show correct configurable product image.

Please help.

Thanks

enter image description here

4

Use the below code to show the correct configurable's child product image.

<?php
    $_item = $block->getItem();
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
    $_product = $productRepository->get($_item->getSku());
    $imageHelper  = $objectManager->get('\Magento\Catalog\Helper\Image');
    $image_url = $imageHelper->init($_product, 'product_page_image_small')->setImageFile($_product->getImage())->resize(100, 100)->getUrl();
?>

Check the screenshot.

enter image description here

Hope this will work for you.

| improve this answer | |
  • Yes getSku is correct way :) – Shiv Singh Jan 1 at 11:17

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.