0

I am unable to find a solution for this error :

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

I am also getting this error in the email :

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; ?>
6
  • 1
    add full code from this file. Aug 29, 2020 at 5:47
  • I have added all code please check
    – jykmhar123
    Aug 29, 2020 at 5:55
  • 1
    Unable to resolve the source file for 'frontend/Emthemes/everything_default/en_US/Magento_Catalog/images/product/placeholder/product_base_image.jpg' This means this file do not exist as per its name and path on source. Aug 29, 2020 at 5:58
  • Thank you sir i will check it
    – jykmhar123
    Aug 29, 2020 at 5:59
  • 1
    You can get media path as per the answer i posted or if you want to check with you current code, try var_dump($_order->getStore()); & observe what's there if it contains data or not. Aug 29, 2020 at 6:00

1 Answer 1

1

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(); ?>
4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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