I have created custom email template and calling order item in it. In my site I’m adding or editing the specific order Item and I need need to send email for that item only. It was working fine in the Magento 2.4.3. Now I have upgraded to 2.4.6-p1 and it’s giving error when going to send the email.
sales_email_order_custom_items.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Order Items List" design_abstraction="custom">
<update handle="sales_email_order_renderers"/>
<update handle="sales_email_item_price"/>
<body>
<block class="MagentoSalesBlockOrderEmailItems" name="items" template="Vendor_Module::email/added_items.phtml" cacheable="false">
<block class="MagentoFrameworkViewElementRendererList" name="sales.email.order.renderers" as="renderer.list"/>
</block>
<block class="MagentoFrameworkViewElementTemplate" name="additional.product.info" template="Magento_Theme::template.phtml"/>
</body>
Send Email:
$templateOptions = [
'area' => MagentoFrameworkAppArea::AREA_FRONTEND,
'store' => $this->storeManager->getStore($order->getStoreId())->getId()
];
$templateVars = [
'store' => $store,
'order'=> $order,
'item' => $this->orderItemRepository->get($itemId),
'action' => $itemAction
];
$transport = $this->transportBuilder->setTemplateIdentifier($emailtemplate)
->setTemplateOptions($templateOptions)
->setTemplateVars($templateVars)
->setFrom($senderInfo)
->addTo($ccEmails, $receiverInfo['name'])
->getTransport();
Error: Call to a member function getStoreId() on null in /var/www/html/vendor/magento/module-tax/Block/Item/Price/Renderer.php:82
/**
* Set item for render
*
* @param QuoteItem|OrderItem|InvoiceItem|CreditMemoItem $item
* @return $this
*/
public function setItem($item)
{
$this->item = $item;
$this->storeId = $item->getStoreId();
return $this;
}
Email Template:
<?php
$item = $block->getItem();
?>
<table class="email-items">
<thead>
<tr>
<th class="item-info">
<?= $block->escapeHtml(__('Image')) ?>
</th>
<th class="item-info">
<?= $block->escapeHtml(__('Item')) ?>
</th>
<th class="item-info">
<?= $block->escapeHtml(__('Sku')) ?>
</th>
<th class="item-qty">
<?= $block->escapeHtml(__('Qty')) ?>
</th>
<th class="item-price">
<?= $block->escapeHtml(__('Price')) ?>
</th>
</tr>
</thead>
<?php if (!$item->getParentItemId()) : ?>
<tbody>
<?= $block->getItemHtml($item) ?>
</tbody>
<?php endif; ?>
</table>