0

This question already has an answer here:

I'm very new in Magento. I want to display products images on page sales/order/view. How can I do that? Anyone can help? Thank you!

marked as duplicate by Jai, Aasim Goriya, HelgeB, Mohit Kumar Arora, Shoaib Munir Jun 19 at 9:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

For item image try with below code

step1 :

#app/code/Adamsmage/SalesOrder/etc/module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Adamsmage_SalesOrder" setup_version="1.0.0">
</module>

Step2 :

#app/code/Adamsmage/SalesOrder/etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer"
            type="Adamsmage\SalesOrder\Block\Item\Renderer"/></config>

step3 :

<?php #app/code/Adamsmage/SalesOrder/Block/Item/Renderer.php

namespace Adamsmage\SalesOrder\Block\Item; 
use Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer as DefaultRenderer;


class Renderer extends DefaultRenderer{
 protected $string;

/**
 * @var \Magento\Catalog\Model\Product\OptionFactory
 */
protected $_productOptionFactory;

/**
 * @var \Magento\Catalog\Block\Product\ImageBuilder
 */
protected $imageBuilder;

/**
 * @param \Magento\Framework\View\Element\Template\Context $context
 * @param \Magento\Framework\Stdlib\StringUtils $string
 * @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory
 * @param array $data
 */
public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Framework\Stdlib\StringUtils $string,
    \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory,
    \Magento\Catalog\Block\Product\ImageBuilder $imageBuilder,
    array $data = []
) {
    $this->imageBuilder = $imageBuilder;
    parent::__construct($context, $string, $productOptionFactory, $data);
}

/**
 * Get item product
 *
 * @return \Magento\Catalog\Model\Product
 * @codeCoverageIgnore
 */
public function getProduct()
{
    return $this->getItem()->getProduct();
}

/**
 * Identify the product from which thumbnail should be taken.
 *
 * @return \Magento\Catalog\Model\Product
 * @codeCoverageIgnore
 */
public function getProductForThumbnail()
{
    return $this->getProduct();
}

/**
 * Retrieve product image
 *
 * @param \Magento\Catalog\Model\Product $product
 * @param string $imageId
 * @param array $attributes
 * @return \Magento\Catalog\Block\Product\Image
 */
public function getImage($product, $imageId, $attributes = [])
{
    return $this->imageBuilder->setProduct($product)
        ->setImageId($imageId)
        ->setAttributes($attributes)
        ->create();
} }

step4 :

app/code/Adamsmage/SalesOrder/view/frontend/templates/order/items/renderer/default.phtml

echo $block->getImage($block->getProductForThumbnail(), 'cart_page_product_thumbnail')->toHtml();

step5:

#app/code/Adamsmage/SalesOrder/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Adamsmage_SalesOrder',
__DIR__ );

step6:

#app/etc/config.php
<?php return array ('modules' =>array ('Adamsmage_SalesOrder' => 1,
  • Thanks for your answer! I have read it. I also read other documents and they said we shouldn't modify directly file config.php. Could you explain about that???? – Michael Tao Jun 19 at 9:14
  • run command like : php bin/magento setup:upgrade, php bin/magento setup:static-content:deploy – Anas Mansuri Jun 19 at 9:15

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