I’m trying to display product (or variation of configurable product) image inside of shipment email. I was able to accomplish this inside of Order emails but my current setup doesn’t work inside of shipment emails.
Here’s what I have so far:
Magento_Sales/templates/email/items/shipment/default.phtml
// @codingStandardsIgnoreFile
/** @var $block \Magento\Sales\Block\Order\Email\Items\DefaultItems */
/** @var $_item \Magento\Sales\Model\Order\Item */
$_item = $block->getItem();
$_order = $_item->getOrder();
$imageSize = (int)$block->getConfig('sales_email/imageconfig/image_resize');
if($imageSize <=10)
$imageSize = 135;
$_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
if($childProd = current($_item->getChildrenItems()))
{
$productImage = $_imagehelper->init($childProd->getProduct(), 'category_page_list', array('height' => $imageSize , 'width'=> $imageSize))->getUrl();
}
else
{
$productImage = $_imagehelper->init($_item->getProduct(), 'category_page_list', array('height' => $imageSize , 'width'=> $imageSize))->getUrl();
}
?>
<tr>
<td class="item-image">
<p class="product-image"><img src="<?=$productImage?>" title="<?= $block->escapeHtml($_item->getName()) ?>" alt="<?= $block->escapeHtml($_item->getName()) ?>" /></p>
</td>
<td class="item-info<?php if ($block->getItemOptions()): ?> has-extra<?php endif; ?>">
<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><br />
<?php endforeach; ?>
</dl>
<?php endif; ?>
<?php $addInfoBlock = $block->getProductAdditionalInformationBlock(); ?>
<?php if ($addInfoBlock) :?>
<?= $addInfoBlock->setItem($_item->getOrderItem())->toHtml() ?>
<?php endif; ?>
<?= $block->escapeHtml($_item->getDescription()) ?>
</td>
<td class="item-qty"><?= /* @escapeNotVerified */ $_item->getQty() * 1 ?></td>
</tr>
The same code works for order emails, but this one doesn’t work and leads to crashing the “Send Tracking Information” button in admin to not work.