how to get product thumbnail and product url in order confirmation email
you have to load product to get thumbnail and url .
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($_item->getProduct()->getId());
echo $product->getThumbnail();
echo $product->getProductUrl(); ?>
//get image url
$imagewidth=200;
$imageheight=200;
$imageHelper = $objectManager->get('\Magento\Catalog\Helper\Image');
$image_url = $imageHelper->init($product, 'product_page_image_small')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl();
echo $image_url
I've tried this code myself, its working.
override vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml and use this code in it:
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/** @var $block \Magento\Sales\Block\Order\Email\Items\DefaultItems */
/** @var $_item \Magento\Sales\Model\Order\Item */
$_item = $block->getItem();
$_order = $_item->getOrder();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
?>
<tr>
<td class="item-info<?php if ($block->getItemOptions()): ?> has-extra<?php endif; ?>">
<p class="product-name"><?= $block->escapeHtml($_item->getName()) ?></p>
<p class="product-name"><?= $block->escapeHtml($_item->getName()) ?></p>
<p class="sku"><?= /* @escapeNotVerified */ __('SKU'); ?>: <?= $block->escapeHtml($block->getSku($_item)) ?></p>
<?php if ($block->getItemOptions()): ?>
<dl class="item-options">
<?php foreach ($block->getItemOptions() as $option): ?>
<dt><strong><em><?= /* @escapeNotVerified */ $option['label'] ?></em></strong></dt>
<dd>
<?= /* @escapeNotVerified */ nl2br($option['value']) ?>
</dd>
<?php endforeach; ?>
</dl>
<?php endif; ?>
<?php $addInfoBlock = $block->getProductAdditionalInformationBlock(); ?>
<?php if ($addInfoBlock) :?>
<?= $addInfoBlock->setItem($_item)->toHtml() ?>
<?php endif; ?>
<?= $block->escapeHtml($_item->getDescription()) ?>
</td>
<td>
<?php
$_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->getFile())->resize(100, 100)->getUrl();
?>
<img src="<?php echo $image_url; ?>">
</td>
<td class="item-qty"><?= /* @escapeNotVerified */ $_item->getQtyOrdered() * 1 ?></td>
<td class="item-price">
<?= /* @escapeNotVerified */ $block->getItemPrice($_item); ?>
</td>
</tr>
<?php if ($_item->getGiftMessageId() && $_giftMessage = $this->helper('Magento\GiftMessage\Helper\Message')->getGiftMessage($_item->getGiftMessageId())): ?>
<tr>
<td colspan="3" class="item-extra">
<table class="message-gift">
<tr>
<td>
<h3><?= /* @escapeNotVerified */ __('Gift Message') ?></h3>
<strong><?= /* @escapeNotVerified */ __('From:'); ?></strong> <?= $block->escapeHtml($_giftMessage->getSender()) ?>
<br /><strong><?= /* @escapeNotVerified */ __('To:'); ?></strong> <?= $block->escapeHtml($_giftMessage->getRecipient()) ?>
<br /><strong><?= /* @escapeNotVerified */ __('Message:'); ?></strong>
<br /><?= $block->escapeHtml($_giftMessage->getMessage()) ?>
</td>
</tr>
</table>
</td>
</tr>
<?php endif; ?>
and in override vendor/magento/module-sales/view/frontend/templates/email/items.phtml and use:
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
?>
<?php $_order = $block->getOrder() ?>
<?php if ($_order): ?>
<?php $_items = $_order->getAllItems(); ?>
<table class="email-items">
<thead>
<tr>
<th class="item-info">
<?= /* @escapeNotVerified */ __('Items'); ?>
</th>
<th class="item-qty">
<?= /* @escapeNotVerified */ __('Qty'); ?>
</th>
<th class="item-qty">
<?= /* @escapeNotVerified */ __('Image'); ?>
</th>
<th class="item-price">
<?= /* @escapeNotVerified */ __('Price'); ?>
</th>
</tr>
</thead>
<?php foreach ($_items as $_item): ?>
<?php
if ($_item->getParentItem()) {
continue;
}
?>
<tbody>
<?= $block->getItemHtml($_item) ?>
</tbody>
<?php endforeach; ?>
<tfoot class="order-totals">
<?= $block->getChildHtml('order_totals') ?>
</tfoot>
</table>
<?php if ($this->helper('Magento\GiftMessage\Helper\Message')->isMessagesAllowed('order', $_order, $_order->getStore()) && $_order->getGiftMessageId()): ?>
<?php $_giftMessage = $this->helper('Magento\GiftMessage\Helper\Message')->getGiftMessage($_order->getGiftMessageId()); ?>
<?php if ($_giftMessage): ?>
<br />
<table class="message-gift">
<tr>
<td>
<h3><?= /* @escapeNotVerified */ __('Gift Message for this Order') ?></h3>
<strong><?= /* @escapeNotVerified */ __('From:'); ?></strong> <?= $block->escapeHtml($_giftMessage->getSender()) ?>
<br /><strong><?= /* @escapeNotVerified */ __('To:'); ?></strong> <?= $block->escapeHtml($_giftMessage->getRecipient()) ?>
<br /><strong><?= /* @escapeNotVerified */ __('Message:'); ?></strong>
<br /><?= $block->escapeHtml($_giftMessage->getMessage()) ?>
</td>
</tr>
</table>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>