In the “New Shipment” email templates, I am trying to add additional content to display the items that did not get shipped, such as in the case of a surprise out-of-stock item.
app/design/frontend/Vendor/theme/Magento_Sales/layout/sales_email_order_pending_shipment_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">
<body>
<block class="MagentoSalesBlockOrderEmailItems" name="pending.items" template="Magento_Sales::email/shipment/pending_items.phtml"/>
</body>
app/design/frontend/Vendor/theme/Magento_Sales/templates/email/shipment/pending_items.phtml
<?php
/** @var $block MagentoSalesBlockOrderEmailItems */
?>
<?php $_order = $block->getOrder() ?>
<?php if ($_order) : ?>
<?php $_items = $_order->getAllVisibleItems(); ?>
<?php
foreach ($_items as $item) {
if ($item->getQtyOrdered() > $item->getQtyShipped()) {
$pendingItems[] = [
'name' => $item->getName(),
'sku' => $item->getSku(),
'qty_remaining' => $item->getQtyOrdered() - $item->getQtyShipped(),
];
}
}
?>
<?php if (!empty($pendingItems)): ?>
<h2>Items Yet to be Shipped</h2>
<ul>
<?php foreach ($pendingItems as $item): ?>
<li><?php echo $item['name']; ?> (<?php echo $item['sku']; ?>) - Remaining Qty: <?php echo $item['qty_remaining']; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endif; ?>
I have added my new layout handle to the email template in Magento.
When I get my test email, after shipping only one of the items in my order, the items that did not ship do not display.
What am I missing to get this to work?