Question

unable to find this error solution

Error filtering template: Notice: Undefined variable: _store in /var/www/html/vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml on line 32

Also getting this error in mail

Unable to resolve the source file for 'frontend/Emthemes/everything_default/en_US/Magento_Catalog/images/product/placeholder/product_base_image.jpg'
    #0 /var/www/html/vendor/magento/framework/App/StaticResource.php(134): Magento\Framework\View\Asset\File->getSourceFile()
    #1 /var/www/html/vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\StaticResource->launch()
    #2 /var/www/html/pub/static.php(13): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\StaticResource))
    #3 {main}

Below is my Code

<?php
    $_item = $block->getItem();
    $_order = $_item->getOrder();
    $_store = $_order->getStore();
    $_imageHelper = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Catalog\Helper\Image');
    $_baseImageUrl = $_store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).'catalog/product';
    ?>
    <tr>
        <td class="item-thumbnail">
            <img src="<?= $_imageHelper->init($_item->getProduct(), 'product_base_image', ['type'=>'product_base_image'])->keepAspectRatio(true)->resize('120','120')->getUrl();?>" alt="<?= $block->escapeHtml($_item->getName()) ?>">
        </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>
                <?php endforeach; ?>
                </dl>
            <?php endif; ?>
            <?php $addInfoBlock = $block->getProductAdditionalInformationBlock(); ?>
            <?php if ($addInfoBlock) :?>
                <?= $addInfoBlock->setItem($_item)->toHtml() ?>
            <?php endif; ?>
            <?= $block->escapeHtml($_item->getDescription()) ?>
        </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; ?>

No correct solution

OTHER TIPS

Get media path by Dependency Injection

protected $_storeManager;

public function __construct( 
    ...
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    ...
) {
    ...
    $this->_storeManager = $storeManager;
    ...
}

public function getMediaUrl()
{
    $mediaUrl = $this->_storeManager
                     ->getStore()
                     ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
    return $mediaUrl;
}

Now call function getMediaUrl() in phtml

<?php echo $block->getMediaUrl(); ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top